Skip to content

Commit

Permalink
[pkg/ottl] Move types to config.go (#29596)
Browse files Browse the repository at this point in the history
Followup to
#29339 (comment)
  • Loading branch information
TylerHelmuth authored Dec 1, 2023
1 parent 03ad502 commit d7b940b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 38 deletions.
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

0 comments on commit d7b940b

Please sign in to comment.