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 Mar 11, 2024
1 parent 3838b51 commit a623350
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Main (unreleased)

- Fix an issue where JSON string array elements were not parsed correctly in `loki.source.cloudflare`. (@thampiotr)

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

### Other changes

- Clustering for Grafana Agent in Flow mode has graduated from beta to stable.
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/internal/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 a623350

Please sign in to comment.