@@ -16,10 +16,12 @@ package prometheus
16
16
import (
17
17
"math"
18
18
"testing"
19
+ "time"
19
20
20
21
dto "github.com/prometheus/client_model/go"
21
22
22
23
"google.golang.org/protobuf/proto"
24
+ "google.golang.org/protobuf/types/known/timestamppb"
23
25
)
24
26
25
27
func TestBuildFQName (t * testing.T ) {
@@ -90,3 +92,29 @@ func TestWithExemplarsMetric(t *testing.T) {
90
92
}
91
93
})
92
94
}
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