Skip to content

Commit

Permalink
[processor/filter] prevent the matcher from panicking (#14147)
Browse files Browse the repository at this point in the history
* [processor/filter] prevent the matcher from panicking

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

* [processor/filter] add changelog

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
  • Loading branch information
frzifus authored Oct 10, 2022
1 parent bb9960d commit 956b162
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/coreinternal/processor/filterexpr/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package filterexpr // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterexpr"

import (
"fmt"

"github.com/antonmedv/expr"
"github.com/antonmedv/expr/vm"
"go.opentelemetry.io/collector/pdata/pcommon"
Expand Down Expand Up @@ -151,5 +153,12 @@ func (m *Matcher) match(env env) (bool, error) {
if err != nil {
return false, err
}
return result.(bool), nil

v, ok := result.(bool)
if !ok {
return false, fmt.Errorf("filter returned non-boolean value type=%T result=%v metric=%s, attributes=%v",
result, result, env.MetricName, env.attributes.AsRaw())
}

return v, nil
}
11 changes: 11 additions & 0 deletions unreleased/processor-filter_prevent_panic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: filterexpr

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: prevent the matcher from panicking

# One or more tracking issues related to the change
issues: [13573]

0 comments on commit 956b162

Please sign in to comment.