diff --git a/pkg/ottl/config.go b/pkg/ottl/config.go new file mode 100644 index 000000000000..eed0724b9909 --- /dev/null +++ b/pkg/ottl/config.go @@ -0,0 +1,45 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package ottl // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" + +import ( + "fmt" + "strings" +) + +type ErrorMode string + +const ( + IgnoreError ErrorMode = "ignore" + PropagateError ErrorMode = "propagate" +) + +func (e *ErrorMode) UnmarshalText(text []byte) error { + str := ErrorMode(strings.ToLower(string(text))) + switch str { + case IgnoreError, PropagateError: + *e = str + return nil + default: + return fmt.Errorf("unknown error mode %v", str) + } +} + +type LogicOperation string + +const ( + And LogicOperation = "and" + Or LogicOperation = "or" +) + +func (l *LogicOperation) UnmarshalText(text []byte) error { + str := LogicOperation(strings.ToLower(string(text))) + switch str { + case And, Or: + *l = str + return nil + default: + return fmt.Errorf("unknown LogicOperation %v", str) + } +} diff --git a/pkg/ottl/parser.go b/pkg/ottl/parser.go index e2b239e0c87e..222b3bbfa5e3 100644 --- a/pkg/ottl/parser.go +++ b/pkg/ottl/parser.go @@ -7,50 +7,12 @@ import ( "context" "errors" "fmt" - "strings" "github.com/alecthomas/participle/v2" "go.opentelemetry.io/collector/component" "go.uber.org/zap" ) -type ErrorMode string - -const ( - IgnoreError ErrorMode = "ignore" - PropagateError ErrorMode = "propagate" -) - -func (e *ErrorMode) UnmarshalText(text []byte) error { - str := ErrorMode(strings.ToLower(string(text))) - switch str { - case IgnoreError, PropagateError: - *e = str - return nil - default: - return fmt.Errorf("unknown error mode %v", str) - } -} - -// TODO: move this and ErrorMode to a config.go file -type LogicOperation string - -const ( - And LogicOperation = "and" - Or LogicOperation = "or" -) - -func (l *LogicOperation) UnmarshalText(text []byte) error { - str := LogicOperation(strings.ToLower(string(text))) - switch str { - case And, Or: - *l = str - return nil - default: - return fmt.Errorf("unknown LogicOperation %v", str) - } -} - // Statement holds a top level Statement for processing telemetry data. A Statement is a combination of a function // invocation and the boolean expression to match telemetry for invoking the function. type Statement[K any] struct {