@@ -16,10 +16,12 @@ package prometheus
1616import (
1717 "math"
1818 "testing"
19+ "time"
1920
2021 dto "github.com/prometheus/client_model/go"
2122
2223 "google.golang.org/protobuf/proto"
24+ "google.golang.org/protobuf/types/known/timestamppb"
2325)
2426
2527func TestBuildFQName (t * testing.T ) {
@@ -90,3 +92,29 @@ func TestWithExemplarsMetric(t *testing.T) {
9092 }
9193 })
9294}
95+
96+ func TestWithExemplarsNativeHistogramMetric (t * testing.T ) {
97+ t .Run ("histogram" , func (t * testing.T ) {
98+ // Create a constant histogram from values we got from a 3rd party telemetry system.
99+ h := MustNewConstNativeHistogram (
100+ NewDesc ("http_request_duration_seconds" , "A histogram of the HTTP request durations." , nil , nil ),
101+ 10 , 12.1 , map [int ]int64 {1 : 7 , 2 : 1 , 3 : 2 }, map [int ]int64 {}, 0 , 2 , 0.2 , time .Date (
102+ 2009 , 11 , 17 , 20 , 34 , 58 , 651387237 , time .UTC ))
103+ m := & withExemplarsMetric {Metric : h , exemplars : []* dto.Exemplar {
104+ {Value : proto .Float64 (2000.0 ), Timestamp : timestamppb .New (time .Date (2009 , 11 , 17 , 20 , 34 , 58 , 3243244 , time .UTC ))},
105+ }}
106+ metric := dto.Metric {}
107+ if err := m .Write (& metric ); err != nil {
108+ t .Fatal (err )
109+ }
110+ if want , got := 1 , len (metric .GetHistogram ().Exemplars ); want != got {
111+ t .Errorf ("want %v, got %v" , want , got )
112+ }
113+
114+ for _ , b := range metric .GetHistogram ().Bucket {
115+ if b .Exemplar != nil {
116+ t .Error ("Not expecting exemplar for bucket" )
117+ }
118+ }
119+ })
120+ }
0 commit comments