From 8e2feacc5d6f78cc71e5fa665280a289504ba23a Mon Sep 17 00:00:00 2001 From: Jan Fajerski Date: Thu, 11 Jul 2024 10:59:26 +0200 Subject: [PATCH] api: identify native histograms by presence if at least one span Signed-off-by: Jan Fajerski --- api/v1/api.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/api/v1/api.go b/api/v1/api.go index f7932b61..2e63c72a 100644 --- a/api/v1/api.go +++ b/api/v1/api.go @@ -231,12 +231,10 @@ func makeEncodableMetrics(metrics []*dto.Metric, metricsType dto.MetricType) []e metric["count"] = fmt.Sprint(m.GetSummary().GetSampleCount()) metric["sum"] = fmt.Sprint(m.GetSummary().GetSampleSum()) case dto.MetricType_HISTOGRAM: - metric["sum"] = fmt.Sprint(m.GetHistogram().GetSampleSum()) - if b := makeBuckets(m); len(b) > 0 { - metric["buckets"] = b - metric["count"] = fmt.Sprint(m.GetHistogram().GetSampleCount()) - } else { - h, fh := histogram.NewModelHistogram(m.GetHistogram()) + dtoH := m.GetHistogram() + metric["sum"] = fmt.Sprint(dtoH.GetSampleSum()) + if len(dtoH.GetNegativeSpan())+len(dtoH.GetPositiveSpan()) > 0 { + h, fh := histogram.NewModelHistogram(dtoH) if h == nil { // float histogram metric["count"] = fmt.Sprint(fh.Count) @@ -245,6 +243,9 @@ func makeEncodableMetrics(metrics []*dto.Metric, metricsType dto.MetricType) []e metric["count"] = fmt.Sprint(h.Count) metric["buckets"] = histogram.BucketsAsJson[uint64](histogram.GetAPIBuckets(h)) } + } else { + metric["buckets"] = makeBuckets(m) + metric["count"] = fmt.Sprint(dtoH.GetSampleCount()) } default: metric["value"] = fmt.Sprint(getValue(m))