forked from mirrors/statsd_exporter
Rename timer to observer in mapper
Signed-off-by: glightfoot <glightfoot@rsglab.com>
This commit is contained in:
parent
d95a53553e
commit
32e9e58e32
8 changed files with 47 additions and 47 deletions
|
@ -61,7 +61,7 @@ type ObserverEvent struct {
|
||||||
func (t *ObserverEvent) MetricName() string { return t.OMetricName }
|
func (t *ObserverEvent) MetricName() string { return t.OMetricName }
|
||||||
func (t *ObserverEvent) Value() float64 { return t.OValue }
|
func (t *ObserverEvent) Value() float64 { return t.OValue }
|
||||||
func (c *ObserverEvent) Labels() map[string]string { return c.OLabels }
|
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
|
type Events []Event
|
||||||
|
|
||||||
|
|
|
@ -141,16 +141,16 @@ func (b *Exporter) handleEvent(thisEvent event.Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case *event.ObserverEvent:
|
case *event.ObserverEvent:
|
||||||
t := mapper.TimerTypeDefault
|
t := mapper.ObserverTypeDefault
|
||||||
if mapping != nil {
|
if mapping != nil {
|
||||||
t = mapping.TimerType
|
t = mapping.ObserverType
|
||||||
}
|
}
|
||||||
if t == mapper.TimerTypeDefault {
|
if t == mapper.ObserverTypeDefault {
|
||||||
t = b.Mapper.Defaults.TimerType
|
t = b.Mapper.Defaults.ObsereverType
|
||||||
}
|
}
|
||||||
|
|
||||||
switch t {
|
switch t {
|
||||||
case mapper.TimerTypeHistogram:
|
case mapper.ObserverTypeHistogram:
|
||||||
histogram, err := b.Registry.GetHistogram(metricName, prometheusLabels, help, mapping, b.MetricsCount)
|
histogram, err := b.Registry.GetHistogram(metricName, prometheusLabels, help, mapping, b.MetricsCount)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
histogram.Observe(thisEvent.Value())
|
histogram.Observe(thisEvent.Value())
|
||||||
|
@ -160,7 +160,7 @@ func (b *Exporter) handleEvent(thisEvent event.Event) {
|
||||||
b.ConflictingEventStats.WithLabelValues("observer").Inc()
|
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)
|
summary, err := b.Registry.GetSummary(metricName, prometheusLabels, help, mapping, b.MetricsCount)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
summary.Observe(thisEvent.Value())
|
summary.Observe(thisEvent.Value())
|
||||||
|
|
|
@ -711,7 +711,7 @@ func TestHistogramUnits(t *testing.T) {
|
||||||
testMapper := mapper.MetricMapper{}
|
testMapper := mapper.MetricMapper{}
|
||||||
testMapper.InitCache(0)
|
testMapper.InitCache(0)
|
||||||
ex := NewExporter(&testMapper, log.NewNopLogger(), eventsActions, eventsUnmapped, errorEventStats, eventStats, conflictingEventStats, metricsCount)
|
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)
|
ex.Listen(events)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ At first, the FSM only contains three states, representing three possible metric
|
||||||
/
|
/
|
||||||
(start)---- [counter]
|
(start)---- [counter]
|
||||||
\
|
\
|
||||||
'--- [ timer ]
|
'--- [observer]
|
||||||
|
|
||||||
|
|
||||||
Adding a rule `client.*.request.count` with type `counter` will make the FSM to be:
|
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}
|
(start)---- [counter] -- [client] -- [*] -- [request] -- [count] -- {R1}
|
||||||
\
|
\
|
||||||
'--- [timer]
|
'--- [observer]
|
||||||
|
|
||||||
`{R1}` is short for result 1, which is the match result for `client.*.request.count`.
|
`{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] -- [*]
|
(start)---- [counter] -- [client] -- [*]
|
||||||
\ \__ [*] -- [size] -- {R2}
|
\ \__ [*] -- [size] -- {R2}
|
||||||
'--- [timer]
|
'--- [observer]
|
||||||
|
|
||||||
|
|
||||||
### Finding a result state in FSM
|
### 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
|
/ / ^5 ^6 ^7
|
||||||
(start)---- [counter] -- [client] -- [*]
|
(start)---- [counter] -- [client] -- [*]
|
||||||
^1 \ ^2 ^3 \__ [*] -- [size] -- {R2}
|
^1 \ ^2 ^3 \__ [*] -- [size] -- {R2}
|
||||||
'--- [timer] ^4
|
'--- [observer] ^4
|
||||||
|
|
||||||
|
|
||||||
To map `client.bbb.request.size`, FSM will do a backtracking:
|
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
|
/ / ^5 ^6
|
||||||
(start)---- [counter] -- [client] -- [*]
|
(start)---- [counter] -- [client] -- [*]
|
||||||
^1 \ ^2 ^3 \__ [*] -- [size] -- {R2}
|
^1 \ ^2 ^3 \__ [*] -- [size] -- {R2}
|
||||||
'--- [timer] ^4
|
'--- [observer] ^4
|
||||||
^7 ^8 ^9
|
^7 ^8 ^9
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type mapperConfigDefaults struct {
|
type mapperConfigDefaults struct {
|
||||||
TimerType TimerType `yaml:"timer_type"`
|
ObsereverType ObserverType `yaml:"observer_type"`
|
||||||
Buckets []float64 `yaml:"buckets"`
|
Buckets []float64 `yaml:"buckets"`
|
||||||
Quantiles []metricObjective `yaml:"quantiles"`
|
Quantiles []metricObjective `yaml:"quantiles"`
|
||||||
MatchType MatchType `yaml:"match_type"`
|
MatchType MatchType `yaml:"match_type"`
|
||||||
|
@ -64,7 +64,7 @@ type MetricMapping struct {
|
||||||
Labels prometheus.Labels `yaml:"labels"`
|
Labels prometheus.Labels `yaml:"labels"`
|
||||||
labelKeys []string
|
labelKeys []string
|
||||||
labelFormatters []*fsm.TemplateFormatter
|
labelFormatters []*fsm.TemplateFormatter
|
||||||
TimerType TimerType `yaml:"timer_type"`
|
ObserverType ObserverType `yaml:"observer_type"`
|
||||||
LegacyBuckets []float64 `yaml:"buckets"`
|
LegacyBuckets []float64 `yaml:"buckets"`
|
||||||
LegacyQuantiles []metricObjective `yaml:"quantiles"`
|
LegacyQuantiles []metricObjective `yaml:"quantiles"`
|
||||||
MatchType MatchType `yaml:"match_type"`
|
MatchType MatchType `yaml:"match_type"`
|
||||||
|
@ -119,7 +119,7 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string, cacheSize int, op
|
||||||
|
|
||||||
remainingMappingsCount := len(n.Mappings)
|
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)
|
remainingMappingsCount, n.Defaults.GlobDisableOrdering)
|
||||||
|
|
||||||
for i := range n.Mappings {
|
for i := range n.Mappings {
|
||||||
|
@ -181,8 +181,8 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string, cacheSize int, op
|
||||||
n.doRegex = true
|
n.doRegex = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentMapping.TimerType == "" {
|
if currentMapping.ObserverType == "" {
|
||||||
currentMapping.TimerType = n.Defaults.TimerType
|
currentMapping.ObserverType = n.Defaults.ObsereverType
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentMapping.LegacyQuantiles != nil &&
|
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)
|
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 {
|
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 {
|
if currentMapping.HistogramOptions == nil {
|
||||||
currentMapping.HistogramOptions = &HistogramOptions{}
|
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 {
|
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 {
|
if currentMapping.SummaryOptions == nil {
|
||||||
currentMapping.SummaryOptions = &SummaryOptions{}
|
currentMapping.SummaryOptions = &SummaryOptions{}
|
||||||
|
|
|
@ -441,12 +441,12 @@ mappings:
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Config with good timer type.
|
// Config with good observer type.
|
||||||
{
|
{
|
||||||
config: `---
|
config: `---
|
||||||
mappings:
|
mappings:
|
||||||
- match: test.*.*
|
- match: test.*.*
|
||||||
timer_type: summary
|
observer_type: summary
|
||||||
name: "foo"
|
name: "foo"
|
||||||
labels: {}
|
labels: {}
|
||||||
quantiles:
|
quantiles:
|
||||||
|
@ -471,7 +471,7 @@ mappings:
|
||||||
config: `---
|
config: `---
|
||||||
mappings:
|
mappings:
|
||||||
- match: test1.*.*
|
- match: test1.*.*
|
||||||
timer_type: summary
|
observer_type: summary
|
||||||
name: "foo"
|
name: "foo"
|
||||||
labels: {}
|
labels: {}
|
||||||
`,
|
`,
|
||||||
|
@ -488,12 +488,12 @@ mappings:
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Config with bad timer type.
|
// Config with bad observer type.
|
||||||
{
|
{
|
||||||
config: `---
|
config: `---
|
||||||
mappings:
|
mappings:
|
||||||
- match: test.*.*
|
- match: test.*.*
|
||||||
timer_type: wrong
|
observer_type: wrong
|
||||||
name: "foo"
|
name: "foo"
|
||||||
labels: {}
|
labels: {}
|
||||||
`,
|
`,
|
||||||
|
@ -504,7 +504,7 @@ mappings:
|
||||||
config: `---
|
config: `---
|
||||||
mappings:
|
mappings:
|
||||||
- match: test.*.*
|
- match: test.*.*
|
||||||
timer_type: summary
|
observer_type: summary
|
||||||
name: "foo"
|
name: "foo"
|
||||||
labels: {}
|
labels: {}
|
||||||
summary_options:
|
summary_options:
|
||||||
|
@ -531,7 +531,7 @@ mappings:
|
||||||
config: `---
|
config: `---
|
||||||
mappings:
|
mappings:
|
||||||
- match: test.*.*
|
- match: test.*.*
|
||||||
timer_type: summary
|
observer_type: summary
|
||||||
name: "foo"
|
name: "foo"
|
||||||
labels: {}
|
labels: {}
|
||||||
summary_options:
|
summary_options:
|
||||||
|
@ -564,7 +564,7 @@ mappings:
|
||||||
config: `---
|
config: `---
|
||||||
mappings:
|
mappings:
|
||||||
- match: test.*.*
|
- match: test.*.*
|
||||||
timer_type: summary
|
observer_type: summary
|
||||||
name: "foo"
|
name: "foo"
|
||||||
labels: {}
|
labels: {}
|
||||||
quantiles:
|
quantiles:
|
||||||
|
@ -638,7 +638,7 @@ mappings:
|
||||||
config: `---
|
config: `---
|
||||||
mappings:
|
mappings:
|
||||||
- match: foo.*.*
|
- match: foo.*.*
|
||||||
timer_type: summary
|
observer_type: summary
|
||||||
name: "foo"
|
name: "foo"
|
||||||
labels: {}
|
labels: {}
|
||||||
`,
|
`,
|
||||||
|
|
|
@ -18,9 +18,9 @@ import "fmt"
|
||||||
type MetricType string
|
type MetricType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MetricTypeCounter MetricType = "counter"
|
MetricTypeCounter MetricType = "counter"
|
||||||
MetricTypeGauge MetricType = "gauge"
|
MetricTypeGauge MetricType = "gauge"
|
||||||
MetricTypeTimer MetricType = "timer"
|
MetricTypeObserver MetricType = "observer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *MetricType) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (m *MetricType) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
@ -34,8 +34,8 @@ func (m *MetricType) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
*m = MetricTypeCounter
|
*m = MetricTypeCounter
|
||||||
case MetricTypeGauge:
|
case MetricTypeGauge:
|
||||||
*m = MetricTypeGauge
|
*m = MetricTypeGauge
|
||||||
case MetricTypeTimer:
|
case MetricTypeObserver:
|
||||||
*m = MetricTypeTimer
|
*m = MetricTypeObserver
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid metric type '%s'", v)
|
return fmt.Errorf("invalid metric type '%s'", v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,27 +15,27 @@ package mapper
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
type TimerType string
|
type ObserverType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TimerTypeHistogram TimerType = "histogram"
|
ObserverTypeHistogram ObserverType = "histogram"
|
||||||
TimerTypeSummary TimerType = "summary"
|
ObserverTypeSummary ObserverType = "summary"
|
||||||
TimerTypeDefault TimerType = ""
|
ObserverTypeDefault ObserverType = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *TimerType) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (t *ObserverType) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
var v string
|
var v string
|
||||||
if err := unmarshal(&v); err != nil {
|
if err := unmarshal(&v); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch TimerType(v) {
|
switch ObserverType(v) {
|
||||||
case TimerTypeHistogram:
|
case ObserverTypeHistogram:
|
||||||
*t = TimerTypeHistogram
|
*t = ObserverTypeHistogram
|
||||||
case TimerTypeSummary, TimerTypeDefault:
|
case ObserverTypeSummary, ObserverTypeDefault:
|
||||||
*t = TimerTypeSummary
|
*t = ObserverTypeSummary
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid timer type '%s'", v)
|
return fmt.Errorf("invalid observer type '%s'", v)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
Loading…
Reference in a new issue