Skip to content

Commit d9e86f9

Browse files
committed
fix timer count sampling, honor persist-count-keys
by handling the timer count with the plain counters also, BenchmarkManyDifferentSensors should clear the stats maps ...
1 parent 619304e commit d9e86f9

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

statsdaemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func packetHandler(s *Packet) {
146146
case "ms":
147147
// if missing gets nil []float64, works with append()
148148
timers[s.Bucket] = append(timers[s.Bucket], s.ValFlt)
149+
counters[s.Bucket+".count"] += float64(1 / s.Sampling)
149150
case "g":
150151
var gaugeValue float64
151152
if s.ValStr == "" {
@@ -339,7 +340,6 @@ func processTimers(buffer *bytes.Buffer, now int64, pctls Percentiles) int64 {
339340
fmt.Fprintf(buffer, "%s%s.mean%s %s %d\n", *prefix, bucket, *postfix, mean_s, now)
340341
fmt.Fprintf(buffer, "%s%s.upper%s %s %d\n", *prefix, bucket, *postfix, max_s, now)
341342
fmt.Fprintf(buffer, "%s%s.lower%s %s %d\n", *prefix, bucket, *postfix, min_s, now)
342-
fmt.Fprintf(buffer, "%s%s.count%s %d %d\n", *prefix, bucket, *postfix, count, now)
343343

344344
delete(timers, bucket)
345345
}

statsdaemon_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ func TestPacketHandlerGauge(t *testing.T) {
450450

451451
func TestPacketHandlerTimer(t *testing.T) {
452452
timers = make(map[string]Float64Slice)
453+
counters = make(map[string]float64)
453454

454455
p := &Packet{
455456
Bucket: "glork",
@@ -460,11 +461,13 @@ func TestPacketHandlerTimer(t *testing.T) {
460461
packetHandler(p)
461462
assert.Equal(t, len(timers["glork"]), 1)
462463
assert.Equal(t, timers["glork"][0], float64(320))
464+
assert.Equal(t, counters["glork.count"], 1.0)
463465

464466
p.ValFlt = float64(100)
465467
packetHandler(p)
466468
assert.Equal(t, len(timers["glork"]), 2)
467469
assert.Equal(t, timers["glork"][1], float64(100))
470+
assert.Equal(t, counters["glork.count"], 2.0)
468471
}
469472

470473
func TestPacketHandlerSet(t *testing.T) {
@@ -558,7 +561,7 @@ func TestProcessTimers(t *testing.T) {
558561
assert.Equal(t, string(lines[0]), "response_time.mean 20 1418052649")
559562
assert.Equal(t, string(lines[1]), "response_time.upper 30 1418052649")
560563
assert.Equal(t, string(lines[2]), "response_time.lower 0 1418052649")
561-
assert.Equal(t, string(lines[3]), "response_time.count 3 1418052649")
564+
// response_time.count handled by processCounters, not processTimers
562565

563566
num = processTimers(&buffer, now, Percentiles{})
564567
assert.Equal(t, num, int64(0))
@@ -769,7 +772,11 @@ func TestMultipleUDPSends(t *testing.T) {
769772
}
770773

771774
func BenchmarkManyDifferentSensors(t *testing.B) {
775+
counters = make(map[string]float64)
776+
gauges = make(map[string]float64)
777+
timers = make(map[string]Float64Slice)
772778
r := rand.New(rand.NewSource(438))
779+
773780
for i := 0; i < 1000; i++ {
774781
bucket := "response_time" + strconv.Itoa(i)
775782
for i := 0; i < 10000; i++ {
@@ -925,6 +932,7 @@ func BenchmarkPacketHandlerTimer(b *testing.B) {
925932
d1 := parseLine([]byte("glork.some.keyspace:3.7211|ms"))
926933
d2 := parseLine([]byte("glork.some.keyspace:11223|ms"))
927934
timers = make(map[string]Float64Slice)
935+
counters = make(map[string]float64)
928936

929937
for i := 0; i < b.N; i++ {
930938
packetHandler(d1)

0 commit comments

Comments
 (0)