forked from mirrors/statsd_exporter
rename TimerEvent to ObserverEvent
Signed-off-by: glightfoot <glightfoot@rsglab.com>
This commit is contained in:
parent
01b19722d7
commit
374d202daa
6 changed files with 158 additions and 159 deletions
178
bridge_test.go
178
bridge_test.go
|
@ -83,60 +83,60 @@ func TestHandlePacket(t *testing.T) {
|
|||
name: "simple timer",
|
||||
in: "foo:200|ms",
|
||||
out: event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.2,
|
||||
TLabels: map[string]string{},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.2,
|
||||
OLabels: map[string]string{},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "simple histogram",
|
||||
in: "foo:200|h",
|
||||
out: event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 200,
|
||||
TLabels: map[string]string{},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 200,
|
||||
OLabels: map[string]string{},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "simple distribution",
|
||||
in: "foo:200|d",
|
||||
out: event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 200,
|
||||
TLabels: map[string]string{},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 200,
|
||||
OLabels: map[string]string{},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "distribution with sampling",
|
||||
in: "foo:0.01|d|@0.2|#tag1:bar,#tag2:baz",
|
||||
out: event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.01,
|
||||
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.01,
|
||||
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.01,
|
||||
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.01,
|
||||
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.01,
|
||||
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.01,
|
||||
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.01,
|
||||
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.01,
|
||||
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.01,
|
||||
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.01,
|
||||
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -265,30 +265,30 @@ func TestHandlePacket(t *testing.T) {
|
|||
name: "histogram with sampling",
|
||||
in: "foo:0.01|h|@0.2|#tag1:bar,#tag2:baz",
|
||||
out: event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.01,
|
||||
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.01,
|
||||
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.01,
|
||||
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.01,
|
||||
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.01,
|
||||
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.01,
|
||||
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.01,
|
||||
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.01,
|
||||
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.01,
|
||||
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.01,
|
||||
OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -321,15 +321,15 @@ func TestHandlePacket(t *testing.T) {
|
|||
name: "combined multiline metrics",
|
||||
in: "foo:200|ms:300|ms:5|c|@0.1:6|g\nbar:1|c:5|ms",
|
||||
out: event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: .200,
|
||||
TLabels: map[string]string{},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: .200,
|
||||
OLabels: map[string]string{},
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: .300,
|
||||
TLabels: map[string]string{},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: .300,
|
||||
OLabels: map[string]string{},
|
||||
},
|
||||
&event.CounterEvent{
|
||||
CMetricName: "foo",
|
||||
|
@ -346,26 +346,26 @@ func TestHandlePacket(t *testing.T) {
|
|||
CValue: 1,
|
||||
CLabels: map[string]string{},
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "bar",
|
||||
TValue: .005,
|
||||
TLabels: map[string]string{},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "bar",
|
||||
OValue: .005,
|
||||
OLabels: map[string]string{},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "timings with sampling factor",
|
||||
in: "foo.timing:0.5|ms|@0.1",
|
||||
out: event.Events{
|
||||
&event.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}},
|
||||
&event.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}},
|
||||
&event.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}},
|
||||
&event.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}},
|
||||
&event.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}},
|
||||
&event.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}},
|
||||
&event.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}},
|
||||
&event.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}},
|
||||
&event.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}},
|
||||
&event.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}},
|
||||
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
|
||||
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
|
||||
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
|
||||
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
|
||||
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
|
||||
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
|
||||
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
|
||||
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
|
||||
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
|
||||
&event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
|
||||
},
|
||||
}, {
|
||||
name: "bad line",
|
||||
|
@ -426,30 +426,30 @@ func TestHandlePacket(t *testing.T) {
|
|||
name: "ms timer with conversion to seconds",
|
||||
in: "foo:200|ms",
|
||||
out: event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 0.2,
|
||||
TLabels: map[string]string{},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 0.2,
|
||||
OLabels: map[string]string{},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "histogram with no unit conversion",
|
||||
in: "foo:200|h",
|
||||
out: event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 200,
|
||||
TLabels: map[string]string{},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 200,
|
||||
OLabels: map[string]string{},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "distribution with no unit conversion",
|
||||
in: "foo:200|d",
|
||||
out: event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: "foo",
|
||||
TValue: 200,
|
||||
TLabels: map[string]string{},
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "foo",
|
||||
OValue: 200,
|
||||
OLabels: map[string]string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -584,9 +584,9 @@ mappings:
|
|||
GValue: 200,
|
||||
},
|
||||
// event with ttl = 2s from a mapping
|
||||
&event.TimerEvent{
|
||||
TMetricName: "bazqux.main",
|
||||
TValue: 42,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "bazqux.main",
|
||||
OValue: 42,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -86,13 +86,13 @@ func BenchmarkExporterListener(b *testing.B) {
|
|||
GMetricName: "gauge",
|
||||
GValue: 10,
|
||||
},
|
||||
&event.TimerEvent{ // simple timer
|
||||
TMetricName: "timer",
|
||||
TValue: 200,
|
||||
&event.ObserverEvent{ // simple timer
|
||||
OMetricName: "timer",
|
||||
OValue: 200,
|
||||
},
|
||||
&event.TimerEvent{ // simple histogram
|
||||
TMetricName: "histogram.test",
|
||||
TValue: 200,
|
||||
&event.ObserverEvent{ // simple histogram
|
||||
OMetricName: "histogram.test",
|
||||
OValue: 200,
|
||||
},
|
||||
&event.CounterEvent{ // simple_tags
|
||||
CMetricName: "simple_tags",
|
||||
|
|
|
@ -52,17 +52,16 @@ func (g *GaugeEvent) Value() float64 { return g.GValue }
|
|||
func (c *GaugeEvent) Labels() map[string]string { return c.GLabels }
|
||||
func (c *GaugeEvent) MetricType() mapper.MetricType { return mapper.MetricTypeGauge }
|
||||
|
||||
// TimerEvent now defaults to seconds units
|
||||
type TimerEvent struct {
|
||||
TMetricName string
|
||||
TValue float64
|
||||
TLabels map[string]string
|
||||
type ObserverEvent struct {
|
||||
OMetricName string
|
||||
OValue float64
|
||||
OLabels map[string]string
|
||||
}
|
||||
|
||||
func (t *TimerEvent) MetricName() string { return t.TMetricName }
|
||||
func (t *TimerEvent) Value() float64 { return t.TValue }
|
||||
func (c *TimerEvent) Labels() map[string]string { return c.TLabels }
|
||||
func (c *TimerEvent) MetricType() mapper.MetricType { return mapper.MetricTypeTimer }
|
||||
func (t *ObserverEvent) MetricName() string { return t.OMetricName }
|
||||
func (t *ObserverEvent) Value() float64 { return t.OValue }
|
||||
func (c *ObserverEvent) Labels() map[string]string { return c.OLabels }
|
||||
func (c *ObserverEvent) MetricType() mapper.MetricType { return mapper.MetricTypeTimer }
|
||||
|
||||
type Events []Event
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ func (b *Exporter) handleEvent(thisEvent event.Event) {
|
|||
b.ConflictingEventStats.WithLabelValues("gauge").Inc()
|
||||
}
|
||||
|
||||
case *event.TimerEvent:
|
||||
case *event.ObserverEvent:
|
||||
t := mapper.TimerTypeDefault
|
||||
if mapping != nil {
|
||||
t = mapping.TimerType
|
||||
|
|
|
@ -228,25 +228,25 @@ func TestInconsistentLabelSets(t *testing.T) {
|
|||
GValue: 1,
|
||||
GLabels: secondLabelSet,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "histogram.test",
|
||||
TValue: 1,
|
||||
TLabels: firstLabelSet,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "histogram.test",
|
||||
OValue: 1,
|
||||
OLabels: firstLabelSet,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "histogram.test",
|
||||
TValue: 1,
|
||||
TLabels: secondLabelSet,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "histogram.test",
|
||||
OValue: 1,
|
||||
OLabels: secondLabelSet,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "summary_test",
|
||||
TValue: 1,
|
||||
TLabels: firstLabelSet,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "summary_test",
|
||||
OValue: 1,
|
||||
OLabels: firstLabelSet,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "summary_test",
|
||||
TValue: 1,
|
||||
TLabels: secondLabelSet,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "summary_test",
|
||||
OValue: 1,
|
||||
OLabels: secondLabelSet,
|
||||
},
|
||||
}
|
||||
events <- c
|
||||
|
@ -427,9 +427,9 @@ func TestConflictingMetrics(t *testing.T) {
|
|||
CMetricName: "histogram_test1",
|
||||
CValue: 1,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "histogram.test1",
|
||||
TValue: 2,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "histogram.test1",
|
||||
OValue: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -441,9 +441,9 @@ func TestConflictingMetrics(t *testing.T) {
|
|||
CMetricName: "histogram_test1_sum",
|
||||
CValue: 1,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "histogram.test1",
|
||||
TValue: 2,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "histogram.test1",
|
||||
OValue: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -455,9 +455,9 @@ func TestConflictingMetrics(t *testing.T) {
|
|||
CMetricName: "histogram_test2_count",
|
||||
CValue: 1,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "histogram.test2",
|
||||
TValue: 2,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "histogram.test2",
|
||||
OValue: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -469,9 +469,9 @@ func TestConflictingMetrics(t *testing.T) {
|
|||
CMetricName: "histogram_test3_bucket",
|
||||
CValue: 1,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "histogram.test3",
|
||||
TValue: 2,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "histogram.test3",
|
||||
OValue: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -483,9 +483,9 @@ func TestConflictingMetrics(t *testing.T) {
|
|||
CMetricName: "cvsq_test",
|
||||
CValue: 1,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "cvsq_test",
|
||||
TValue: 2,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "cvsq_test",
|
||||
OValue: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -497,9 +497,9 @@ func TestConflictingMetrics(t *testing.T) {
|
|||
CMetricName: "cvsc_count",
|
||||
CValue: 1,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "cvsc",
|
||||
TValue: 2,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "cvsc",
|
||||
OValue: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -511,9 +511,9 @@ func TestConflictingMetrics(t *testing.T) {
|
|||
CMetricName: "cvss_sum",
|
||||
CValue: 1,
|
||||
},
|
||||
&event.TimerEvent{
|
||||
TMetricName: "cvss",
|
||||
TValue: 2,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "cvss",
|
||||
OValue: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -672,9 +672,9 @@ func TestSummaryWithQuantilesEmptyMapping(t *testing.T) {
|
|||
|
||||
name := "default_foo"
|
||||
c := event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: name,
|
||||
TValue: 300,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: name,
|
||||
OValue: 300,
|
||||
},
|
||||
}
|
||||
events <- c
|
||||
|
@ -719,9 +719,9 @@ func TestHistogramUnits(t *testing.T) {
|
|||
// Then close events channel to stop a listener.
|
||||
name := "foo"
|
||||
c := event.Events{
|
||||
&event.TimerEvent{
|
||||
TMetricName: name,
|
||||
TValue: .300,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: name,
|
||||
OValue: .300,
|
||||
},
|
||||
}
|
||||
events <- c
|
||||
|
@ -867,9 +867,9 @@ mappings:
|
|||
GValue: 200,
|
||||
},
|
||||
// event with ttl = 2s from a mapping
|
||||
&event.TimerEvent{
|
||||
TMetricName: "bazqux.main",
|
||||
TValue: 42,
|
||||
&event.ObserverEvent{
|
||||
OMetricName: "bazqux.main",
|
||||
OValue: 42,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -43,16 +43,16 @@ func buildEvent(statType, metric string, value float64, relative bool, labels ma
|
|||
GLabels: labels,
|
||||
}, nil
|
||||
case "ms":
|
||||
return &event.TimerEvent{
|
||||
TMetricName: metric,
|
||||
TValue: float64(value) / 1000, // prometheus presumes seconds, statsd millisecond
|
||||
TLabels: labels,
|
||||
return &event.ObserverEvent{
|
||||
OMetricName: metric,
|
||||
OValue: float64(value) / 1000, // prometheus presumes seconds, statsd millisecond
|
||||
OLabels: labels,
|
||||
}, nil
|
||||
case "h", "d":
|
||||
return &event.TimerEvent{
|
||||
TMetricName: metric,
|
||||
TValue: float64(value),
|
||||
TLabels: labels,
|
||||
return &event.ObserverEvent{
|
||||
OMetricName: metric,
|
||||
OValue: float64(value),
|
||||
OLabels: labels,
|
||||
}, nil
|
||||
case "s":
|
||||
return nil, fmt.Errorf("no support for StatsD sets")
|
||||
|
|
Loading…
Reference in a new issue