Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions expfmt/openmetrics_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
"expected histogram in metric %s %s", compliantName, metric,
)
}
sumSuffix, countSuffix := "_sum", "_count"
if metricType == dto.MetricType_GAUGE_HISTOGRAM {
sumSuffix, countSuffix = "_gsum", "_gcount"
}
infSeen := false
for _, b := range metric.Histogram.Bucket {
if b.GetCumulativeCountFloat() > 0 {
Expand Down Expand Up @@ -347,7 +351,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
}
}
n, err = writeOpenMetricsSample(
w, compliantName, "_sum", metric, "", 0,
w, compliantName, sumSuffix, metric, "", 0,
metric.Histogram.GetSampleSum(), 0, false,
nil,
)
Expand All @@ -362,11 +366,11 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
)
}
n, err = writeOpenMetricsSample(
w, compliantName, "_count", metric, "", 0,
w, compliantName, countSuffix, metric, "", 0,
0, metric.Histogram.GetSampleCount(), true,
nil,
)
if toOM.withCreatedLines && metric.Histogram.CreatedTimestamp != nil {
if metricType == dto.MetricType_HISTOGRAM && toOM.withCreatedLines && metric.Histogram.CreatedTimestamp != nil {
createdTsBytesWritten, err = writeOpenMetricsCreated(w, compliantName, "", metric, "", 0, metric.Histogram.GetCreatedTimestamp())
n += createdTsBytesWritten
}
Expand Down
10 changes: 6 additions & 4 deletions expfmt/openmetrics_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,15 +718,17 @@ some_measure_total{labelname="val2",basename="basevalue"} 0.23 1.23456789e+06
},
// 17: Gauge histogram.
{
options: []EncoderOption{WithCreatedLines()},
in: &dto.MetricFamily{
Name: proto.String("name"),
Help: proto.String("doc string"),
Type: dto.MetricType_GAUGE_HISTOGRAM.Enum(),
Metric: []*dto.Metric{
{
Histogram: &dto.Histogram{
SampleCount: proto.Uint64(2693),
SampleSum: proto.Float64(1756047.3),
SampleCount: proto.Uint64(2693),
SampleSum: proto.Float64(1756047.3),
CreatedTimestamp: openMetricsTimestamp,
Bucket: []*dto.Bucket{
{
UpperBound: proto.Float64(100),
Expand Down Expand Up @@ -756,8 +758,8 @@ name_bucket{le="120.0"} 412
name_bucket{le="144.0"} 592
name_bucket{le="172.8"} 1524
name_bucket{le="+Inf"} 2693
name_sum 1.7560473e+06
name_count 2693
name_gsum 1.7560473e+06
name_gcount 2693
`,
},
// 18: Colons are valid in legacy metric names but not in legacy label names.
Expand Down
Loading