-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processor/attributes] support Profile signal type
Signed-off-by: odubajDT <[email protected]>
- Loading branch information
Showing
13 changed files
with
2,198 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package filterprofile // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterprofile" | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"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/filterset" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlprofile" | ||
) | ||
|
||
// 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[ottlprofile.TransformContext], error) { | ||
|
||
var matchers []expr.BoolExpr[ottlprofile.TransformContext] | ||
inclExpr, err := newExpr(mp.Include) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if inclExpr != nil { | ||
matchers = append(matchers, expr.Not(inclExpr)) | ||
} | ||
exclExpr, err := newExpr(mp.Exclude) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if exclExpr != nil { | ||
matchers = append(matchers, exclExpr) | ||
} | ||
return expr.Or(matchers...), nil | ||
} | ||
|
||
// propertiesMatcher allows matching a log record against various log record properties. | ||
type propertiesMatcher struct { | ||
filtermatcher.PropertiesMatcher | ||
|
||
// log bodies to compare to. | ||
bodyFilters filterset.FilterSet | ||
|
||
// log severity texts to compare to | ||
severityTextFilters filterset.FilterSet | ||
|
||
// matcher for severity number | ||
severityNumberMatcher *severityNumberMatcher | ||
} | ||
|
||
// NewMatcher creates a LogRecord Matcher that matches based on the given MatchProperties. | ||
func newExpr(mp *filterconfig.MatchProperties) (expr.BoolExpr[ottlprofile.TransformContext], error) { | ||
if mp == nil { | ||
return nil, nil | ||
} | ||
|
||
if err := mp.ValidateForLogs(); err != nil { | ||
return nil, err | ||
} | ||
|
||
rm, err := filtermatcher.NewMatcher(mp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var bodyFS filterset.FilterSet | ||
if len(mp.LogBodies) > 0 { | ||
bodyFS, err = filterset.CreateFilterSet(mp.LogBodies, &mp.Config) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating log record body filters: %w", err) | ||
} | ||
} | ||
var severitytextFS filterset.FilterSet | ||
if len(mp.LogSeverityTexts) > 0 { | ||
severitytextFS, err = filterset.CreateFilterSet(mp.LogSeverityTexts, &mp.Config) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating log record severity text filters: %w", err) | ||
} | ||
} | ||
|
||
pm := &propertiesMatcher{ | ||
PropertiesMatcher: rm, | ||
bodyFilters: bodyFS, | ||
severityTextFilters: severitytextFS, | ||
} | ||
|
||
return pm, nil | ||
} | ||
|
||
// Eval matches a log record to a set of properties. | ||
// There are 3 sets of properties to match against. | ||
// The log record names are matched, if specified. | ||
// The log record bodies are matched, if specified. | ||
// The attributes are then checked, if specified. | ||
// At least one of log record names or attributes must be specified. It is | ||
// supported to have more than one of these specified, and all specified must | ||
// evaluate to true for a match to occur. | ||
func (mp *propertiesMatcher) Eval(_ context.Context, tCtx ottlprofile.TransformContext) (bool, error) { | ||
lr := tCtx.GetLogRecord() | ||
if mp.bodyFilters != nil && !mp.bodyFilters.Matches(lr.Body().AsString()) { | ||
return false, nil | ||
} | ||
if mp.severityTextFilters != nil && !mp.severityTextFilters.Matches(lr.SeverityText()) { | ||
return false, nil | ||
} | ||
if mp.severityNumberMatcher != nil && !mp.severityNumberMatcher.match(lr) { | ||
return false, nil | ||
} | ||
|
||
return mp.PropertiesMatcher.Match(lr.Attributes(), tCtx.GetResource(), tCtx.GetInstrumentationScope()), nil | ||
} |
Oops, something went wrong.