From d7b940b7c3feacf7c8d39fb1f7466edc7e25e373 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Fri, 1 Dec 2023 09:08:46 -0700 Subject: [PATCH] [pkg/ottl] Move types to config.go (#29596) Followup to https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/29339#discussion_r1411045519 --- pkg/ottl/config.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ pkg/ottl/parser.go | 38 -------------------------------------- 2 files changed, 45 insertions(+), 38 deletions(-) create mode 100644 pkg/ottl/config.go 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 {