mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-14 19:31:11 +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 (
|
||||
"fmt"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"net"
|
||||
"testing"
|
||||
"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 {
|
||||
handlePacket(packet []byte, e chan<- Events)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue