Skip to content

Commit

Permalink
Revert unnecessary changes
Browse files Browse the repository at this point in the history
Signed-off-by: Arianna Vespri <[email protected]>
  • Loading branch information
vesari committed Dec 7, 2023
1 parent f1b4762 commit ae18ca7
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 201 deletions.
4 changes: 2 additions & 2 deletions expfmt/openmetrics_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,14 @@ foos_total 42.0
// 9: No metric plus unit.
{
in: &dto.MetricFamily{
Name: proto.String("name_seconds"),
Name: proto.String("name_seconds_total"),
Help: proto.String("doc string"),
Type: dto.MetricType_COUNTER.Enum(),
Unit: proto.String("seconds"),
Metric: []*dto.Metric{},
},
out: `# HELP name_seconds doc string
# TYPE name_seconds unknown
# TYPE name_seconds counter
# UNIT name_seconds seconds
`,
},
Expand Down
27 changes: 0 additions & 27 deletions expfmt/text_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,33 +148,6 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
if err != nil {
return
}
if in.Unit != nil {
n, err = w.WriteString("# UNIT ")
written += n
if err != nil {
return
}
n, err = w.WriteString(name)
written += n
if err != nil {
return
}
err = w.WriteByte(' ')
written++
if err != nil {
return
}
n, err = writeEscapedString(w, *in.Unit, false)
written += n
if err != nil {
return
}
err = w.WriteByte('\n')
written++
if err != nil {
return
}
}

// Finally the samples, one line for each.
for _, metric := range in.Metric {
Expand Down
50 changes: 0 additions & 50 deletions expfmt/text_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,56 +330,6 @@ request_duration_microseconds_count 2693
out: `# HELP name doc string
# TYPE name counter
name -Inf
`,
},
// 7: Histogram with unit
{
in: &dto.MetricFamily{
Name: proto.String("request_duration_microseconds"),
Help: proto.String("The response latency."),
Type: dto.MetricType_HISTOGRAM.Enum(),
Unit: proto.String("microseconds"),
Metric: []*dto.Metric{
&dto.Metric{
Histogram: &dto.Histogram{
SampleCount: proto.Uint64(2693),
SampleSum: proto.Float64(1756047.3),
Bucket: []*dto.Bucket{
&dto.Bucket{
UpperBound: proto.Float64(100),
CumulativeCount: proto.Uint64(123),
},
&dto.Bucket{
UpperBound: proto.Float64(120),
CumulativeCount: proto.Uint64(412),
},
&dto.Bucket{
UpperBound: proto.Float64(144),
CumulativeCount: proto.Uint64(592),
},
&dto.Bucket{
UpperBound: proto.Float64(172.8),
CumulativeCount: proto.Uint64(1524),
},
&dto.Bucket{
UpperBound: proto.Float64(math.Inf(+1)),
CumulativeCount: proto.Uint64(2693),
},
},
},
},
},
},
out: `# HELP request_duration_microseconds The response latency.
# TYPE request_duration_microseconds histogram
# UNIT request_duration_microseconds microseconds
request_duration_microseconds_bucket{le="100"} 123
request_duration_microseconds_bucket{le="120"} 412
request_duration_microseconds_bucket{le="144"} 592
request_duration_microseconds_bucket{le="172.8"} 1524
request_duration_microseconds_bucket{le="+Inf"} 2693
request_duration_microseconds_sum 1.7560473e+06
request_duration_microseconds_count 2693
`,
},
}
Expand Down
19 changes: 1 addition & 18 deletions expfmt/text_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (p *TextParser) startComment() stateFn {
return p.startOfLine
}
keyword := p.currentToken.String()
if keyword != "HELP" && keyword != "TYPE" && keyword != "UNIT" {
if keyword != "HELP" && keyword != "TYPE" {
// Generic comment, ignore by fast forwarding to end of line.
for p.currentByte != '\n' {
if p.currentByte, p.err = p.buf.ReadByte(); p.err != nil {
Expand Down Expand Up @@ -217,8 +217,6 @@ func (p *TextParser) startComment() stateFn {
return p.readingHelp
case "TYPE":
return p.readingType
case "UNIT":
return p.readingUnit
}
panic(fmt.Sprintf("code error: unexpected keyword %q", keyword))
}
Expand Down Expand Up @@ -530,21 +528,6 @@ func (p *TextParser) readingType() stateFn {
return p.startOfLine
}

// readingUnit represents the state where the last byte read (now in
// p.currentByte) is the first byte of the docstring after 'UNIT'.
func (p *TextParser) readingUnit() stateFn {
if p.currentMF.Unit != nil {
p.parseError(fmt.Sprintf("second UNIT line for metric name %q", p.currentMF.GetName()))
return nil
}
// Rest of line is the docstring.
if p.readTokenUntilNewline(true); p.err != nil {
return nil // Unexpected end of input.
}
p.currentMF.Unit = proto.String(p.currentToken.String())
return p.startOfLine
}

// parseError sets p.err to a ParseError at the current line with the given
// message.
func (p *TextParser) parseError(msg string) {
Expand Down
104 changes: 0 additions & 104 deletions expfmt/text_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,110 +385,6 @@ request_duration_microseconds_count 2693
},
},
},
// 5: The histogram with unit.
{
in: `
# HELP request_duration_microseconds The response latency.
# TYPE request_duration_microseconds histogram
# UNIT request_duration_microseconds microseconds
request_duration_microseconds_bucket{le="100"} 123
request_duration_microseconds_bucket{le="120"} 412
request_duration_microseconds_bucket{le="144"} 592
request_duration_microseconds_bucket{le="172.8"} 1524
request_duration_microseconds_bucket{le="+Inf"} 2693
request_duration_microseconds_sum 1.7560473e+06
request_duration_microseconds_count 2693
`,
out: []*dto.MetricFamily{
{
Name: proto.String("request_duration_microseconds"),
Help: proto.String("The response latency."),
Type: dto.MetricType_HISTOGRAM.Enum(),
Unit: proto.String("microseconds"),
Metric: []*dto.Metric{
&dto.Metric{
Histogram: &dto.Histogram{
SampleCount: proto.Uint64(2693),
SampleSum: proto.Float64(1756047.3),
Bucket: []*dto.Bucket{
&dto.Bucket{
UpperBound: proto.Float64(100),
CumulativeCount: proto.Uint64(123),
},
&dto.Bucket{
UpperBound: proto.Float64(120),
CumulativeCount: proto.Uint64(412),
},
&dto.Bucket{
UpperBound: proto.Float64(144),
CumulativeCount: proto.Uint64(592),
},
&dto.Bucket{
UpperBound: proto.Float64(172.8),
CumulativeCount: proto.Uint64(1524),
},
&dto.Bucket{
UpperBound: proto.Float64(math.Inf(+1)),
CumulativeCount: proto.Uint64(2693),
},
},
},
},
},
},
},
},
// 6: A counter with unit
{
in: `
# HELP name something to do with time
# TYPE name counter
# UNIT name seconds
name{labelname="val1",basename="basevalue"} 50.0
name{labelname="val2",basename="basevalue"} 0.24 2
`,
out: []*dto.MetricFamily{
{
Name: proto.String("name"),
Help: proto.String("something to do with time"),
Type: dto.MetricType_COUNTER.Enum(),
Unit: proto.String("seconds"),
Metric: []*dto.Metric{
&dto.Metric{
Label: []*dto.LabelPair{
&dto.LabelPair{
Name: proto.String("labelname"),
Value: proto.String("val1"),
},
&dto.LabelPair{
Name: proto.String("basename"),
Value: proto.String("basevalue"),
},
},
Counter: &dto.Counter{
Value: proto.Float64(50),
},
},
&dto.Metric{
Label: []*dto.LabelPair{
&dto.LabelPair{
Name: proto.String("labelname"),
Value: proto.String("val2"),
},
&dto.LabelPair{
Name: proto.String("basename"),
Value: proto.String("basevalue"),
},
},
Counter: &dto.Counter{
Value: proto.Float64(.24),
},
TimestampMs: proto.Int64(2),
},
},
},
},
},
}

for i, scenario := range scenarios {
Expand Down

0 comments on commit ae18ca7

Please sign in to comment.