Rename timer to observer in mapper

Signed-off-by: glightfoot <glightfoot@rsglab.com>
This commit is contained in:
glightfoot 2020-06-15 17:26:20 -04:00
parent d95a53553e
commit 32e9e58e32
8 changed files with 47 additions and 47 deletions

View file

@ -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

View file

@ -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())

View file

@ -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)
}()

View file

@ -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

View file

@ -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{}

View file

@ -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: {}
`,

View file

@ -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)
}

View file

@ -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
}