Skip to content

Commit

Permalink
loki.source.api: fix a bug where structured metadata is not passed do…
Browse files Browse the repository at this point in the history
…wnstream (#6508)
  • Loading branch information
marchellodev authored and thampiotr committed Mar 14, 2024
1 parent 26e9071 commit a3062e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ This document contains a historical list of changes between releases. Only
changes that impact end-user behavior are listed; changes to documentation or
internal API changes are not present.

v0.40.3 (2024-03-14)
--------------------

### Bugfixes

- Fix a bug where structured metadata and parsed field are not passed further in `loki.source.api` (@marchellodev)

v0.40.2 (2024-03-05)
--------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ func (s *PushAPIServer) handleLoki(w http.ResponseWriter, r *http.Request) {
e := loki.Entry{
Labels: filtered.Clone(),
Entry: logproto.Entry{
Line: entry.Line,
Line: entry.Line,
StructuredMetadata: entry.StructuredMetadata,
Parsed: entry.Parsed,
},
}
if keepTimestamp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
frelabel "github.com/grafana/agent/component/common/relabel"
"github.com/grafana/dskit/flagext"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/push"
"github.com/grafana/river"
"github.com/phayes/freeport"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -79,6 +80,10 @@ regex = "dropme"
Entry: logproto.Entry{
Timestamp: time.Unix(int64(i), 0),
Line: "line" + strconv.Itoa(i),
StructuredMetadata: push.LabelsAdapter{
{Name: "i", Value: strconv.Itoa(i)},
{Name: "anotherMetaData", Value: "val"},
},
},
}
}
Expand All @@ -98,9 +103,18 @@ regex = "dropme"
"pushserver": "pushserver1",
"stream": "stream1",
}

expectedStructuredMetadata := push.LabelsAdapter{
{Name: "i", Value: strconv.Itoa(0)},
{Name: "anotherMetaData", Value: "val"},
}

// Spot check the first value in the result to make sure relabel rules were applied properly
require.Equal(t, expectedLabels, eh.Received()[0].Labels)

// Spot check the first value in the result to make sure structured metadata was received properly
require.Equal(t, expectedStructuredMetadata, eh.Received()[0].StructuredMetadata)

// With keep timestamp enabled, verify timestamp
require.Equal(t, time.Unix(99, 0).Unix(), eh.Received()[99].Timestamp.Unix())

Expand Down

0 comments on commit a3062e1

Please sign in to comment.