File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -350,7 +350,7 @@ func writeOpenMetricsSample(
350
350
return written , err
351
351
}
352
352
}
353
- if exemplar != nil {
353
+ if exemplar != nil && len ( exemplar . Label ) > 0 {
354
354
n , err = writeExemplar (w , exemplar )
355
355
written += n
356
356
if err != nil {
Original file line number Diff line number Diff line change @@ -542,6 +542,31 @@ foos_total 42.0
542
542
},
543
543
out : `# HELP name doc string
544
544
# TYPE name counter
545
+ ` ,
546
+ },
547
+ // 9: Simple Counter with exemplar that has empty label set:
548
+ // ignore the exemplar, since OpenMetrics spec requires labels.
549
+ {
550
+ in : & dto.MetricFamily {
551
+ Name : proto .String ("foos_total" ),
552
+ Help : proto .String ("Number of foos." ),
553
+ Type : dto .MetricType_COUNTER .Enum (),
554
+ Metric : []* dto.Metric {
555
+ {
556
+ Counter : & dto.Counter {
557
+ Value : proto .Float64 (42 ),
558
+ Exemplar : & dto.Exemplar {
559
+ Label : []* dto.LabelPair {},
560
+ Value : proto .Float64 (1 ),
561
+ Timestamp : openMetricsTimestamp ,
562
+ },
563
+ },
564
+ },
565
+ },
566
+ },
567
+ out : `# HELP foos Number of foos.
568
+ # TYPE foos counter
569
+ foos_total 42.0
545
570
` ,
546
571
},
547
572
}
You can’t perform that action at this time.
0 commit comments