Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid off-spec openmetrics exposition when exemplars have empty labels #569

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion expfmt/openmetrics_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func writeOpenMetricsSample(
return written, err
}
}
if exemplar != nil {
if exemplar != nil && len(exemplar.Label) > 0 {
n, err = writeExemplar(w, exemplar)
written += n
if err != nil {
Expand Down
25 changes: 25 additions & 0 deletions expfmt/openmetrics_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,31 @@ foos_total 42.0
},
out: `# HELP name doc string
# TYPE name counter
`,
},
// 9: Simple Counter with exemplar that has empty label set:
// ignore the exemplar, since OpenMetrics spec requires labels.
{
in: &dto.MetricFamily{
Name: proto.String("foos_total"),
Help: proto.String("Number of foos."),
Type: dto.MetricType_COUNTER.Enum(),
Metric: []*dto.Metric{
{
Counter: &dto.Counter{
Value: proto.Float64(42),
Exemplar: &dto.Exemplar{
Label: []*dto.LabelPair{},
Value: proto.Float64(1),
Timestamp: openMetricsTimestamp,
},
},
},
},
},
out: `# HELP foos Number of foos.
# TYPE foos counter
foos_total 42.0
`,
},
}
Expand Down