Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[internal/filter] Add filterottl functions with additional options #37271

Merged
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
49 changes: 42 additions & 7 deletions internal/filter/filterottl/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import (
// The passed in functions should use the ottlspan.TransformContext.
// If a function named `match` is not present in the function map it will be added automatically so that parsing works as expected
func NewBoolExprForSpan(conditions []string, functions map[string]ottl.Factory[ottlspan.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings) (*ottl.ConditionSequence[ottlspan.TransformContext], error) {
parser, err := ottlspan.NewParser(functions, set)
return NewBoolExprForSpanWithOptions(conditions, functions, errorMode, set, nil)
}

// NewBoolExprForSpanWithOptions is like NewBoolExprForSpan, but with additional options.
func NewBoolExprForSpanWithOptions(conditions []string, functions map[string]ottl.Factory[ottlspan.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings, parserOptions []ottlspan.Option) (*ottl.ConditionSequence[ottlspan.TransformContext], error) {
parser, err := ottlspan.NewParser(functions, set, parserOptions...)
if err != nil {
return nil, err
}
Expand All @@ -36,7 +41,12 @@ func NewBoolExprForSpan(conditions []string, functions map[string]ottl.Factory[o
// The passed in functions should use the ottlspanevent.TransformContext.
// If a function named `match` is not present in the function map it will be added automatically so that parsing works as expected
func NewBoolExprForSpanEvent(conditions []string, functions map[string]ottl.Factory[ottlspanevent.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings) (*ottl.ConditionSequence[ottlspanevent.TransformContext], error) {
parser, err := ottlspanevent.NewParser(functions, set)
return NewBoolExprForSpanEventWithOptions(conditions, functions, errorMode, set, nil)
}

// NewBoolExprForSpanEventWithOptions is like NewBoolExprForSpanEvent, but with additional options.
func NewBoolExprForSpanEventWithOptions(conditions []string, functions map[string]ottl.Factory[ottlspanevent.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings, parserOptions []ottlspanevent.Option) (*ottl.ConditionSequence[ottlspanevent.TransformContext], error) {
parser, err := ottlspanevent.NewParser(functions, set, parserOptions...)
if err != nil {
return nil, err
}
Expand All @@ -52,7 +62,12 @@ func NewBoolExprForSpanEvent(conditions []string, functions map[string]ottl.Fact
// The passed in functions should use the ottlmetric.TransformContext.
// If a function named `match` is not present in the function map it will be added automatically so that parsing works as expected
func NewBoolExprForMetric(conditions []string, functions map[string]ottl.Factory[ottlmetric.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings) (*ottl.ConditionSequence[ottlmetric.TransformContext], error) {
parser, err := ottlmetric.NewParser(functions, set)
return NewBoolExprForMetricWithOptions(conditions, functions, errorMode, set, nil)
}

// NewBoolExprForMetricWithOptions is like NewBoolExprForMetric, but with additional options.
func NewBoolExprForMetricWithOptions(conditions []string, functions map[string]ottl.Factory[ottlmetric.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings, parserOptions []ottlmetric.Option) (*ottl.ConditionSequence[ottlmetric.TransformContext], error) {
parser, err := ottlmetric.NewParser(functions, set, parserOptions...)
if err != nil {
return nil, err
}
Expand All @@ -68,7 +83,12 @@ func NewBoolExprForMetric(conditions []string, functions map[string]ottl.Factory
// The passed in functions should use the ottldatapoint.TransformContext.
// If a function named `match` is not present in the function map it will be added automatically so that parsing works as expected
func NewBoolExprForDataPoint(conditions []string, functions map[string]ottl.Factory[ottldatapoint.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings) (*ottl.ConditionSequence[ottldatapoint.TransformContext], error) {
parser, err := ottldatapoint.NewParser(functions, set)
return NewBoolExprForDataPointWithOptions(conditions, functions, errorMode, set, nil)
}

// NewBoolExprForDataPointWithOptions is like NewBoolExprForDataPoint, but with additional options.
func NewBoolExprForDataPointWithOptions(conditions []string, functions map[string]ottl.Factory[ottldatapoint.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings, parserOptions []ottldatapoint.Option) (*ottl.ConditionSequence[ottldatapoint.TransformContext], error) {
parser, err := ottldatapoint.NewParser(functions, set, parserOptions...)
if err != nil {
return nil, err
}
Expand All @@ -84,7 +104,12 @@ func NewBoolExprForDataPoint(conditions []string, functions map[string]ottl.Fact
// The passed in functions should use the ottllog.TransformContext.
// If a function named `match` is not present in the function map it will be added automatically so that parsing works as expected
func NewBoolExprForLog(conditions []string, functions map[string]ottl.Factory[ottllog.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings) (*ottl.ConditionSequence[ottllog.TransformContext], error) {
parser, err := ottllog.NewParser(functions, set)
return NewBoolExprForLogWithOptions(conditions, functions, errorMode, set, nil)
}

// NewBoolExprForLogWithOptions is like NewBoolExprForLog, but with additional options.
func NewBoolExprForLogWithOptions(conditions []string, functions map[string]ottl.Factory[ottllog.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings, parserOptions []ottllog.Option) (*ottl.ConditionSequence[ottllog.TransformContext], error) {
parser, err := ottllog.NewParser(functions, set, parserOptions...)
if err != nil {
return nil, err
}
Expand All @@ -100,7 +125,12 @@ func NewBoolExprForLog(conditions []string, functions map[string]ottl.Factory[ot
// The passed in functions should use the ottlresource.TransformContext.
// If a function named `match` is not present in the function map it will be added automatically so that parsing works as expected
func NewBoolExprForResource(conditions []string, functions map[string]ottl.Factory[ottlresource.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings) (*ottl.ConditionSequence[ottlresource.TransformContext], error) {
parser, err := ottlresource.NewParser(functions, set)
return NewBoolExprForResourceWithOptions(conditions, functions, errorMode, set, nil)
}

// NewBoolExprForResourceWithOptions is like NewBoolExprForResource, but with additional options.
func NewBoolExprForResourceWithOptions(conditions []string, functions map[string]ottl.Factory[ottlresource.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings, parserOptions []ottlresource.Option) (*ottl.ConditionSequence[ottlresource.TransformContext], error) {
parser, err := ottlresource.NewParser(functions, set, parserOptions...)
if err != nil {
return nil, err
}
Expand All @@ -116,7 +146,12 @@ func NewBoolExprForResource(conditions []string, functions map[string]ottl.Facto
// The passed in functions should use the ottlresource.TransformContext.
// If a function named `match` is not present in the function map it will be added automatically so that parsing works as expected
func NewBoolExprForScope(conditions []string, functions map[string]ottl.Factory[ottlscope.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings) (*ottl.ConditionSequence[ottlscope.TransformContext], error) {
parser, err := ottlscope.NewParser(functions, set)
return NewBoolExprForScopeWithOptions(conditions, functions, errorMode, set, nil)
}

// NewBoolExprForScopeWithOptions is like NewBoolExprForScope, but with additional options.
func NewBoolExprForScopeWithOptions(conditions []string, functions map[string]ottl.Factory[ottlscope.TransformContext], errorMode ottl.ErrorMode, set component.TelemetrySettings, parserOptions []ottlscope.Option) (*ottl.ConditionSequence[ottlscope.TransformContext], error) {
parser, err := ottlscope.NewParser(functions, set, parserOptions...)
if err != nil {
return nil, err
}
Expand Down
77 changes: 77 additions & 0 deletions internal/filter/filterottl/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ func Test_NewBoolExprForSpan(t *testing.T) {
}
}

func Test_NewBoolExprForSpanWithOptions(t *testing.T) {
_, err := NewBoolExprForSpanWithOptions(
[]string{`span.name == "foo"`},
StandardSpanFuncs(),
ottl.PropagateError,
componenttest.NewNopTelemetrySettings(),
[]ottlspan.Option{ottlspan.EnablePathContextNames()},
)
assert.NoError(t, err)
}

func Test_NewBoolExprForSpanEvent(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -104,6 +115,17 @@ func Test_NewBoolExprForSpanEvent(t *testing.T) {
}
}

func Test_NewBoolExprForSpanEventWithOptions(t *testing.T) {
_, err := NewBoolExprForSpanEventWithOptions(
[]string{`spanevent.name == "foo"`},
StandardSpanEventFuncs(),
ottl.PropagateError,
componenttest.NewNopTelemetrySettings(),
[]ottlspanevent.Option{ottlspanevent.EnablePathContextNames()},
)
assert.NoError(t, err)
}

func Test_NewBoolExprForMetric(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -146,6 +168,17 @@ func Test_NewBoolExprForMetric(t *testing.T) {
}
}

func Test_NewBoolExprForMetricWithOptions(t *testing.T) {
_, err := NewBoolExprForMetricWithOptions(
[]string{`metric.name == "foo"`},
StandardMetricFuncs(),
ottl.PropagateError,
componenttest.NewNopTelemetrySettings(),
[]ottlmetric.Option{ottlmetric.EnablePathContextNames()},
)
assert.NoError(t, err)
}

func Test_NewBoolExprForDataPoint(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -188,6 +221,17 @@ func Test_NewBoolExprForDataPoint(t *testing.T) {
}
}

func Test_NewBoolExprForDataPointWithOptions(t *testing.T) {
_, err := NewBoolExprForDataPointWithOptions(
[]string{"datapoint.count > 0"},
StandardDataPointFuncs(),
ottl.PropagateError,
componenttest.NewNopTelemetrySettings(),
[]ottldatapoint.Option{ottldatapoint.EnablePathContextNames()},
)
assert.NoError(t, err)
}

func Test_NewBoolExprForLog(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -230,6 +274,17 @@ func Test_NewBoolExprForLog(t *testing.T) {
}
}

func Test_NewBoolExprForLogWithOptions(t *testing.T) {
_, err := NewBoolExprForLogWithOptions(
[]string{`log.body != ""`},
StandardLogFuncs(),
ottl.PropagateError,
componenttest.NewNopTelemetrySettings(),
[]ottllog.Option{ottllog.EnablePathContextNames()},
)
assert.NoError(t, err)
}

func Test_NewBoolExprForResource(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -272,6 +327,17 @@ func Test_NewBoolExprForResource(t *testing.T) {
}
}

func Test_NewBoolExprForResourceWithOptions(t *testing.T) {
_, err := NewBoolExprForResourceWithOptions(
[]string{`resource.dropped_attributes_count == 0`},
StandardResourceFuncs(),
ottl.PropagateError,
componenttest.NewNopTelemetrySettings(),
[]ottlresource.Option{ottlresource.EnablePathContextNames()},
)
assert.NoError(t, err)
}

func Test_NewBoolExprForScope(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -321,3 +387,14 @@ func Test_NewBoolExprForScope(t *testing.T) {
})
}
}

func Test_NewBoolExprForScopeWithOptions(t *testing.T) {
_, err := NewBoolExprForScopeWithOptions(
[]string{`scope.name != ""`},
StandardScopeFuncs(),
ottl.PropagateError,
componenttest.NewNopTelemetrySettings(),
[]ottlscope.Option{ottlscope.EnablePathContextNames()},
)
assert.NoError(t, err)
}
Loading