@@ -43,12 +43,34 @@ type PusherAppender struct {
43
43
pusher Pusher
44
44
labels []labels.Labels
45
45
samples []cortexpb.Sample
46
+ histogramLabels []labels.Labels
47
+ histograms []cortexpb.Histogram
46
48
userID string
47
49
evaluationDelay time.Duration
48
50
}
49
51
50
- func (a * PusherAppender ) AppendHistogram (storage.SeriesRef , labels.Labels , int64 , * histogram.Histogram , * histogram.FloatHistogram ) (storage.SeriesRef , error ) {
51
- return 0 , errors .New ("querying native histograms is not supported" )
52
+ func (a * PusherAppender ) AppendHistogram (_ storage.SeriesRef , l labels.Labels , t int64 , h * histogram.Histogram , fh * histogram.FloatHistogram ) (storage.SeriesRef , error ) {
53
+ if h == nil && fh == nil {
54
+ return 0 , errors .New ("no histogram" )
55
+ }
56
+
57
+ if h != nil {
58
+ // A histogram sample is considered stale if its sum is set to NaN.
59
+ // https://github.com/prometheus/prometheus/blob/b6ef745016fa9472fdd0ae20f75a9682e01d1e5c/tsdb/head_append.go#L339-L346
60
+ if a .evaluationDelay > 0 && (value .IsStaleNaN (h .Sum )) {
61
+ t -= a .evaluationDelay .Milliseconds ()
62
+ }
63
+ a .histograms = append (a .histograms , cortexpb .HistogramToHistogramProto (t , h ))
64
+ } else {
65
+ // A histogram sample is considered stale if its sum is set to NaN.
66
+ // https://github.com/prometheus/prometheus/blob/b6ef745016fa9472fdd0ae20f75a9682e01d1e5c/tsdb/head_append.go#L339-L346
67
+ if a .evaluationDelay > 0 && (value .IsStaleNaN (fh .Sum )) {
68
+ t -= a .evaluationDelay .Milliseconds ()
69
+ }
70
+ a .histograms = append (a .histograms , cortexpb .FloatHistogramToHistogramProto (t , fh ))
71
+ }
72
+ a .histogramLabels = append (a .histogramLabels , l )
73
+ return 0 , nil
52
74
}
53
75
54
76
func (a * PusherAppender ) Append (_ storage.SeriesRef , l labels.Labels , t int64 , v float64 ) (storage.SeriesRef , error ) {
@@ -85,10 +107,11 @@ func (a *PusherAppender) AppendExemplar(_ storage.SeriesRef, _ labels.Labels, _
85
107
func (a * PusherAppender ) Commit () error {
86
108
a .totalWrites .Inc ()
87
109
110
+ req := cortexpb .ToWriteRequest (a .labels , a .samples , nil , nil , cortexpb .RULE )
111
+ req .AddHistogramTimeSeries (a .histogramLabels , a .histograms )
88
112
// Since a.pusher is distributor, client.ReuseSlice will be called in a.pusher.Push.
89
113
// We shouldn't call client.ReuseSlice here.
90
- _ , err := a .pusher .Push (user .InjectOrgID (a .ctx , a .userID ), cortexpb .ToWriteRequest (a .labels , a .samples , nil , nil , cortexpb .RULE ))
91
-
114
+ _ , err := a .pusher .Push (user .InjectOrgID (a .ctx , a .userID ), req )
92
115
if err != nil {
93
116
// Don't report errors that ended with 4xx HTTP status code (series limits, duplicate samples, out of order, etc.)
94
117
if resp , ok := httpgrpc .HTTPResponseFromError (err ); ! ok || resp .Code / 100 != 4 {
@@ -98,6 +121,8 @@ func (a *PusherAppender) Commit() error {
98
121
99
122
a .labels = nil
100
123
a .samples = nil
124
+ a .histogramLabels = nil
125
+ a .histograms = nil
101
126
return err
102
127
}
103
128
@@ -108,6 +133,8 @@ func (a *PusherAppender) UpdateMetadata(_ storage.SeriesRef, _ labels.Labels, _
108
133
func (a * PusherAppender ) Rollback () error {
109
134
a .labels = nil
110
135
a .samples = nil
136
+ a .histogramLabels = nil
137
+ a .histograms = nil
111
138
return nil
112
139
}
113
140
0 commit comments