fix(metricpass): Remove python logic compatibility (#13791)
This commit is contained in:
parent
ca2295e1a4
commit
8dbc177d3f
|
|
@ -1,6 +1,15 @@
|
||||||
<!-- markdownlint-disable MD024 -->
|
<!-- markdownlint-disable MD024 -->
|
||||||
# Changelog
|
# 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]
|
## v1.27.4 [2023-08-21]
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
[[processors.processor]]
|
[[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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/cel-go/cel"
|
"github.com/google/cel-go/cel"
|
||||||
|
|
@ -257,11 +256,6 @@ func (f *Filter) compileMetricFilter() error {
|
||||||
// Initialize the expression
|
// Initialize the expression
|
||||||
expression := f.MetricPass
|
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
|
// Check if we need to call into CEL at all and quit early
|
||||||
if expression == "" {
|
if expression == "" {
|
||||||
return nil
|
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")`,
|
expression: `(name.startsWith("t") || fields.on) && "id" in fields && fields.id.contains("nwr")`,
|
||||||
expected: true,
|
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",
|
name: "time arithmetics",
|
||||||
expression: `time >= timestamp("2023-04-25T00:00:00Z") - duration("24h")`,
|
expression: `time >= timestamp("2023-04-25T00:00:00Z") - duration("24h")`,
|
||||||
|
|
@ -569,12 +564,12 @@ func TestFilter_MetricPass(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "complex field filtering",
|
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,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "complex field filtering (exactly one)",
|
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,
|
expected: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue