rename TimerEvent to ObserverEvent

Signed-off-by: glightfoot <glightfoot@rsglab.com>
This commit is contained in:
glightfoot 2020-06-12 08:42:09 -04:00
parent 01b19722d7
commit 374d202daa
6 changed files with 158 additions and 159 deletions

View file

@ -83,60 +83,60 @@ func TestHandlePacket(t *testing.T) {
name: "simple timer", name: "simple timer",
in: "foo:200|ms", in: "foo:200|ms",
out: event.Events{ out: event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.2, OValue: 0.2,
TLabels: map[string]string{}, OLabels: map[string]string{},
}, },
}, },
}, { }, {
name: "simple histogram", name: "simple histogram",
in: "foo:200|h", in: "foo:200|h",
out: event.Events{ out: event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 200, OValue: 200,
TLabels: map[string]string{}, OLabels: map[string]string{},
}, },
}, },
}, { }, {
name: "simple distribution", name: "simple distribution",
in: "foo:200|d", in: "foo:200|d",
out: event.Events{ out: event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 200, OValue: 200,
TLabels: map[string]string{}, OLabels: map[string]string{},
}, },
}, },
}, { }, {
name: "distribution with sampling", name: "distribution with sampling",
in: "foo:0.01|d|@0.2|#tag1:bar,#tag2:baz", in: "foo:0.01|d|@0.2|#tag1:bar,#tag2:baz",
out: event.Events{ out: event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.01, OValue: 0.01,
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"}, OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.01, OValue: 0.01,
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"}, OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.01, OValue: 0.01,
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"}, OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.01, OValue: 0.01,
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"}, OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.01, OValue: 0.01,
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"}, OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
}, },
}, },
}, { }, {
@ -265,30 +265,30 @@ func TestHandlePacket(t *testing.T) {
name: "histogram with sampling", name: "histogram with sampling",
in: "foo:0.01|h|@0.2|#tag1:bar,#tag2:baz", in: "foo:0.01|h|@0.2|#tag1:bar,#tag2:baz",
out: event.Events{ out: event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.01, OValue: 0.01,
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"}, OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.01, OValue: 0.01,
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"}, OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.01, OValue: 0.01,
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"}, OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.01, OValue: 0.01,
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"}, OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.01, OValue: 0.01,
TLabels: map[string]string{"tag1": "bar", "tag2": "baz"}, OLabels: map[string]string{"tag1": "bar", "tag2": "baz"},
}, },
}, },
}, { }, {
@ -321,15 +321,15 @@ func TestHandlePacket(t *testing.T) {
name: "combined multiline metrics", name: "combined multiline metrics",
in: "foo:200|ms:300|ms:5|c|@0.1:6|g\nbar:1|c:5|ms", in: "foo:200|ms:300|ms:5|c|@0.1:6|g\nbar:1|c:5|ms",
out: event.Events{ out: event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: .200, OValue: .200,
TLabels: map[string]string{}, OLabels: map[string]string{},
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: .300, OValue: .300,
TLabels: map[string]string{}, OLabels: map[string]string{},
}, },
&event.CounterEvent{ &event.CounterEvent{
CMetricName: "foo", CMetricName: "foo",
@ -346,26 +346,26 @@ func TestHandlePacket(t *testing.T) {
CValue: 1, CValue: 1,
CLabels: map[string]string{}, CLabels: map[string]string{},
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "bar", OMetricName: "bar",
TValue: .005, OValue: .005,
TLabels: map[string]string{}, OLabels: map[string]string{},
}, },
}, },
}, { }, {
name: "timings with sampling factor", name: "timings with sampling factor",
in: "foo.timing:0.5|ms|@0.1", in: "foo.timing:0.5|ms|@0.1",
out: event.Events{ out: event.Events{
&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.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}}, &event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: 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.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}}, &event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: 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.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}}, &event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: 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.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}}, &event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: 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.TimerEvent{TMetricName: "foo.timing", TValue: 0.0005, TLabels: map[string]string{}}, &event.ObserverEvent{OMetricName: "foo.timing", OValue: 0.0005, OLabels: map[string]string{}},
}, },
}, { }, {
name: "bad line", name: "bad line",
@ -426,30 +426,30 @@ func TestHandlePacket(t *testing.T) {
name: "ms timer with conversion to seconds", name: "ms timer with conversion to seconds",
in: "foo:200|ms", in: "foo:200|ms",
out: event.Events{ out: event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 0.2, OValue: 0.2,
TLabels: map[string]string{}, OLabels: map[string]string{},
}, },
}, },
}, { }, {
name: "histogram with no unit conversion", name: "histogram with no unit conversion",
in: "foo:200|h", in: "foo:200|h",
out: event.Events{ out: event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 200, OValue: 200,
TLabels: map[string]string{}, OLabels: map[string]string{},
}, },
}, },
}, { }, {
name: "distribution with no unit conversion", name: "distribution with no unit conversion",
in: "foo:200|d", in: "foo:200|d",
out: event.Events{ out: event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "foo", OMetricName: "foo",
TValue: 200, OValue: 200,
TLabels: map[string]string{}, OLabels: map[string]string{},
}, },
}, },
}, },
@ -584,9 +584,9 @@ mappings:
GValue: 200, GValue: 200,
}, },
// event with ttl = 2s from a mapping // event with ttl = 2s from a mapping
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "bazqux.main", OMetricName: "bazqux.main",
TValue: 42, OValue: 42,
}, },
} }

View file

@ -86,13 +86,13 @@ func BenchmarkExporterListener(b *testing.B) {
GMetricName: "gauge", GMetricName: "gauge",
GValue: 10, GValue: 10,
}, },
&event.TimerEvent{ // simple timer &event.ObserverEvent{ // simple timer
TMetricName: "timer", OMetricName: "timer",
TValue: 200, OValue: 200,
}, },
&event.TimerEvent{ // simple histogram &event.ObserverEvent{ // simple histogram
TMetricName: "histogram.test", OMetricName: "histogram.test",
TValue: 200, OValue: 200,
}, },
&event.CounterEvent{ // simple_tags &event.CounterEvent{ // simple_tags
CMetricName: "simple_tags", CMetricName: "simple_tags",

View file

@ -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) Labels() map[string]string { return c.GLabels }
func (c *GaugeEvent) MetricType() mapper.MetricType { return mapper.MetricTypeGauge } func (c *GaugeEvent) MetricType() mapper.MetricType { return mapper.MetricTypeGauge }
// TimerEvent now defaults to seconds units type ObserverEvent struct {
type TimerEvent struct { OMetricName string
TMetricName string OValue float64
TValue float64 OLabels map[string]string
TLabels map[string]string
} }
func (t *TimerEvent) MetricName() string { return t.TMetricName } func (t *ObserverEvent) MetricName() string { return t.OMetricName }
func (t *TimerEvent) Value() float64 { return t.TValue } func (t *ObserverEvent) Value() float64 { return t.OValue }
func (c *TimerEvent) Labels() map[string]string { return c.TLabels } func (c *ObserverEvent) Labels() map[string]string { return c.OLabels }
func (c *TimerEvent) MetricType() mapper.MetricType { return mapper.MetricTypeTimer } func (c *ObserverEvent) MetricType() mapper.MetricType { return mapper.MetricTypeTimer }
type Events []Event type Events []Event

View file

@ -140,7 +140,7 @@ func (b *Exporter) handleEvent(thisEvent event.Event) {
b.ConflictingEventStats.WithLabelValues("gauge").Inc() b.ConflictingEventStats.WithLabelValues("gauge").Inc()
} }
case *event.TimerEvent: case *event.ObserverEvent:
t := mapper.TimerTypeDefault t := mapper.TimerTypeDefault
if mapping != nil { if mapping != nil {
t = mapping.TimerType t = mapping.TimerType

View file

@ -228,25 +228,25 @@ func TestInconsistentLabelSets(t *testing.T) {
GValue: 1, GValue: 1,
GLabels: secondLabelSet, GLabels: secondLabelSet,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "histogram.test", OMetricName: "histogram.test",
TValue: 1, OValue: 1,
TLabels: firstLabelSet, OLabels: firstLabelSet,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "histogram.test", OMetricName: "histogram.test",
TValue: 1, OValue: 1,
TLabels: secondLabelSet, OLabels: secondLabelSet,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "summary_test", OMetricName: "summary_test",
TValue: 1, OValue: 1,
TLabels: firstLabelSet, OLabels: firstLabelSet,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "summary_test", OMetricName: "summary_test",
TValue: 1, OValue: 1,
TLabels: secondLabelSet, OLabels: secondLabelSet,
}, },
} }
events <- c events <- c
@ -427,9 +427,9 @@ func TestConflictingMetrics(t *testing.T) {
CMetricName: "histogram_test1", CMetricName: "histogram_test1",
CValue: 1, CValue: 1,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "histogram.test1", OMetricName: "histogram.test1",
TValue: 2, OValue: 2,
}, },
}, },
}, },
@ -441,9 +441,9 @@ func TestConflictingMetrics(t *testing.T) {
CMetricName: "histogram_test1_sum", CMetricName: "histogram_test1_sum",
CValue: 1, CValue: 1,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "histogram.test1", OMetricName: "histogram.test1",
TValue: 2, OValue: 2,
}, },
}, },
}, },
@ -455,9 +455,9 @@ func TestConflictingMetrics(t *testing.T) {
CMetricName: "histogram_test2_count", CMetricName: "histogram_test2_count",
CValue: 1, CValue: 1,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "histogram.test2", OMetricName: "histogram.test2",
TValue: 2, OValue: 2,
}, },
}, },
}, },
@ -469,9 +469,9 @@ func TestConflictingMetrics(t *testing.T) {
CMetricName: "histogram_test3_bucket", CMetricName: "histogram_test3_bucket",
CValue: 1, CValue: 1,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "histogram.test3", OMetricName: "histogram.test3",
TValue: 2, OValue: 2,
}, },
}, },
}, },
@ -483,9 +483,9 @@ func TestConflictingMetrics(t *testing.T) {
CMetricName: "cvsq_test", CMetricName: "cvsq_test",
CValue: 1, CValue: 1,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "cvsq_test", OMetricName: "cvsq_test",
TValue: 2, OValue: 2,
}, },
}, },
}, },
@ -497,9 +497,9 @@ func TestConflictingMetrics(t *testing.T) {
CMetricName: "cvsc_count", CMetricName: "cvsc_count",
CValue: 1, CValue: 1,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "cvsc", OMetricName: "cvsc",
TValue: 2, OValue: 2,
}, },
}, },
}, },
@ -511,9 +511,9 @@ func TestConflictingMetrics(t *testing.T) {
CMetricName: "cvss_sum", CMetricName: "cvss_sum",
CValue: 1, CValue: 1,
}, },
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "cvss", OMetricName: "cvss",
TValue: 2, OValue: 2,
}, },
}, },
}, },
@ -672,9 +672,9 @@ func TestSummaryWithQuantilesEmptyMapping(t *testing.T) {
name := "default_foo" name := "default_foo"
c := event.Events{ c := event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: name, OMetricName: name,
TValue: 300, OValue: 300,
}, },
} }
events <- c events <- c
@ -719,9 +719,9 @@ func TestHistogramUnits(t *testing.T) {
// Then close events channel to stop a listener. // Then close events channel to stop a listener.
name := "foo" name := "foo"
c := event.Events{ c := event.Events{
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: name, OMetricName: name,
TValue: .300, OValue: .300,
}, },
} }
events <- c events <- c
@ -867,9 +867,9 @@ mappings:
GValue: 200, GValue: 200,
}, },
// event with ttl = 2s from a mapping // event with ttl = 2s from a mapping
&event.TimerEvent{ &event.ObserverEvent{
TMetricName: "bazqux.main", OMetricName: "bazqux.main",
TValue: 42, OValue: 42,
}, },
} }

View file

@ -43,16 +43,16 @@ func buildEvent(statType, metric string, value float64, relative bool, labels ma
GLabels: labels, GLabels: labels,
}, nil }, nil
case "ms": case "ms":
return &event.TimerEvent{ return &event.ObserverEvent{
TMetricName: metric, OMetricName: metric,
TValue: float64(value) / 1000, // prometheus presumes seconds, statsd millisecond OValue: float64(value) / 1000, // prometheus presumes seconds, statsd millisecond
TLabels: labels, OLabels: labels,
}, nil }, nil
case "h", "d": case "h", "d":
return &event.TimerEvent{ return &event.ObserverEvent{
TMetricName: metric, OMetricName: metric,
TValue: float64(value), OValue: float64(value),
TLabels: labels, OLabels: labels,
}, nil }, nil
case "s": case "s":
return nil, fmt.Errorf("no support for StatsD sets") return nil, fmt.Errorf("no support for StatsD sets")