Skip to content

Commit ae18ca7

Browse files
committed
Revert unnecessary changes
Signed-off-by: Arianna Vespri <[email protected]>
1 parent f1b4762 commit ae18ca7

File tree

5 files changed

+3
-201
lines changed

5 files changed

+3
-201
lines changed

expfmt/openmetrics_create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,14 @@ foos_total 42.0
422422
// 9: No metric plus unit.
423423
{
424424
in: &dto.MetricFamily{
425-
Name: proto.String("name_seconds"),
425+
Name: proto.String("name_seconds_total"),
426426
Help: proto.String("doc string"),
427427
Type: dto.MetricType_COUNTER.Enum(),
428428
Unit: proto.String("seconds"),
429429
Metric: []*dto.Metric{},
430430
},
431431
out: `# HELP name_seconds doc string
432-
# TYPE name_seconds unknown
432+
# TYPE name_seconds counter
433433
# UNIT name_seconds seconds
434434
`,
435435
},

expfmt/text_create.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -148,33 +148,6 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
148148
if err != nil {
149149
return
150150
}
151-
if in.Unit != nil {
152-
n, err = w.WriteString("# UNIT ")
153-
written += n
154-
if err != nil {
155-
return
156-
}
157-
n, err = w.WriteString(name)
158-
written += n
159-
if err != nil {
160-
return
161-
}
162-
err = w.WriteByte(' ')
163-
written++
164-
if err != nil {
165-
return
166-
}
167-
n, err = writeEscapedString(w, *in.Unit, false)
168-
written += n
169-
if err != nil {
170-
return
171-
}
172-
err = w.WriteByte('\n')
173-
written++
174-
if err != nil {
175-
return
176-
}
177-
}
178151

179152
// Finally the samples, one line for each.
180153
for _, metric := range in.Metric {

expfmt/text_create_test.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -330,56 +330,6 @@ request_duration_microseconds_count 2693
330330
out: `# HELP name doc string
331331
# TYPE name counter
332332
name -Inf
333-
`,
334-
},
335-
// 7: Histogram with unit
336-
{
337-
in: &dto.MetricFamily{
338-
Name: proto.String("request_duration_microseconds"),
339-
Help: proto.String("The response latency."),
340-
Type: dto.MetricType_HISTOGRAM.Enum(),
341-
Unit: proto.String("microseconds"),
342-
Metric: []*dto.Metric{
343-
&dto.Metric{
344-
Histogram: &dto.Histogram{
345-
SampleCount: proto.Uint64(2693),
346-
SampleSum: proto.Float64(1756047.3),
347-
Bucket: []*dto.Bucket{
348-
&dto.Bucket{
349-
UpperBound: proto.Float64(100),
350-
CumulativeCount: proto.Uint64(123),
351-
},
352-
&dto.Bucket{
353-
UpperBound: proto.Float64(120),
354-
CumulativeCount: proto.Uint64(412),
355-
},
356-
&dto.Bucket{
357-
UpperBound: proto.Float64(144),
358-
CumulativeCount: proto.Uint64(592),
359-
},
360-
&dto.Bucket{
361-
UpperBound: proto.Float64(172.8),
362-
CumulativeCount: proto.Uint64(1524),
363-
},
364-
&dto.Bucket{
365-
UpperBound: proto.Float64(math.Inf(+1)),
366-
CumulativeCount: proto.Uint64(2693),
367-
},
368-
},
369-
},
370-
},
371-
},
372-
},
373-
out: `# HELP request_duration_microseconds The response latency.
374-
# TYPE request_duration_microseconds histogram
375-
# UNIT request_duration_microseconds microseconds
376-
request_duration_microseconds_bucket{le="100"} 123
377-
request_duration_microseconds_bucket{le="120"} 412
378-
request_duration_microseconds_bucket{le="144"} 592
379-
request_duration_microseconds_bucket{le="172.8"} 1524
380-
request_duration_microseconds_bucket{le="+Inf"} 2693
381-
request_duration_microseconds_sum 1.7560473e+06
382-
request_duration_microseconds_count 2693
383333
`,
384334
},
385335
}

expfmt/text_parse.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (p *TextParser) startComment() stateFn {
178178
return p.startOfLine
179179
}
180180
keyword := p.currentToken.String()
181-
if keyword != "HELP" && keyword != "TYPE" && keyword != "UNIT" {
181+
if keyword != "HELP" && keyword != "TYPE" {
182182
// Generic comment, ignore by fast forwarding to end of line.
183183
for p.currentByte != '\n' {
184184
if p.currentByte, p.err = p.buf.ReadByte(); p.err != nil {
@@ -217,8 +217,6 @@ func (p *TextParser) startComment() stateFn {
217217
return p.readingHelp
218218
case "TYPE":
219219
return p.readingType
220-
case "UNIT":
221-
return p.readingUnit
222220
}
223221
panic(fmt.Sprintf("code error: unexpected keyword %q", keyword))
224222
}
@@ -530,21 +528,6 @@ func (p *TextParser) readingType() stateFn {
530528
return p.startOfLine
531529
}
532530

533-
// readingUnit represents the state where the last byte read (now in
534-
// p.currentByte) is the first byte of the docstring after 'UNIT'.
535-
func (p *TextParser) readingUnit() stateFn {
536-
if p.currentMF.Unit != nil {
537-
p.parseError(fmt.Sprintf("second UNIT line for metric name %q", p.currentMF.GetName()))
538-
return nil
539-
}
540-
// Rest of line is the docstring.
541-
if p.readTokenUntilNewline(true); p.err != nil {
542-
return nil // Unexpected end of input.
543-
}
544-
p.currentMF.Unit = proto.String(p.currentToken.String())
545-
return p.startOfLine
546-
}
547-
548531
// parseError sets p.err to a ParseError at the current line with the given
549532
// message.
550533
func (p *TextParser) parseError(msg string) {

expfmt/text_parse_test.go

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -385,110 +385,6 @@ request_duration_microseconds_count 2693
385385
},
386386
},
387387
},
388-
// 5: The histogram with unit.
389-
{
390-
in: `
391-
# HELP request_duration_microseconds The response latency.
392-
# TYPE request_duration_microseconds histogram
393-
# UNIT request_duration_microseconds microseconds
394-
request_duration_microseconds_bucket{le="100"} 123
395-
request_duration_microseconds_bucket{le="120"} 412
396-
request_duration_microseconds_bucket{le="144"} 592
397-
request_duration_microseconds_bucket{le="172.8"} 1524
398-
request_duration_microseconds_bucket{le="+Inf"} 2693
399-
request_duration_microseconds_sum 1.7560473e+06
400-
request_duration_microseconds_count 2693
401-
`,
402-
out: []*dto.MetricFamily{
403-
{
404-
Name: proto.String("request_duration_microseconds"),
405-
Help: proto.String("The response latency."),
406-
Type: dto.MetricType_HISTOGRAM.Enum(),
407-
Unit: proto.String("microseconds"),
408-
Metric: []*dto.Metric{
409-
&dto.Metric{
410-
Histogram: &dto.Histogram{
411-
SampleCount: proto.Uint64(2693),
412-
SampleSum: proto.Float64(1756047.3),
413-
Bucket: []*dto.Bucket{
414-
&dto.Bucket{
415-
UpperBound: proto.Float64(100),
416-
CumulativeCount: proto.Uint64(123),
417-
},
418-
&dto.Bucket{
419-
UpperBound: proto.Float64(120),
420-
CumulativeCount: proto.Uint64(412),
421-
},
422-
&dto.Bucket{
423-
UpperBound: proto.Float64(144),
424-
CumulativeCount: proto.Uint64(592),
425-
},
426-
&dto.Bucket{
427-
UpperBound: proto.Float64(172.8),
428-
CumulativeCount: proto.Uint64(1524),
429-
},
430-
&dto.Bucket{
431-
UpperBound: proto.Float64(math.Inf(+1)),
432-
CumulativeCount: proto.Uint64(2693),
433-
},
434-
},
435-
},
436-
},
437-
},
438-
},
439-
},
440-
},
441-
// 6: A counter with unit
442-
{
443-
in: `
444-
# HELP name something to do with time
445-
# TYPE name counter
446-
# UNIT name seconds
447-
name{labelname="val1",basename="basevalue"} 50.0
448-
name{labelname="val2",basename="basevalue"} 0.24 2
449-
`,
450-
out: []*dto.MetricFamily{
451-
{
452-
Name: proto.String("name"),
453-
Help: proto.String("something to do with time"),
454-
Type: dto.MetricType_COUNTER.Enum(),
455-
Unit: proto.String("seconds"),
456-
Metric: []*dto.Metric{
457-
&dto.Metric{
458-
Label: []*dto.LabelPair{
459-
&dto.LabelPair{
460-
Name: proto.String("labelname"),
461-
Value: proto.String("val1"),
462-
},
463-
&dto.LabelPair{
464-
Name: proto.String("basename"),
465-
Value: proto.String("basevalue"),
466-
},
467-
},
468-
Counter: &dto.Counter{
469-
Value: proto.Float64(50),
470-
},
471-
},
472-
&dto.Metric{
473-
Label: []*dto.LabelPair{
474-
&dto.LabelPair{
475-
Name: proto.String("labelname"),
476-
Value: proto.String("val2"),
477-
},
478-
&dto.LabelPair{
479-
Name: proto.String("basename"),
480-
Value: proto.String("basevalue"),
481-
},
482-
},
483-
Counter: &dto.Counter{
484-
Value: proto.Float64(.24),
485-
},
486-
TimestampMs: proto.Int64(2),
487-
},
488-
},
489-
},
490-
},
491-
},
492388
}
493389

494390
for i, scenario := range scenarios {

0 commit comments

Comments
 (0)