Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,6 @@ These will be used by all mappings that do not define them.
An option that can only be configured in `defaults` is `glob_disable_ordering`, which is `false` if omitted.
By setting this to `true`, `glob` match type will not honor the occurance of rules in the mapping rules file and always treat `*` as lower priority than a concrete string.

Setting `buckets` or `quantiles` in the defaults is deprecated in favor of `histogram_options` and `summary_options`, which will override the deprecated values.

If `summary_options` is present in a mapping config, it will only override the fields set in the mapping. Unset fields in the mapping will take the values from the defaults.

See [`config.exmple.yml`](config.example.yml) for an annotated example configuration.
Expand Down
2 changes: 0 additions & 2 deletions pkg/exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ func TestInconsistentLabelSets(t *testing.T) {
config := `
mappings:
- match: histogram.test
timer_type: histogram
name: "histogram_test"
`
testMapper := &mapper.MetricMapper{}
Expand Down Expand Up @@ -631,7 +630,6 @@ func TestConflictingMetrics(t *testing.T) {
config := `
mappings:
- match: histogram.*
timer_type: histogram
name: "histogram_${1}"
`
for _, s := range scenarios {
Expand Down
30 changes: 1 addition & 29 deletions pkg/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var defaultQuantiles = []MetricObjective{
func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
var n MetricMapper

if err := yaml.Unmarshal([]byte(fileContents), &n); err != nil {
if err := yaml.UnmarshalStrict([]byte(fileContents), &n); err != nil {
return err
}

Expand Down Expand Up @@ -172,38 +172,13 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
currentMapping.ObserverType = n.Defaults.ObserverType
}

if currentMapping.LegacyQuantiles != nil &&
(currentMapping.SummaryOptions == nil || currentMapping.SummaryOptions.Quantiles != nil) {
m.Logger.Warn("using the top level quantiles is deprecated. Please use quantiles in the summary_options hierarchy")
}

if currentMapping.LegacyBuckets != nil &&
(currentMapping.HistogramOptions == nil || currentMapping.HistogramOptions.Buckets != nil) {
m.Logger.Warn("using the top level buckets is deprecated. Please use buckets in the histogram_options hierarchy")
}

if currentMapping.SummaryOptions != nil &&
currentMapping.LegacyQuantiles != nil &&
currentMapping.SummaryOptions.Quantiles != nil {
return fmt.Errorf("cannot use quantiles in both the top level and summary options at the same time in %s", currentMapping.Match)
}

if currentMapping.HistogramOptions != nil &&
currentMapping.LegacyBuckets != nil &&
currentMapping.HistogramOptions.Buckets != nil {
return fmt.Errorf("cannot use buckets in both the top level and histogram options at the same time in %s", currentMapping.Match)
}

if currentMapping.ObserverType == ObserverTypeHistogram {
if currentMapping.SummaryOptions != nil {
return fmt.Errorf("cannot use histogram observer and summary options at the same time")
}
if currentMapping.HistogramOptions == nil {
currentMapping.HistogramOptions = &HistogramOptions{}
}
if len(currentMapping.LegacyBuckets) != 0 {
currentMapping.HistogramOptions.Buckets = currentMapping.LegacyBuckets
}
if len(currentMapping.HistogramOptions.Buckets) == 0 {
currentMapping.HistogramOptions.Buckets = n.Defaults.HistogramOptions.Buckets
}
Expand All @@ -216,9 +191,6 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
if currentMapping.SummaryOptions == nil {
currentMapping.SummaryOptions = &SummaryOptions{}
}
if len(currentMapping.LegacyQuantiles) != 0 {
currentMapping.SummaryOptions.Quantiles = currentMapping.LegacyQuantiles
}
if len(currentMapping.SummaryOptions.Quantiles) == 0 {
currentMapping.SummaryOptions.Quantiles = n.Defaults.SummaryOptions.Quantiles
}
Expand Down
47 changes: 0 additions & 47 deletions pkg/mapper/mapper_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,3 @@ type MapperConfigDefaults struct {
SummaryOptions SummaryOptions `yaml:"summary_options"`
HistogramOptions HistogramOptions `yaml:"histogram_options"`
}

// mapperConfigDefaultsAlias is used to unmarshal the yaml config into mapperConfigDefaults and allows deprecated fields
type mapperConfigDefaultsAlias struct {
ObserverType ObserverType `yaml:"observer_type"`
TimerType ObserverType `yaml:"timer_type,omitempty"` // DEPRECATED - field only present to preserve backwards compatibility in configs
Buckets []float64 `yaml:"buckets"` // DEPRECATED - field only present to preserve backwards compatibility in configs
Quantiles []MetricObjective `yaml:"quantiles"` // DEPRECATED - field only present to preserve backwards compatibility in configs
MatchType MatchType `yaml:"match_type"`
GlobDisableOrdering bool `yaml:"glob_disable_ordering"`
Ttl time.Duration `yaml:"ttl"`
SummaryOptions SummaryOptions `yaml:"summary_options"`
HistogramOptions HistogramOptions `yaml:"histogram_options"`
}

// UnmarshalYAML is a custom unmarshal function to allow use of deprecated config keys
// observer_type will override timer_type
func (d *MapperConfigDefaults) UnmarshalYAML(unmarshal func(interface{}) error) error {
var tmp mapperConfigDefaultsAlias
if err := unmarshal(&tmp); err != nil {
return err
}

// Copy defaults
d.ObserverType = tmp.ObserverType
d.MatchType = tmp.MatchType
d.GlobDisableOrdering = tmp.GlobDisableOrdering
d.Ttl = tmp.Ttl
d.SummaryOptions = tmp.SummaryOptions
d.HistogramOptions = tmp.HistogramOptions

// Use deprecated TimerType if necessary
if tmp.ObserverType == "" {
d.ObserverType = tmp.TimerType
}

// Use deprecated quantiles if necessary
if len(tmp.SummaryOptions.Quantiles) == 0 && len(tmp.Quantiles) > 0 {
d.SummaryOptions = SummaryOptions{Quantiles: tmp.Quantiles}
}

// Use deprecated buckets if necessary
if len(tmp.HistogramOptions.Buckets) == 0 && len(tmp.Buckets) > 0 {
d.HistogramOptions = HistogramOptions{Buckets: tmp.Buckets}
}

return nil
}
142 changes: 6 additions & 136 deletions pkg/mapper/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,38 +560,12 @@ mappings:
observer_type: summary
name: "foo"
labels: {}
quantiles:
- quantile: 0.42
error: 0.04
- quantile: 0.7
error: 0.002
`,
mappings: mappings{
{
statsdMetric: "test.*.*",
name: "foo",
labels: map[string]string{},
quantiles: []MetricObjective{
{Quantile: 0.42, Error: 0.04},
{Quantile: 0.7, Error: 0.002},
},
},
},
},
{
testName: "Config with good observer type and unused timer type",
config: `---
mappings:
- match: test.*.*
observer_type: summary
timer_type: histogram
name: "foo"
labels: {}
quantiles:
- quantile: 0.42
error: 0.04
- quantile: 0.7
error: 0.002
summary_options:
quantiles:
- quantile: 0.42
error: 0.04
- quantile: 0.7
error: 0.002
`,
mappings: mappings{
{
Expand All @@ -613,28 +587,6 @@ mappings:
observer_type: summary
name: "foo"
labels: {}
`,
mappings: mappings{
{
statsdMetric: "test1.*.*",
name: "foo",
labels: map[string]string{},
quantiles: []MetricObjective{
{Quantile: 0.5, Error: 0.05},
{Quantile: 0.9, Error: 0.01},
{Quantile: 0.99, Error: 0.001},
},
},
},
},
{
testName: "Config with good deprecated timer type",
config: `---
mappings:
- match: test1.*.*
timer_type: summary
name: "foo"
labels: {}
`,
mappings: mappings{
{
Expand All @@ -656,17 +608,6 @@ mappings:
- match: test.*.*
observer_type: wrong
name: "foo"
labels: {}
`,
configBad: true,
},
{
testName: "Config with bad deprecated timer type",
config: `---
mappings:
- match: test.*.*
timer_type: wrong
name: "foo"
labels: {}
`,
configBad: true,
Expand Down Expand Up @@ -791,45 +732,6 @@ mappings:
},
},
},
{
testName: "Config with default summary options overrides quantiles",
config: `---
defaults:
quantiles:
- quantile: 0.9
error: 0.1
- quantile: 0.99
error: 0.01
summary_options:
quantiles:
- quantile: 0.42
error: 0.04
- quantile: 0.7
error: 0.002
max_age: 5m
age_buckets: 2
buf_cap: 1000
mappings:
- match: test.*.*
observer_type: summary
name: "foo"
labels: {}
`,
mappings: mappings{
{
statsdMetric: "test.*.*",
name: "foo",
labels: map[string]string{},
quantiles: []MetricObjective{
{Quantile: 0.42, Error: 0.04},
{Quantile: 0.7, Error: 0.002},
},
maxAge: 5 * time.Minute,
ageBuckets: 2,
bufCap: 1000,
},
},
},
{
testName: "Config that overrides default summary options",
config: `---
Expand Down Expand Up @@ -1102,28 +1004,6 @@ mappings:
},
},
},
{
testName: "Config with default histogram options overrides buckets",
config: `---
defaults:
buckets: [0.2, 2, 20, 200, 2000]
histogram_options:
buckets: [0.1, 1, 10, 100, 1000]
mappings:
- match: test.*.*
observer_type: histogram
name: "foo"
labels: {}
`,
mappings: mappings{
{
statsdMetric: "test.*.*",
name: "foo",
labels: map[string]string{},
buckets: []float64{0.1, 1, 10, 100, 1000},
},
},
},
{
testName: "Config that overrides default histogram configuration",
config: `---
Expand Down Expand Up @@ -1215,16 +1095,6 @@ mappings:
- match: test.*.*
match_metric_type: observer
name: "foo"
labels: {}
`,
},
{
testName: "Config with good metric type timer",
config: `---
mappings:
- match: test.*.*
match_metric_type: timer
name: "foo"
labels: {}
`,
},
Expand Down
37 changes: 0 additions & 37 deletions pkg/mapper/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ type MetricMapping struct {
labelKeys []string
labelFormatters []*fsm.TemplateFormatter
ObserverType ObserverType `yaml:"observer_type"`
TimerType ObserverType `yaml:"timer_type,omitempty"` // DEPRECATED - field only present to preserve backwards compatibility in configs. Always empty
LegacyBuckets []float64 `yaml:"buckets"`
LegacyQuantiles []MetricObjective `yaml:"quantiles"`
MatchType MatchType `yaml:"match_type"`
HelpText string `yaml:"help"`
Action ActionType `yaml:"action"`
Expand All @@ -45,40 +42,6 @@ type MetricMapping struct {
Scale MaybeFloat64 `yaml:"scale"`
}

// UnmarshalYAML is a custom unmarshal function to allow use of deprecated config keys
// observer_type will override timer_type
func (m *MetricMapping) UnmarshalYAML(unmarshal func(interface{}) error) error {
type MetricMappingAlias MetricMapping
var tmp MetricMappingAlias
if err := unmarshal(&tmp); err != nil {
return err
}

// Copy defaults
m.Match = tmp.Match
m.Name = tmp.Name
m.Labels = tmp.Labels
m.HonorLabels = tmp.HonorLabels
m.ObserverType = tmp.ObserverType
m.LegacyBuckets = tmp.LegacyBuckets
m.LegacyQuantiles = tmp.LegacyQuantiles
m.MatchType = tmp.MatchType
m.HelpText = tmp.HelpText
m.Action = tmp.Action
m.MatchMetricType = tmp.MatchMetricType
m.Ttl = tmp.Ttl
m.SummaryOptions = tmp.SummaryOptions
m.HistogramOptions = tmp.HistogramOptions
m.Scale = tmp.Scale

// Use deprecated TimerType if necessary
if tmp.ObserverType == "" {
m.ObserverType = tmp.TimerType
}

return nil
}

type MaybeFloat64 struct {
Set bool
Val float64
Expand Down
3 changes: 0 additions & 3 deletions pkg/mapper/metric_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const (
MetricTypeCounter MetricType = "counter"
MetricTypeGauge MetricType = "gauge"
MetricTypeObserver MetricType = "observer"
MetricTypeTimer MetricType = "timer" // DEPRECATED
)

func (m *MetricType) UnmarshalYAML(unmarshal func(interface{}) error) error {
Expand All @@ -37,8 +36,6 @@ func (m *MetricType) UnmarshalYAML(unmarshal func(interface{}) error) error {
*m = MetricTypeGauge
case MetricTypeObserver:
*m = MetricTypeObserver
case MetricTypeTimer:
*m = MetricTypeObserver
default:
return fmt.Errorf("invalid metric type '%s'", v)
}
Expand Down