Skip to content

Commit

Permalink
api: identify native histograms by presence if at least one span
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Fajerski <[email protected]>
  • Loading branch information
jan--f committed Jul 11, 2024
1 parent 42c4075 commit 8e2feac
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down

0 comments on commit 8e2feac

Please sign in to comment.