mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-26 09:11:01 +00:00
Added test for histogram unit conversion
This commit is contained in:
parent
e37bee9bf2
commit
b2082eda2b
1 changed files with 39 additions and 0 deletions
|
@ -15,6 +15,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -74,6 +75,44 @@ 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)
|
||||||
|
c := Events{
|
||||||
|
&TimerEvent{
|
||||||
|
metricName: "foo",
|
||||||
|
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{}
|
||||||
|
ex.Histograms.Elements[7787632782521330630] = 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 {
|
type statsDPacketHandler interface {
|
||||||
handlePacket(packet []byte, e chan<- Events)
|
handlePacket(packet []byte, e chan<- Events)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue