Skip to content

Commit

Permalink
[internal/filter] Add bridge from filterlog to filterottl (open-telem…
Browse files Browse the repository at this point in the history
…etry#22789)

This PR adds a bridge between `filterlog.NewSkipExpr` and
`filterottl.NewBoolExprForLog` behind a feature gate. With the feature
gate enabled, any component using `filterlog.NewSkipExpr` will start
using OTTL behind the scenes.

Related to
open-telemetry#18643
Related to
open-telemetry#18642

Added tests comparing the output of the existing config and the bridge.
  • Loading branch information
TylerHelmuth authored and Caleb-Hurshman committed Jul 6, 2023
1 parent f4810c4 commit c76a9bb
Show file tree
Hide file tree
Showing 4 changed files with 1,345 additions and 39 deletions.
14 changes: 14 additions & 0 deletions internal/filter/filterlog/filterlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@ import (
"context"
"fmt"

"go.opentelemetry.io/collector/featuregate"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/expr"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filtermatcher"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterottl"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog"
)

var useOTTLBridge = featuregate.GlobalRegistry().MustRegister(
"filter.filterlog.useOTTLBridge",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("When enabled, filterlog will convert filterlog configuration to OTTL and use filterottl evaluation"),
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/18642"),
)

// NewSkipExpr creates a BoolExpr that on evaluation returns true if a log should NOT be processed or kept.
// The logic determining if a log should be processed is based on include and exclude settings.
// Include properties are checked before exclude settings are checked.
func NewSkipExpr(mp *filterconfig.MatchConfig) (expr.BoolExpr[ottllog.TransformContext], error) {

if useOTTLBridge.IsEnabled() {
return filterottl.NewLogSkipExprBridge(mp)
}
var matchers []expr.BoolExpr[ottllog.TransformContext]
inclExpr, err := newExpr(mp.Include)
if err != nil {
Expand Down
Loading

0 comments on commit c76a9bb

Please sign in to comment.