File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ package prometheus
16
16
import (
17
17
"fmt"
18
18
"hash/fnv"
19
+ "math"
19
20
"sort"
20
21
"sync"
21
22
"time"
@@ -277,20 +278,24 @@ func (s *summary) Write(out *dto.Metric) error {
277
278
278
279
s .bufMtx .Lock ()
279
280
s .mtx .Lock ()
280
-
281
- if len (s .hotBuf ) != 0 {
282
- s .swapBufs (time .Now ())
283
- }
281
+ // Swap bufs even if hotBuf is empty to set new hotBufExpTime.
282
+ s .swapBufs (time .Now ())
284
283
s .bufMtx .Unlock ()
285
284
286
285
s .flushColdBuf ()
287
286
sum .SampleCount = proto .Uint64 (s .cnt )
288
287
sum .SampleSum = proto .Float64 (s .sum )
289
288
290
289
for _ , rank := range s .sortedObjectives {
290
+ var q float64
291
+ if s .headStream .Count () == 0 {
292
+ q = math .NaN ()
293
+ } else {
294
+ q = s .headStream .Query (rank )
295
+ }
291
296
qs = append (qs , & dto.Quantile {
292
297
Quantile : proto .Float64 (rank ),
293
- Value : proto .Float64 (s . headStream . Query ( rank ) ),
298
+ Value : proto .Float64 (q ),
294
299
})
295
300
}
296
301
Original file line number Diff line number Diff line change @@ -289,6 +289,11 @@ func TestSummaryVecConcurrency(t *testing.T) {
289
289
}
290
290
291
291
func TestSummaryDecay (t * testing.T ) {
292
+ if testing .Short () {
293
+ t .Skip ("Skipping test in short mode." )
294
+ // More because it depends on timing than because it is particularly long...
295
+ }
296
+
292
297
sum := NewSummary (SummaryOpts {
293
298
Name : "test_summary" ,
294
299
Help : "helpless" ,
@@ -315,6 +320,12 @@ func TestSummaryDecay(t *testing.T) {
315
320
}
316
321
}
317
322
tick .Stop ()
323
+ // Wait for MaxAge without observations and make sure quantiles are NaN.
324
+ time .Sleep (100 * time .Millisecond )
325
+ sum .Write (m )
326
+ if got := * m .Summary .Quantile [0 ].Value ; ! math .IsNaN (got ) {
327
+ t .Errorf ("got %f, want NaN after expiration" , got )
328
+ }
318
329
}
319
330
320
331
func getBounds (vars []float64 , q , ε float64 ) (min , max float64 ) {
You can’t perform that action at this time.
0 commit comments