Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label filters ignore parsed label if it exists in structured metadata #13937

Closed
hvenev opened this issue Aug 20, 2024 · 1 comment · Fixed by #13955
Closed

Label filters ignore parsed label if it exists in structured metadata #13937

hvenev opened this issue Aug 20, 2024 · 1 comment · Fixed by #13955
Labels
type/bug Somehing is not working as expected

Comments

@hvenev
Copy link

hvenev commented Aug 20, 2024

Describe the bug
When a line has a label in structured metadata, and the label is then overwritten by a label format expression, the label filter uses the structured metadata instead of the updated value.

To Reproduce
Steps to reproduce the behavior:

  1. Started Loki (SHA or version): v3.1.1
  2. Sent record to /loki/api/v1/push:
{
  "streams": [
    {
      "stream": {"service_name":"test"},
      "values": [["1724169776000000000", "hello", {"x": "foo"}]]
    }
  ]
}

Command:

curl -H 'Content-Type: application/json' -d '{"streams": [{"stream": {"service_name":"test"},"values":[["1724169776000000000", "hello", {"x": "foo"}]]}]}' -v 'http://127.0.0.1:3100/loki/api/v1/push'
  1. Sent queries:
  • {service_name="test"} | label_format x="bar" | x="foo"
  • {service_name="test"} | label_format x="bar" | x="bar"

Commands:

curl -s -G http://127.0.0.1:3100/loki/api/v1/query_range --data-urlencode start=1724169776000000000 --data-urlencode query='{service_name="test"} | label_format x="bar" | x="foo"' | jq '.data.result[]'
curl -s -G http://127.0.0.1:3100/loki/api/v1/query_range --data-urlencode start=1724169776000000000 --data-urlencode query='{service_name="test"} | label_format x="bar" | x="bar"' | jq '.data.result[]'
  1. Observe that the first query (the one with the x="foo" filter) produces a result with x="bar", and the second query (the one with the x="bar" filter) produces no result.

Expected behavior
Given that label_format is supposed to always set x to "bar", only the second query (... | label_format x="bar" | x="bar") should ever produce a result. The first query (... | label_format x="bar" | x="foo") should never produce anything, as "bar" != "foo".

Environment:

  • Infrastructure: bare-metal
  • Deployment tool: /bin/bash

Screenshots, Promtail config, or terminal output

localhost ~ # curl -H 'Content-Type: application/json' -d '{"streams": [{"stream": {"service_name":"test"},"values":[["1724169776000000000", "hello", {"x": "foo"}]]}]}' 'http://127.0.0.1:3100/loki/api/v1/push'
localhost ~ # curl -s -G http://127.0.0.1:3100/loki/api/v1/query_range --data-urlencode start=1724169776000000000 --data-urlencode query='{service_name="test"} | label_format x="bar" | x="foo"' | jq '.data.result'
[
  {
    "stream": {
      "service_name": "test",
      "x": "bar"
    },
    "values": [
      [
        "1724169776000000000",
        "hello"
      ]
    ]
  }
]
localhost ~ # curl -s -G http://127.0.0.1:3100/loki/api/v1/query_range --data-urlencode start=1724169776000000000 --data-urlencode query='{service_name="test"} | label_format x="bar" | x="bar"' | jq '.data.result'
[]
@chaudum
Copy link
Contributor

chaudum commented Aug 28, 2024

@hvenev Thanks for the bug report its detailed instructions to reproduce the issue!

@chaudum chaudum added the type/bug Somehing is not working as expected label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Somehing is not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants