From 804675a5c572327f96bd6c2c5f95cb17f9dc21d6 Mon Sep 17 00:00:00 2001 From: simonhammes Date: Tue, 17 Mar 2026 23:46:25 +0100 Subject: [PATCH 1/2] Remove deprecated fields I also removed all test cases that turned out to be redundant Signed-off-by: simonhammes --- README.md | 2 - pkg/exporter/exporter_test.go | 2 - pkg/mapper/mapper.go | 28 ------- pkg/mapper/mapper_defaults.go | 47 ----------- pkg/mapper/mapper_test.go | 142 ++-------------------------------- pkg/mapper/mapping.go | 37 --------- pkg/mapper/metric_type.go | 3 - 7 files changed, 6 insertions(+), 255 deletions(-) diff --git a/README.md b/README.md index 067b74bb..1caea1ab 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/pkg/exporter/exporter_test.go b/pkg/exporter/exporter_test.go index a578674b..1d6ef260 100644 --- a/pkg/exporter/exporter_test.go +++ b/pkg/exporter/exporter_test.go @@ -245,7 +245,6 @@ func TestInconsistentLabelSets(t *testing.T) { config := ` mappings: - match: histogram.test - timer_type: histogram name: "histogram_test" ` testMapper := &mapper.MetricMapper{} @@ -631,7 +630,6 @@ func TestConflictingMetrics(t *testing.T) { config := ` mappings: - match: histogram.* - timer_type: histogram name: "histogram_${1}" ` for _, s := range scenarios { diff --git a/pkg/mapper/mapper.go b/pkg/mapper/mapper.go index 8bf3abb6..ac93e248 100644 --- a/pkg/mapper/mapper.go +++ b/pkg/mapper/mapper.go @@ -172,28 +172,6 @@ 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") @@ -201,9 +179,6 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error { 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 } @@ -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 } diff --git a/pkg/mapper/mapper_defaults.go b/pkg/mapper/mapper_defaults.go index c2112be0..022c48e0 100644 --- a/pkg/mapper/mapper_defaults.go +++ b/pkg/mapper/mapper_defaults.go @@ -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 -} diff --git a/pkg/mapper/mapper_test.go b/pkg/mapper/mapper_test.go index 4c19badd..f93c720f 100644 --- a/pkg/mapper/mapper_test.go +++ b/pkg/mapper/mapper_test.go @@ -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{ { @@ -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{ { @@ -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, @@ -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: `--- @@ -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: `--- @@ -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: {} `, }, diff --git a/pkg/mapper/mapping.go b/pkg/mapper/mapping.go index 80fb2a8a..96e4b1de 100644 --- a/pkg/mapper/mapping.go +++ b/pkg/mapper/mapping.go @@ -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"` @@ -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 diff --git a/pkg/mapper/metric_type.go b/pkg/mapper/metric_type.go index 920c16ed..d98d80a1 100644 --- a/pkg/mapper/metric_type.go +++ b/pkg/mapper/metric_type.go @@ -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 { @@ -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) } From ce6961dba0a5237f8f6c0e871eef519a40e5c7c4 Mon Sep 17 00:00:00 2001 From: simonhammes Date: Tue, 17 Mar 2026 23:47:05 +0100 Subject: [PATCH 2/2] Use yaml.UnmarshalStrict() Fixes #546 Supersedes #608 Signed-off-by: simonhammes --- pkg/mapper/mapper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/mapper/mapper.go b/pkg/mapper/mapper.go index ac93e248..669b69ab 100644 --- a/pkg/mapper/mapper.go +++ b/pkg/mapper/mapper.go @@ -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 }