Skip to content

Commit 8e2feac

Browse files
committed
api: identify native histograms by presence if at least one span
Signed-off-by: Jan Fajerski <[email protected]>
1 parent 42c4075 commit 8e2feac

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

api/v1/api.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,10 @@ func makeEncodableMetrics(metrics []*dto.Metric, metricsType dto.MetricType) []e
231231
metric["count"] = fmt.Sprint(m.GetSummary().GetSampleCount())
232232
metric["sum"] = fmt.Sprint(m.GetSummary().GetSampleSum())
233233
case dto.MetricType_HISTOGRAM:
234-
metric["sum"] = fmt.Sprint(m.GetHistogram().GetSampleSum())
235-
if b := makeBuckets(m); len(b) > 0 {
236-
metric["buckets"] = b
237-
metric["count"] = fmt.Sprint(m.GetHistogram().GetSampleCount())
238-
} else {
239-
h, fh := histogram.NewModelHistogram(m.GetHistogram())
234+
dtoH := m.GetHistogram()
235+
metric["sum"] = fmt.Sprint(dtoH.GetSampleSum())
236+
if len(dtoH.GetNegativeSpan())+len(dtoH.GetPositiveSpan()) > 0 {
237+
h, fh := histogram.NewModelHistogram(dtoH)
240238
if h == nil {
241239
// float histogram
242240
metric["count"] = fmt.Sprint(fh.Count)
@@ -245,6 +243,9 @@ func makeEncodableMetrics(metrics []*dto.Metric, metricsType dto.MetricType) []e
245243
metric["count"] = fmt.Sprint(h.Count)
246244
metric["buckets"] = histogram.BucketsAsJson[uint64](histogram.GetAPIBuckets(h))
247245
}
246+
} else {
247+
metric["buckets"] = makeBuckets(m)
248+
metric["count"] = fmt.Sprint(dtoH.GetSampleCount())
248249
}
249250
default:
250251
metric["value"] = fmt.Sprint(getValue(m))

0 commit comments

Comments
 (0)