Skip to content

Commit f5ccf20

Browse files
committed
Merge pull request #95 from prometheus/beorn7/fixes
Fix two bugs (see commit descriptions).
2 parents 1cf6d4b + 715be73 commit f5ccf20

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ continue your journey:
88
1. See the [exposition library](prometheus/README.md) if you want to
99
export metrics to a Prometheus server or pushgateway
1010

11-
2. See the [consumption library](extraction/README.md) if you want to
11+
2. See the [consumption library](https://godoc.org/github.com/prometheus/client_golang/extraction) if you want to
1212
process metrics exported by a Prometheus client. (The Prometheus server
1313
is using that library.)
1414

prometheus/summary.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package prometheus
1616
import (
1717
"fmt"
1818
"hash/fnv"
19+
"math"
1920
"sort"
2021
"sync"
2122
"time"
@@ -277,20 +278,24 @@ func (s *summary) Write(out *dto.Metric) error {
277278

278279
s.bufMtx.Lock()
279280
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())
284283
s.bufMtx.Unlock()
285284

286285
s.flushColdBuf()
287286
sum.SampleCount = proto.Uint64(s.cnt)
288287
sum.SampleSum = proto.Float64(s.sum)
289288

290289
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+
}
291296
qs = append(qs, &dto.Quantile{
292297
Quantile: proto.Float64(rank),
293-
Value: proto.Float64(s.headStream.Query(rank)),
298+
Value: proto.Float64(q),
294299
})
295300
}
296301

prometheus/summary_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ func TestSummaryVecConcurrency(t *testing.T) {
289289
}
290290

291291
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+
292297
sum := NewSummary(SummaryOpts{
293298
Name: "test_summary",
294299
Help: "helpless",
@@ -315,6 +320,12 @@ func TestSummaryDecay(t *testing.T) {
315320
}
316321
}
317322
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+
}
318329
}
319330

320331
func getBounds(vars []float64, q, ε float64) (min, max float64) {

0 commit comments

Comments
 (0)