Skip to content

Structured metadata not stored correctly when using JSON encoding #13918

Description

@hvenev

Describe the bug
When a log message is submitted to the /loki/api/v1/push endpoint, and is encoded as JSON, its structured metadata is not recorded correctly.

To Reproduce
Steps to reproduce the behavior:

  1. Started Loki (SHA or version): v3.1.1
  2. Sent JSON record to `/loki/api/v1/push``:
{
  "streams": [
    {
      "stream": {"service_name":"test"},
      "values": [["1723985681658755744", "{}", {"message": "a\nb\nc"}]]
    }
  ]
}

Command:

curl -H 'Content-Type: application/json' -d '{"streams": [{"stream": {"service_name":"test"},"values":[["1723986725000000000", "{}", {"message": "a\nb\nc"}]]}]}' -v 'http://127.0.0.1:3100/loki/api/v1/push'
  1. Sent query: {"service_name":"test"}

Command:

curl -v 'http://127.0.0.1:3100/loki/api/v1/query_range?query=%7Bservice_name%3D%22test%22%7D&start=1723986725000000000' | jq .data.result
  1. Observe the resulting labels: {"service_name": "test", "message": "a\\nb\\nc"}. Note that the message is different from the one submitted.

Expected behavior
The result should have the labels {"service_name": "test", "message": "a\nb\nc"}

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":[["1723986725000000000", "{}", {"message": "a\nb\nc"}]]}]}' 'http://127.0.0.1:3100/loki/api/v1/push'
localhost ~ # curl -s 'http://127.0.0.1:3100/loki/api/v1/query_range?query=%7Bservice_name%3D%22test%22%7D&start=1723986725000000000' | jq -c .data.result
[{"stream":{"message":"a\\nb\\nc","service_name":"test"},"values":[["1723986725000000000","{}"]]}]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions