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

[pkg/ottl] Move types to config.go #29596

Merged
merged 3 commits into from
Dec 1, 2023
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
45 changes: 45 additions & 0 deletions pkg/ottl/config.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
38 changes: 0 additions & 38 deletions pkg/ottl/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down