forked from mirrors/statsd_exporter
Merge pull request #91 from drawks/issue-88
Resolves #88 - histograms use wrong units
This commit is contained in:
commit
d2ca0a8c0b
2 changed files with 42 additions and 1 deletions
|
@ -327,7 +327,7 @@ func (b *Exporter) Listen(e <-chan Events) {
|
|||
mapping,
|
||||
)
|
||||
if err == nil {
|
||||
histogram.Observe(event.Value())
|
||||
histogram.Observe(event.Value() / 1000) // prometheus presumes seconds, statsd millisecond
|
||||
eventStats.WithLabelValues("timer").Inc()
|
||||
} else {
|
||||
log.Errorf(regErrF, metricName, err)
|
||||
|
|
|
@ -18,6 +18,8 @@ import (
|
|||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// TestNegativeCounter validates when we send a negative
|
||||
|
@ -74,6 +76,45 @@ func TestInvalidUtf8InDatadogTagValue(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type MockHistogram struct {
|
||||
prometheus.Metric
|
||||
prometheus.Collector
|
||||
value float64
|
||||
}
|
||||
|
||||
func (h *MockHistogram) Observe(n float64) {
|
||||
h.value = n
|
||||
}
|
||||
|
||||
func TestHistogramUnits(t *testing.T) {
|
||||
events := make(chan Events, 1)
|
||||
name := "foo"
|
||||
c := Events{
|
||||
&TimerEvent{
|
||||
metricName: name,
|
||||
value: 300,
|
||||
},
|
||||
}
|
||||
events <- c
|
||||
ex := NewExporter(&metricMapper{}, true)
|
||||
ex.mapper.Defaults.TimerType = timerTypeHistogram
|
||||
|
||||
// Close channel to signify we are done with the listener after a short period.
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
close(events)
|
||||
}()
|
||||
mock := &MockHistogram{}
|
||||
key := hashNameAndLabels(name+"_timer", nil)
|
||||
ex.Histograms.Elements[key] = mock
|
||||
ex.Listen(events)
|
||||
if mock.value == 300 {
|
||||
t.Fatalf("Histogram observations not scaled into Seconds")
|
||||
} else if mock.value != .300 {
|
||||
t.Fatalf("Received unexpected value for histogram observation %f != .300", mock.value)
|
||||
}
|
||||
}
|
||||
|
||||
type statsDPacketHandler interface {
|
||||
handlePacket(packet []byte, e chan<- Events)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue