From 82a899e891de6e8fb1f1414faf02e1b928be2662 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Fri, 2 Jun 2023 12:25:02 -0600 Subject: [PATCH] Move filtermetric config to filterconfig --- internal/filter/filterconfig/config.go | 50 +++++++++++++++ internal/filter/filtermetric/config.go | 59 ----------------- internal/filter/filtermetric/config_test.go | 7 ++- internal/filter/filtermetric/filtermetric.go | 7 ++- .../filter/filtermetric/filtermetric_test.go | 3 +- internal/filter/filtermetric/helpers_test.go | 7 ++- internal/filter/filtermetric/name_matcher.go | 3 +- processor/attributesprocessor/factory.go | 5 +- processor/filterprocessor/config.go | 5 +- processor/filterprocessor/config_test.go | 45 +++++++------ processor/filterprocessor/expr_test.go | 6 +- processor/filterprocessor/metrics.go | 4 +- processor/filterprocessor/metrics_test.go | 63 +++++++++---------- 13 files changed, 129 insertions(+), 135 deletions(-) delete mode 100644 internal/filter/filtermetric/config.go diff --git a/internal/filter/filterconfig/config.go b/internal/filter/filterconfig/config.go index 1cd5957b458f..8859e001339e 100644 --- a/internal/filter/filterconfig/config.go +++ b/internal/filter/filterconfig/config.go @@ -13,6 +13,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/traceutil" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset/regexp" ) // MatchConfig has two optional MatchProperties one to define what is processed @@ -224,3 +225,52 @@ type LogSeverityNumberMatchProperties struct { // If this is true, entries with undefined severity will match. MatchUndefined bool `mapstructure:"match_undefined"` } + +// MetricMatchType specifies the strategy for matching against `pmetric.Metric`s. This +// is distinct from filterset.MatchType which matches against metric (and +// tracing) names only. To support matching against metric names and +// `pmetric.Metric`s, filtermetric.MatchType is effectively a superset of +// filterset.MatchType. +type MetricMatchType string + +// These are the MetricMatchType that users can specify for filtering +// `pmetric.Metric`s. +const ( + MetricRegexp = MetricMatchType(filterset.Regexp) + MetricStrict = MetricMatchType(filterset.Strict) + MetricExpr = "expr" +) + +// MetricMatchProperties specifies the set of properties in a metric to match against and the +// type of string pattern matching to use. +type MetricMatchProperties struct { + // MatchType specifies the type of matching desired + MatchType MetricMatchType `mapstructure:"match_type"` + // RegexpConfig specifies options for the MetricRegexp match type + RegexpConfig *regexp.Config `mapstructure:"regexp"` + + // MetricNames specifies the list of string patterns to match metric names against. + // A match occurs if the metric name matches at least one string pattern in this list. + MetricNames []string `mapstructure:"metric_names"` + + // Expressions specifies the list of expr expressions to match metrics against. + // A match occurs if any datapoint in a metric matches at least one expression in this list. + Expressions []string `mapstructure:"expressions"` + + // ResourceAttributes defines a list of possible resource attributes to match metrics against. + // A match occurs if any resource attribute matches all expressions in this given list. + ResourceAttributes []Attribute `mapstructure:"resource_attributes"` +} + +func CreateMetricMatchPropertiesFromDefault(properties *MatchProperties) *MetricMatchProperties { + if properties == nil { + return nil + } + + return &MetricMatchProperties{ + MatchType: MetricMatchType(properties.Config.MatchType), + RegexpConfig: properties.Config.RegexpConfig, + MetricNames: properties.MetricNames, + ResourceAttributes: properties.Resources, + } +} diff --git a/internal/filter/filtermetric/config.go b/internal/filter/filtermetric/config.go deleted file mode 100644 index 710bd93e3662..000000000000 --- a/internal/filter/filtermetric/config.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package filtermetric // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filtermetric" - -import ( - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset/regexp" -) - -// MatchType specifies the strategy for matching against `pmetric.Metric`s. This -// is distinct from filterset.MatchType which matches against metric (and -// tracing) names only. To support matching against metric names and -// `pmetric.Metric`s, filtermetric.MatchType is effectively a superset of -// filterset.MatchType. -type MatchType string - -// These are the MatchTypes that users can specify for filtering -// `pmetric.Metric`s. -const ( - Regexp = MatchType(filterset.Regexp) - Strict = MatchType(filterset.Strict) - Expr MatchType = "expr" -) - -// MatchProperties specifies the set of properties in a metric to match against and the -// type of string pattern matching to use. -type MatchProperties struct { - // MatchType specifies the type of matching desired - MatchType MatchType `mapstructure:"match_type"` - // RegexpConfig specifies options for the Regexp match type - RegexpConfig *regexp.Config `mapstructure:"regexp"` - - // MetricNames specifies the list of string patterns to match metric names against. - // A match occurs if the metric name matches at least one string pattern in this list. - MetricNames []string `mapstructure:"metric_names"` - - // Expressions specifies the list of expr expressions to match metrics against. - // A match occurs if any datapoint in a metric matches at least one expression in this list. - Expressions []string `mapstructure:"expressions"` - - // ResourceAttributes defines a list of possible resource attributes to match metrics against. - // A match occurs if any resource attribute matches all expressions in this given list. - ResourceAttributes []filterconfig.Attribute `mapstructure:"resource_attributes"` -} - -func CreateMatchPropertiesFromDefault(properties *filterconfig.MatchProperties) *MatchProperties { - if properties == nil { - return nil - } - - return &MatchProperties{ - MatchType: MatchType(properties.Config.MatchType), - RegexpConfig: properties.Config.RegexpConfig, - MetricNames: properties.MetricNames, - ResourceAttributes: properties.Resources, - } -} diff --git a/internal/filter/filtermetric/config_test.go b/internal/filter/filtermetric/config_test.go index 1c4c6d248700..a98fcd062f85 100644 --- a/internal/filter/filtermetric/config_test.go +++ b/internal/filter/filtermetric/config_test.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset/regexp" ) @@ -30,7 +31,7 @@ var ( } ) -func createConfigWithRegexpOptions(filters []string, rCfg *regexp.Config) *MatchProperties { +func createConfigWithRegexpOptions(filters []string, rCfg *regexp.Config) *filterconfig.MetricMatchProperties { cfg := createConfig(filters, filterset.Regexp) cfg.RegexpConfig = rCfg return cfg @@ -40,12 +41,12 @@ func TestConfig(t *testing.T) { testFile := filepath.Join("testdata", "config.yaml") v, err := confmaptest.LoadConf(testFile) require.NoError(t, err) - testYamls := map[string]MatchProperties{} + testYamls := map[string]filterconfig.MetricMatchProperties{} require.NoErrorf(t, v.Unmarshal(&testYamls, confmap.WithErrorUnused()), "unable to unmarshal yaml from file %v", testFile) tests := []struct { name string - expCfg *MatchProperties + expCfg *filterconfig.MetricMatchProperties }{ { name: "config/regexp", diff --git a/internal/filter/filtermetric/filtermetric.go b/internal/filter/filtermetric/filtermetric.go index 97bd9a0a49e7..63baffbb1bd1 100644 --- a/internal/filter/filtermetric/filtermetric.go +++ b/internal/filter/filtermetric/filtermetric.go @@ -5,13 +5,14 @@ package filtermetric // import "github.com/open-telemetry/opentelemetry-collecto import ( "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/expr" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlmetric" ) // NewSkipExpr creates a BoolExpr that on evaluation returns true if a metric should NOT be processed or kept. // The logic determining if a metric should be processed is based on include and exclude settings. // Include properties are checked before exclude settings are checked. -func NewSkipExpr(include *MatchProperties, exclude *MatchProperties) (expr.BoolExpr[ottlmetric.TransformContext], error) { +func NewSkipExpr(include *filterconfig.MetricMatchProperties, exclude *filterconfig.MetricMatchProperties) (expr.BoolExpr[ottlmetric.TransformContext], error) { var matchers []expr.BoolExpr[ottlmetric.TransformContext] inclExpr, err := newExpr(include) if err != nil { @@ -32,12 +33,12 @@ func NewSkipExpr(include *MatchProperties, exclude *MatchProperties) (expr.BoolE // NewMatcher constructs a metric Matcher. If an 'expr' match type is specified, // returns an expr matcher, otherwise a name matcher. -func newExpr(mp *MatchProperties) (expr.BoolExpr[ottlmetric.TransformContext], error) { +func newExpr(mp *filterconfig.MetricMatchProperties) (expr.BoolExpr[ottlmetric.TransformContext], error) { if mp == nil { return nil, nil } - if mp.MatchType == Expr { + if mp.MatchType == filterconfig.MetricExpr { if len(mp.Expressions) == 0 { return nil, nil } diff --git a/internal/filter/filtermetric/filtermetric_test.go b/internal/filter/filtermetric/filtermetric_test.go index e4cbe7085a15..ad850d36e556 100644 --- a/internal/filter/filtermetric/filtermetric_test.go +++ b/internal/filter/filtermetric/filtermetric_test.go @@ -11,6 +11,7 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlmetric" ) @@ -43,7 +44,7 @@ func createMetric(name string) pmetric.Metric { func TestMatcherMatches(t *testing.T) { tests := []struct { name string - cfg *MatchProperties + cfg *filterconfig.MetricMatchProperties metric pmetric.Metric shouldMatch bool }{ diff --git a/internal/filter/filtermetric/helpers_test.go b/internal/filter/filtermetric/helpers_test.go index b0b745417406..283718e5cf6d 100644 --- a/internal/filter/filtermetric/helpers_test.go +++ b/internal/filter/filtermetric/helpers_test.go @@ -4,12 +4,13 @@ package filtermetric import ( + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" ) -func createConfig(filters []string, matchType filterset.MatchType) *MatchProperties { - return &MatchProperties{ - MatchType: MatchType(matchType), +func createConfig(filters []string, matchType filterset.MatchType) *filterconfig.MetricMatchProperties { + return &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricMatchType(matchType), MetricNames: filters, } } diff --git a/internal/filter/filtermetric/name_matcher.go b/internal/filter/filtermetric/name_matcher.go index 350139af819e..a27b8fa6fb28 100644 --- a/internal/filter/filtermetric/name_matcher.go +++ b/internal/filter/filtermetric/name_matcher.go @@ -6,6 +6,7 @@ package filtermetric // import "github.com/open-telemetry/opentelemetry-collecto import ( "context" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlmetric" ) @@ -15,7 +16,7 @@ type nameMatcher struct { nameFilters filterset.FilterSet } -func newNameMatcher(mp *MatchProperties) (*nameMatcher, error) { +func newNameMatcher(mp *filterconfig.MetricMatchProperties) (*nameMatcher, error) { nameFS, err := filterset.CreateFilterSet( mp.MetricNames, &filterset.Config{ diff --git a/processor/attributesprocessor/factory.go b/processor/attributesprocessor/factory.go index 237315f2732a..069db38d0447 100644 --- a/processor/attributesprocessor/factory.go +++ b/processor/attributesprocessor/factory.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/collector/processor/processorhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/attraction" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterlog" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filtermetric" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterspan" @@ -99,8 +100,8 @@ func createMetricsProcessor( } skipExpr, err := filtermetric.NewSkipExpr( - filtermetric.CreateMatchPropertiesFromDefault(oCfg.Include), - filtermetric.CreateMatchPropertiesFromDefault(oCfg.Exclude), + filterconfig.CreateMetricMatchPropertiesFromDefault(oCfg.Include), + filterconfig.CreateMetricMatchPropertiesFromDefault(oCfg.Exclude), ) if err != nil { return nil, err diff --git a/processor/filterprocessor/config.go b/processor/filterprocessor/config.go index 2f6a40382f56..0f4234bf2054 100644 --- a/processor/filterprocessor/config.go +++ b/processor/filterprocessor/config.go @@ -14,7 +14,6 @@ import ( "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filtermetric" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterottl" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset/regexp" @@ -45,12 +44,12 @@ type MetricFilters struct { // Include match properties describe metrics that should be included in the Collector Service pipeline, // all other metrics should be dropped from further processing. // If both Include and Exclude are specified, Include filtering occurs first. - Include *filtermetric.MatchProperties `mapstructure:"include"` + Include *filterconfig.MetricMatchProperties `mapstructure:"include"` // Exclude match properties describe metrics that should be excluded from the Collector Service pipeline, // all other metrics should be included. // If both Include and Exclude are specified, Include filtering occurs first. - Exclude *filtermetric.MatchProperties `mapstructure:"exclude"` + Exclude *filterconfig.MetricMatchProperties `mapstructure:"exclude"` // RegexpConfig specifies options for the Regexp match type RegexpConfig *regexp.Config `mapstructure:"regexp"` diff --git a/processor/filterprocessor/config_test.go b/processor/filterprocessor/config_test.go index 465b310e937a..3725043675ff 100644 --- a/processor/filterprocessor/config_test.go +++ b/processor/filterprocessor/config_test.go @@ -14,7 +14,6 @@ import ( "go.opentelemetry.io/collector/pdata/plog" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filtermetric" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" fsregexp "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset/regexp" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" @@ -29,8 +28,8 @@ func TestLoadingConfigStrict(t *testing.T) { "hello/world", } - testDataMetricProperties := &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + testDataMetricProperties := &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, MetricNames: testDataFilters, } cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config_strict.yaml")) @@ -45,8 +44,8 @@ func TestLoadingConfigStrict(t *testing.T) { expected: &Config{ ErrorMode: ottl.PropagateError, Metrics: MetricFilters{ - Include: &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + Include: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, }, }, }, @@ -72,8 +71,8 @@ func TestLoadingConfigStrict(t *testing.T) { ErrorMode: ottl.PropagateError, Metrics: MetricFilters{ Include: testDataMetricProperties, - Exclude: &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + Exclude: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, MetricNames: []string{"hello_world"}, }, }, @@ -509,8 +508,8 @@ func TestLoadingConfigRegexp(t *testing.T) { "full_name_match", } - testDataMetricProperties := &filtermetric.MatchProperties{ - MatchType: filtermetric.Regexp, + testDataMetricProperties := &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricRegexp, MetricNames: testDataFilters, } @@ -542,8 +541,8 @@ func TestLoadingConfigRegexp(t *testing.T) { expected: &Config{ ErrorMode: ottl.PropagateError, Metrics: MetricFilters{ - Include: &filtermetric.MatchProperties{ - MatchType: filtermetric.Regexp, + Include: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricRegexp, RegexpConfig: &fsregexp.Config{ CacheEnabled: true, }, @@ -556,8 +555,8 @@ func TestLoadingConfigRegexp(t *testing.T) { expected: &Config{ ErrorMode: ottl.PropagateError, Metrics: MetricFilters{ - Exclude: &filtermetric.MatchProperties{ - MatchType: filtermetric.Regexp, + Exclude: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricRegexp, RegexpConfig: &fsregexp.Config{ CacheEnabled: true, CacheMaxNumEntries: 10, @@ -647,8 +646,8 @@ func TestLoadingConfigExpr(t *testing.T) { expected: &Config{ ErrorMode: ottl.PropagateError, Metrics: MetricFilters{ - Include: &filtermetric.MatchProperties{ - MatchType: filtermetric.Expr, + Include: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricExpr, }, }, }, @@ -658,8 +657,8 @@ func TestLoadingConfigExpr(t *testing.T) { expected: &Config{ ErrorMode: ottl.PropagateError, Metrics: MetricFilters{ - Include: &filtermetric.MatchProperties{ - MatchType: filtermetric.Expr, + Include: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricExpr, Expressions: []string{ `Label("foo") == "bar"`, `HasLabel("baz")`, @@ -673,8 +672,8 @@ func TestLoadingConfigExpr(t *testing.T) { expected: &Config{ ErrorMode: ottl.PropagateError, Metrics: MetricFilters{ - Exclude: &filtermetric.MatchProperties{ - MatchType: filtermetric.Expr, + Exclude: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricExpr, Expressions: []string{ `Label("foo") == "bar"`, `HasLabel("baz")`, @@ -688,14 +687,14 @@ func TestLoadingConfigExpr(t *testing.T) { expected: &Config{ ErrorMode: ottl.PropagateError, Metrics: MetricFilters{ - Include: &filtermetric.MatchProperties{ - MatchType: filtermetric.Expr, + Include: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricExpr, Expressions: []string{ `HasLabel("foo")`, }, }, - Exclude: &filtermetric.MatchProperties{ - MatchType: filtermetric.Expr, + Exclude: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricExpr, Expressions: []string{ `HasLabel("bar")`, }, diff --git a/processor/filterprocessor/expr_test.go b/processor/filterprocessor/expr_test.go index 37eedde3807f..bd804cbf955c 100644 --- a/processor/filterprocessor/expr_test.go +++ b/processor/filterprocessor/expr_test.go @@ -18,7 +18,7 @@ import ( "go.opentelemetry.io/collector/processor/processortest" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/goldendataset" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filtermetric" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" ) const filteredMetric = "p0_metric_1" @@ -142,13 +142,13 @@ func exprConfig(factory processor.Factory, include []string, exclude []string) c pCfg := cfg.(*Config) pCfg.Metrics = MetricFilters{} if include != nil { - pCfg.Metrics.Include = &filtermetric.MatchProperties{ + pCfg.Metrics.Include = &filterconfig.MetricMatchProperties{ MatchType: "expr", Expressions: include, } } if exclude != nil { - pCfg.Metrics.Exclude = &filtermetric.MatchProperties{ + pCfg.Metrics.Exclude = &filterconfig.MetricMatchProperties{ MatchType: "expr", Expressions: exclude, } diff --git a/processor/filterprocessor/metrics.go b/processor/filterprocessor/metrics.go index 4c28568cc4d8..2012838506dc 100644 --- a/processor/filterprocessor/metrics.go +++ b/processor/filterprocessor/metrics.go @@ -171,7 +171,7 @@ func (fmp *filterMetricProcessor) processMetrics(ctx context.Context, md pmetric return md, nil } -func newSkipResExpr(include *filtermetric.MatchProperties, exclude *filtermetric.MatchProperties) (expr.BoolExpr[ottlresource.TransformContext], error) { +func newSkipResExpr(include *filterconfig.MetricMatchProperties, exclude *filterconfig.MetricMatchProperties) (expr.BoolExpr[ottlresource.TransformContext], error) { var matchers []expr.BoolExpr[ottlresource.TransformContext] inclExpr, err := newResExpr(include) if err != nil { @@ -196,7 +196,7 @@ func (r resExpr) Eval(_ context.Context, tCtx ottlresource.TransformContext) (bo return filtermatcher.AttributesMatcher(r).Match(tCtx.GetResource().Attributes()), nil } -func newResExpr(mp *filtermetric.MatchProperties) (expr.BoolExpr[ottlresource.TransformContext], error) { +func newResExpr(mp *filterconfig.MetricMatchProperties) (expr.BoolExpr[ottlresource.TransformContext], error) { if mp == nil { return nil, nil } diff --git a/processor/filterprocessor/metrics_test.go b/processor/filterprocessor/metrics_test.go index 5978ee1af808..c2aa12c82f8b 100644 --- a/processor/filterprocessor/metrics_test.go +++ b/processor/filterprocessor/metrics_test.go @@ -20,14 +20,13 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/goldendataset" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filtermetric" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" ) type metricNameTest struct { name string - inc *filtermetric.MatchProperties - exc *filtermetric.MatchProperties + inc *filterconfig.MetricMatchProperties + exc *filterconfig.MetricMatchProperties inMetrics pmetric.Metrics outMN [][]string // output Metric names per Resource } @@ -92,8 +91,8 @@ var ( }, } - regexpMetricsFilterProperties = &filtermetric.MatchProperties{ - MatchType: filtermetric.Regexp, + regexpMetricsFilterProperties = &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricRegexp, MetricNames: validFilters, } @@ -129,8 +128,8 @@ var ( { name: "includeAndExclude", inc: regexpMetricsFilterProperties, - exc: &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + exc: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, MetricNames: []string{ "prefix_test_match", "test_contains_match", @@ -154,8 +153,8 @@ var ( { name: "includeAndExcludeWithEmptyResourceMetrics", inc: regexpMetricsFilterProperties, - exc: &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + exc: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, MetricNames: []string{ "prefix_test_match", "test_contains_match", @@ -180,13 +179,13 @@ var ( }, { name: "emptyFilterInclude", - inc: &filtermetric.MatchProperties{MatchType: filtermetric.Strict}, + inc: &filterconfig.MetricMatchProperties{MatchType: filterconfig.MetricStrict}, inMetrics: testResourceMetrics([]metricWithResource{{metricNames: inMetricNames}}), outMN: [][]string{inMetricNames}, }, { name: "emptyFilterExclude", - exc: &filtermetric.MatchProperties{MatchType: filtermetric.Strict}, + exc: &filterconfig.MetricMatchProperties{MatchType: filterconfig.MetricStrict}, inMetrics: testResourceMetrics([]metricWithResource{{metricNames: inMetricNames}}), outMN: [][]string{inMetricNames}, }, @@ -210,8 +209,8 @@ var ( }, { name: "excludeNilWithResourceAttributes", - exc: &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + exc: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, }, inMetrics: testResourceMetrics(inMetricForResourceTest), outMN: [][]string{ @@ -220,8 +219,8 @@ var ( }, { name: "includeAllWithResourceAttributes", - inc: &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + inc: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, MetricNames: []string{ "metric1", "metric2", @@ -235,8 +234,8 @@ var ( }, { name: "includeAllWithMissingResourceAttributes", - inc: &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + inc: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, MetricNames: []string{ "metric1", "metric2", @@ -252,8 +251,8 @@ var ( }, { name: "excludeAllWithMissingResourceAttributes", - exc: &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + exc: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, ResourceAttributes: []filterconfig.Attribute{{Key: "attr1", Value: "attr1/val1"}}, }, inMetrics: testResourceMetrics(inMetricForTwoResource), @@ -263,8 +262,8 @@ var ( }, { name: "includeWithRegexResourceAttributes", - inc: &filtermetric.MatchProperties{ - MatchType: filtermetric.Regexp, + inc: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricRegexp, MetricNames: []string{ ".*", }, @@ -277,8 +276,8 @@ var ( }, { name: "includeWithRegexResourceAttributesOnly", - inc: &filtermetric.MatchProperties{ - MatchType: filtermetric.Regexp, + inc: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricRegexp, ResourceAttributes: []filterconfig.Attribute{{Key: "attr1", Value: "attr1/val1"}}, }, inMetrics: testResourceMetrics(inMetricForTwoResource), @@ -288,8 +287,8 @@ var ( }, { name: "includeWithStrictResourceAttributes", - inc: &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + inc: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, MetricNames: []string{ "metric1", "metric2", @@ -303,8 +302,8 @@ var ( }, { name: "includeWithStrictResourceAttributesOnly", - inc: &filtermetric.MatchProperties{ - MatchType: filtermetric.Strict, + inc: &filterconfig.MetricMatchProperties{ + MatchType: filterconfig.MetricStrict, ResourceAttributes: []filterconfig.Attribute{{Key: "attr1", Value: "attr1/val1"}}, }, inMetrics: testResourceMetrics(inMetricForTwoResource), @@ -385,7 +384,7 @@ func testResourceMetrics(mwrs []metricWithResource) pmetric.Metrics { } func BenchmarkStrictFilter(b *testing.B) { - mp := &filtermetric.MatchProperties{ + mp := &filterconfig.MetricMatchProperties{ MatchType: "strict", MetricNames: []string{"p10_metric_0"}, } @@ -393,7 +392,7 @@ func BenchmarkStrictFilter(b *testing.B) { } func BenchmarkRegexpFilter(b *testing.B) { - mp := &filtermetric.MatchProperties{ + mp := &filterconfig.MetricMatchProperties{ MatchType: "regexp", MetricNames: []string{"p10_metric_0"}, } @@ -401,14 +400,14 @@ func BenchmarkRegexpFilter(b *testing.B) { } func BenchmarkExprFilter(b *testing.B) { - mp := &filtermetric.MatchProperties{ + mp := &filterconfig.MetricMatchProperties{ MatchType: "expr", Expressions: []string{`MetricName == "p10_metric_0"`}, } benchmarkFilter(b, mp) } -func benchmarkFilter(b *testing.B, mp *filtermetric.MatchProperties) { +func benchmarkFilter(b *testing.B, mp *filterconfig.MetricMatchProperties) { factory := NewFactory() cfg := factory.CreateDefaultConfig() pcfg := cfg.(*Config) @@ -488,7 +487,7 @@ func requireNotPanics(t *testing.T, metrics pmetric.Metrics) { cfg := factory.CreateDefaultConfig() pcfg := cfg.(*Config) pcfg.Metrics = MetricFilters{ - Exclude: &filtermetric.MatchProperties{ + Exclude: &filterconfig.MetricMatchProperties{ MatchType: "strict", MetricNames: []string{"foo"}, },