fix(metricpass): Remove python logic compatibility (#13791)
This commit is contained in:
parent
ca2295e1a4
commit
8dbc177d3f
|
|
@ -1,6 +1,15 @@
|
|||
<!-- markdownlint-disable MD024 -->
|
||||
# Changelog
|
||||
|
||||
## Next
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
- [#13791](https://github.com/influxdata/telegraf/pull/11493) `metricpass`
|
||||
Removed the Python compatibility support for "not", "and", and "or" keywords.
|
||||
This support was incorrectly removing these keywords from actual data. Users
|
||||
should instead use the standard "!", "&&", and "||" operators.
|
||||
|
||||
## v1.27.4 [2023-08-21]
|
||||
|
||||
### Bugfixes
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
[[processors.processor]]
|
||||
metricpass = '("state" in tags and tags.state == "on") or time > timestamp("2023-04-24T00:00:00Z")'
|
||||
metricpass = '("state" in tags && tags.state == "on") || time > timestamp("2023-04-24T00:00:00Z")'
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package models
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/google/cel-go/cel"
|
||||
|
|
@ -257,11 +256,6 @@ func (f *Filter) compileMetricFilter() error {
|
|||
// Initialize the expression
|
||||
expression := f.MetricPass
|
||||
|
||||
// Replace python-like logic-operators
|
||||
expression = regexp.MustCompile(`\bnot\b`).ReplaceAllString(expression, "!")
|
||||
expression = regexp.MustCompile(`\band\b`).ReplaceAllString(expression, "&&")
|
||||
expression = regexp.MustCompile(`\bor\b`).ReplaceAllString(expression, "||")
|
||||
|
||||
// Check if we need to call into CEL at all and quit early
|
||||
if expression == "" {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -557,11 +557,6 @@ func TestFilter_MetricPass(t *testing.T) {
|
|||
expression: `(name.startsWith("t") || fields.on) && "id" in fields && fields.id.contains("nwr")`,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "python-style logical expression",
|
||||
expression: `(name.startsWith("t") or fields.on) and "id" in fields and fields.id.contains("nwr")`,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "time arithmetics",
|
||||
expression: `time >= timestamp("2023-04-25T00:00:00Z") - duration("24h")`,
|
||||
|
|
@ -569,12 +564,12 @@ func TestFilter_MetricPass(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "complex field filtering",
|
||||
expression: `fields.exists(f, type(fields[f]) in [int, uint, double] and fields[f] > 20.0)`,
|
||||
expression: `fields.exists(f, type(fields[f]) in [int, uint, double] && fields[f] > 20.0)`,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "complex field filtering (exactly one)",
|
||||
expression: `fields.exists_one(f, type(fields[f]) in [int, uint, double] and fields[f] > 20.0)`,
|
||||
expression: `fields.exists_one(f, type(fields[f]) in [int, uint, double] && fields[f] > 20.0)`,
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue