From 8b1189b8a733ce33e18f55c263351c163eaadfdb Mon Sep 17 00:00:00 2001 From: Shivanth Date: Sun, 17 Nov 2024 20:29:39 +0100 Subject: [PATCH 1/2] Add exemplars for native histograms --- prometheus/metric.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/prometheus/metric.go b/prometheus/metric.go index 592eec3..72536fc 100644 --- a/prometheus/metric.go +++ b/prometheus/metric.go @@ -186,6 +186,10 @@ func (m *withExemplarsMetric) Write(pb *dto.Metric) error { case pb.Counter != nil: pb.Counter.Exemplar = m.exemplars[len(m.exemplars)-1] case pb.Histogram != nil: + if *pb.Histogram.Schema > math.MinInt32 { + exemplars := m.exemplars + pb.Histogram.Exemplars = append(pb.Histogram.Exemplars, m.exemplars...) + } for _, e := range m.exemplars { // pb.Histogram.Bucket are sorted by UpperBound. i := sort.Search(len(pb.Histogram.Bucket), func(i int) bool { From 58d00f50d773a66ef7e78301a91e8c02d3bd0145 Mon Sep 17 00:00:00 2001 From: Shivanth Date: Sun, 17 Nov 2024 20:33:48 +0100 Subject: [PATCH 2/2] Remove unused variable --- prometheus/metric.go | 1 - 1 file changed, 1 deletion(-) diff --git a/prometheus/metric.go b/prometheus/metric.go index 72536fc..c587ee8 100644 --- a/prometheus/metric.go +++ b/prometheus/metric.go @@ -187,7 +187,6 @@ func (m *withExemplarsMetric) Write(pb *dto.Metric) error { pb.Counter.Exemplar = m.exemplars[len(m.exemplars)-1] case pb.Histogram != nil: if *pb.Histogram.Schema > math.MinInt32 { - exemplars := m.exemplars pb.Histogram.Exemplars = append(pb.Histogram.Exemplars, m.exemplars...) } for _, e := range m.exemplars {