From 32e9e58e32ca1965a0892cdf137155c49b66a99f Mon Sep 17 00:00:00 2001 From: glightfoot Date: Mon, 15 Jun 2020 17:26:20 -0400 Subject: [PATCH] Rename timer to observer in mapper Signed-off-by: glightfoot --- pkg/event/event.go | 2 +- pkg/exporter/exporter.go | 12 ++++++------ pkg/exporter/exporter_test.go | 2 +- pkg/mapper/fsm/README.md | 10 +++++----- pkg/mapper/mapper.go | 18 +++++++++--------- pkg/mapper/mapper_test.go | 18 +++++++++--------- pkg/mapper/metric_type.go | 10 +++++----- pkg/mapper/{timer.go => observer.go} | 22 +++++++++++----------- 8 files changed, 47 insertions(+), 47 deletions(-) rename pkg/mapper/{timer.go => observer.go} (61%) diff --git a/pkg/event/event.go b/pkg/event/event.go index bfe0de3..9234db9 100644 --- a/pkg/event/event.go +++ b/pkg/event/event.go @@ -61,7 +61,7 @@ type ObserverEvent struct { 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 } +func (c *ObserverEvent) MetricType() mapper.MetricType { return mapper.MetricTypeObserver } type Events []Event diff --git a/pkg/exporter/exporter.go b/pkg/exporter/exporter.go index 8970367..e2f202d 100644 --- a/pkg/exporter/exporter.go +++ b/pkg/exporter/exporter.go @@ -141,16 +141,16 @@ func (b *Exporter) handleEvent(thisEvent event.Event) { } case *event.ObserverEvent: - t := mapper.TimerTypeDefault + t := mapper.ObserverTypeDefault if mapping != nil { - t = mapping.TimerType + t = mapping.ObserverType } - if t == mapper.TimerTypeDefault { - t = b.Mapper.Defaults.TimerType + if t == mapper.ObserverTypeDefault { + t = b.Mapper.Defaults.ObsereverType } switch t { - case mapper.TimerTypeHistogram: + case mapper.ObserverTypeHistogram: histogram, err := b.Registry.GetHistogram(metricName, prometheusLabels, help, mapping, b.MetricsCount) if err == nil { histogram.Observe(thisEvent.Value()) @@ -160,7 +160,7 @@ func (b *Exporter) handleEvent(thisEvent event.Event) { b.ConflictingEventStats.WithLabelValues("observer").Inc() } - case mapper.TimerTypeDefault, mapper.TimerTypeSummary: + case mapper.ObserverTypeDefault, mapper.ObserverTypeSummary: summary, err := b.Registry.GetSummary(metricName, prometheusLabels, help, mapping, b.MetricsCount) if err == nil { summary.Observe(thisEvent.Value()) diff --git a/pkg/exporter/exporter_test.go b/pkg/exporter/exporter_test.go index a58b735..2802ac1 100644 --- a/pkg/exporter/exporter_test.go +++ b/pkg/exporter/exporter_test.go @@ -711,7 +711,7 @@ func TestHistogramUnits(t *testing.T) { testMapper := mapper.MetricMapper{} testMapper.InitCache(0) ex := NewExporter(&testMapper, log.NewNopLogger(), eventsActions, eventsUnmapped, errorEventStats, eventStats, conflictingEventStats, metricsCount) - ex.Mapper.Defaults.TimerType = mapper.TimerTypeHistogram + ex.Mapper.Defaults.ObsereverType = mapper.ObserverTypeHistogram ex.Listen(events) }() diff --git a/pkg/mapper/fsm/README.md b/pkg/mapper/fsm/README.md index 722ee21..9d7da44 100644 --- a/pkg/mapper/fsm/README.md +++ b/pkg/mapper/fsm/README.md @@ -40,7 +40,7 @@ At first, the FSM only contains three states, representing three possible metric / (start)---- [counter] \ - '--- [ timer ] + '--- [observer] Adding a rule `client.*.request.count` with type `counter` will make the FSM to be: @@ -50,7 +50,7 @@ Adding a rule `client.*.request.count` with type `counter` will make the FSM to / (start)---- [counter] -- [client] -- [*] -- [request] -- [count] -- {R1} \ - '--- [timer] + '--- [observer] `{R1}` is short for result 1, which is the match result for `client.*.request.count`. @@ -60,7 +60,7 @@ Adding a rule `client.*.*.size` with type `counter` will make the FSM to be: / / (start)---- [counter] -- [client] -- [*] \ \__ [*] -- [size] -- {R2} - '--- [timer] + '--- [observer] ### Finding a result state in FSM @@ -76,7 +76,7 @@ FSM, the `^1` to `^7` symbols indicate how FSM will traversal in its tree: / / ^5 ^6 ^7 (start)---- [counter] -- [client] -- [*] ^1 \ ^2 ^3 \__ [*] -- [size] -- {R2} - '--- [timer] ^4 + '--- [observer] ^4 To map `client.bbb.request.size`, FSM will do a backtracking: @@ -86,7 +86,7 @@ To map `client.bbb.request.size`, FSM will do a backtracking: / / ^5 ^6 (start)---- [counter] -- [client] -- [*] ^1 \ ^2 ^3 \__ [*] -- [size] -- {R2} - '--- [timer] ^4 + '--- [observer] ^4 ^7 ^8 ^9 diff --git a/pkg/mapper/mapper.go b/pkg/mapper/mapper.go index 8aac9d1..dc9a17b 100644 --- a/pkg/mapper/mapper.go +++ b/pkg/mapper/mapper.go @@ -36,7 +36,7 @@ var ( ) type mapperConfigDefaults struct { - TimerType TimerType `yaml:"timer_type"` + ObsereverType ObserverType `yaml:"observer_type"` Buckets []float64 `yaml:"buckets"` Quantiles []metricObjective `yaml:"quantiles"` MatchType MatchType `yaml:"match_type"` @@ -64,7 +64,7 @@ type MetricMapping struct { Labels prometheus.Labels `yaml:"labels"` labelKeys []string labelFormatters []*fsm.TemplateFormatter - TimerType TimerType `yaml:"timer_type"` + ObserverType ObserverType `yaml:"observer_type"` LegacyBuckets []float64 `yaml:"buckets"` LegacyQuantiles []metricObjective `yaml:"quantiles"` MatchType MatchType `yaml:"match_type"` @@ -119,7 +119,7 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string, cacheSize int, op remainingMappingsCount := len(n.Mappings) - n.FSM = fsm.NewFSM([]string{string(MetricTypeCounter), string(MetricTypeGauge), string(MetricTypeTimer)}, + n.FSM = fsm.NewFSM([]string{string(MetricTypeCounter), string(MetricTypeGauge), string(MetricTypeObserver)}, remainingMappingsCount, n.Defaults.GlobDisableOrdering) for i := range n.Mappings { @@ -181,8 +181,8 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string, cacheSize int, op n.doRegex = true } - if currentMapping.TimerType == "" { - currentMapping.TimerType = n.Defaults.TimerType + if currentMapping.ObserverType == "" { + currentMapping.ObserverType = n.Defaults.ObsereverType } if currentMapping.LegacyQuantiles != nil && @@ -207,9 +207,9 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string, cacheSize int, op return fmt.Errorf("cannot use buckets in both the top level and histogram options at the same time in %s", currentMapping.Match) } - if currentMapping.TimerType == TimerTypeHistogram { + if currentMapping.ObserverType == ObserverTypeHistogram { if currentMapping.SummaryOptions != nil { - return fmt.Errorf("cannot use histogram timer and summary options at the same time") + return fmt.Errorf("cannot use histogram observer and summary options at the same time") } if currentMapping.HistogramOptions == nil { currentMapping.HistogramOptions = &HistogramOptions{} @@ -222,9 +222,9 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string, cacheSize int, op } } - if currentMapping.TimerType == TimerTypeSummary { + if currentMapping.ObserverType == ObserverTypeSummary { if currentMapping.HistogramOptions != nil { - return fmt.Errorf("cannot use summary timer and histogram options at the same time") + return fmt.Errorf("cannot use summary observer and histogram options at the same time") } if currentMapping.SummaryOptions == nil { currentMapping.SummaryOptions = &SummaryOptions{} diff --git a/pkg/mapper/mapper_test.go b/pkg/mapper/mapper_test.go index dc8a45d..f4de0b6 100644 --- a/pkg/mapper/mapper_test.go +++ b/pkg/mapper/mapper_test.go @@ -441,12 +441,12 @@ mappings: }, }, }, - // Config with good timer type. + // Config with good observer type. { config: `--- mappings: - match: test.*.* - timer_type: summary + observer_type: summary name: "foo" labels: {} quantiles: @@ -471,7 +471,7 @@ mappings: config: `--- mappings: - match: test1.*.* - timer_type: summary + observer_type: summary name: "foo" labels: {} `, @@ -488,12 +488,12 @@ mappings: }, }, }, - // Config with bad timer type. + // Config with bad observer type. { config: `--- mappings: - match: test.*.* - timer_type: wrong + observer_type: wrong name: "foo" labels: {} `, @@ -504,7 +504,7 @@ mappings: config: `--- mappings: - match: test.*.* - timer_type: summary + observer_type: summary name: "foo" labels: {} summary_options: @@ -531,7 +531,7 @@ mappings: config: `--- mappings: - match: test.*.* - timer_type: summary + observer_type: summary name: "foo" labels: {} summary_options: @@ -564,7 +564,7 @@ mappings: config: `--- mappings: - match: test.*.* - timer_type: summary + observer_type: summary name: "foo" labels: {} quantiles: @@ -638,7 +638,7 @@ mappings: config: `--- mappings: - match: foo.*.* - timer_type: summary + observer_type: summary name: "foo" labels: {} `, diff --git a/pkg/mapper/metric_type.go b/pkg/mapper/metric_type.go index 0a0810f..d98d80a 100644 --- a/pkg/mapper/metric_type.go +++ b/pkg/mapper/metric_type.go @@ -18,9 +18,9 @@ import "fmt" type MetricType string const ( - MetricTypeCounter MetricType = "counter" - MetricTypeGauge MetricType = "gauge" - MetricTypeTimer MetricType = "timer" + MetricTypeCounter MetricType = "counter" + MetricTypeGauge MetricType = "gauge" + MetricTypeObserver MetricType = "observer" ) func (m *MetricType) UnmarshalYAML(unmarshal func(interface{}) error) error { @@ -34,8 +34,8 @@ func (m *MetricType) UnmarshalYAML(unmarshal func(interface{}) error) error { *m = MetricTypeCounter case MetricTypeGauge: *m = MetricTypeGauge - case MetricTypeTimer: - *m = MetricTypeTimer + case MetricTypeObserver: + *m = MetricTypeObserver default: return fmt.Errorf("invalid metric type '%s'", v) } diff --git a/pkg/mapper/timer.go b/pkg/mapper/observer.go similarity index 61% rename from pkg/mapper/timer.go rename to pkg/mapper/observer.go index f1d2fb7..3d5da7e 100644 --- a/pkg/mapper/timer.go +++ b/pkg/mapper/observer.go @@ -15,27 +15,27 @@ package mapper import "fmt" -type TimerType string +type ObserverType string const ( - TimerTypeHistogram TimerType = "histogram" - TimerTypeSummary TimerType = "summary" - TimerTypeDefault TimerType = "" + ObserverTypeHistogram ObserverType = "histogram" + ObserverTypeSummary ObserverType = "summary" + ObserverTypeDefault ObserverType = "" ) -func (t *TimerType) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (t *ObserverType) UnmarshalYAML(unmarshal func(interface{}) error) error { var v string if err := unmarshal(&v); err != nil { return err } - switch TimerType(v) { - case TimerTypeHistogram: - *t = TimerTypeHistogram - case TimerTypeSummary, TimerTypeDefault: - *t = TimerTypeSummary + switch ObserverType(v) { + case ObserverTypeHistogram: + *t = ObserverTypeHistogram + case ObserverTypeSummary, ObserverTypeDefault: + *t = ObserverTypeSummary default: - return fmt.Errorf("invalid timer type '%s'", v) + return fmt.Errorf("invalid observer type '%s'", v) } return nil }