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](d10549e3ec)
- [ ] 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](0d4416a4b0)
pull/11458/head^2
Karsten Jeschkies 2 years ago committed by GitHub
parent 797720d3b2
commit d048e93f1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      pkg/logql/syntax/serialize.go
  2. 3
      pkg/logql/syntax/serialize_test.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)

@ -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 {

Loading…
Cancel
Save