From d048e93f1af1bb7cc53835d2be6be3fe3e5b6dc6 Mon Sep 17 00:00:00 2001 From: Karsten Jeschkies Date: Fri, 15 Dec 2023 11:08:47 +0100 Subject: [PATCH] Always set matcher in label filter deserialization. (#11497) **What this PR does / why we need it**: Originally we would not set the matcher of a label filter if the name or value was empty. However , `post != ""` is a valid filter expression with an empty value. **Checklist** - [ ] Reviewed the [`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md) guide (**required**) - [ ] Documentation added - [x] Tests updated - [ ] `CHANGELOG.md` updated - [ ] If the change is worth mentioning in the release notes, add `add-to-release-notes` label - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/setup/upgrade/_index.md` - [ ] For Helm chart changes bump the Helm chart version in `production/helm/loki/Chart.yaml` and update `production/helm/loki/CHANGELOG.md` and `production/helm/loki/README.md`. [Example PR](https://github.com/grafana/loki/commit/d10549e3ece02120974929894ee333d07755d213) - [ ] If the change is deprecating or removing a configuration option, update the `deprecated-config.yaml` and `deleted-config.yaml` files respectively in the `tools/deprecated-config-checker` directory. [Example PR](https://github.com/grafana/loki/pull/10840/commits/0d4416a4b03739583349934b96f272fb4f685d15) --- pkg/logql/syntax/serialize.go | 4 +--- pkg/logql/syntax/serialize_test.go | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/logql/syntax/serialize.go b/pkg/logql/syntax/serialize.go index 2d7a1d786f..53c4bef37d 100644 --- a/pkg/logql/syntax/serialize.go +++ b/pkg/logql/syntax/serialize.go @@ -623,9 +623,7 @@ func decodeLabelFilter(iter *jsoniter.Iterator) log.LabelFilterer { } var matcher *labels.Matcher - if name != "" && value != "" { - matcher = labels.MustNewMatcher(t, name, value) - } + matcher = labels.MustNewMatcher(t, name, value) filter = log.NewStringLabelFilter(matcher) diff --git a/pkg/logql/syntax/serialize_test.go b/pkg/logql/syntax/serialize_test.go index 846e3988b8..f4051caaf7 100644 --- a/pkg/logql/syntax/serialize_test.go +++ b/pkg/logql/syntax/serialize_test.go @@ -50,6 +50,9 @@ func TestJSONSerializationRoundTrip(t *testing.T) { "multiple post filters": { query: `rate({app="foo"} | json | unwrap foo | latency >= 250ms or bytes > 42B or ( status_code < 500 and status_code > 200) or source = ip("") and user = "me" [1m])`, }, + "empty label filter string": { + query: `rate({app="foo"} |= "bar" | json | unwrap latency | path!="" [5m])`, + }, } for name, test := range tests {