Skip to content

Commit

Permalink
feat: add structured metadata to the promtail push API (#14153)
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Welch <edward.welch@grafana.com>
(cherry picked from commit 66cffcb)
  • Loading branch information
slim-bean committed Sep 17, 2024
1 parent 6500e54 commit c71da80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clients/pkg/promtail/targets/lokipush/pushtarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ func (t *PushTarget) handleLoki(w http.ResponseWriter, r *http.Request) {
e := api.Entry{
Labels: filtered.Clone(),
Entry: logproto.Entry{
Line: entry.Line,
Line: entry.Line,
StructuredMetadata: entry.StructuredMetadata,
},
}
if t.config.KeepTimestamp {
Expand Down
13 changes: 13 additions & 0 deletions clients/pkg/promtail/targets/lokipush/pushtarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/prometheus/prometheus/model/relabel"
"github.com/stretchr/testify/require"

"github.com/grafana/loki/pkg/push"

"github.com/grafana/loki/v3/clients/pkg/promtail/api"
"github.com/grafana/loki/v3/clients/pkg/promtail/client"
"github.com/grafana/loki/v3/clients/pkg/promtail/client/fake"
Expand Down Expand Up @@ -101,6 +103,10 @@ func TestLokiPushTarget(t *testing.T) {
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 @@ -123,6 +129,13 @@ func TestLokiPushTarget(t *testing.T) {
// Spot check the first value in the result to make sure relabel rules were applied properly
require.Equal(t, expectedLabels, eh.Received()[0].Labels)

expectedStructuredMetadata := push.LabelsAdapter{
{Name: "i", Value: strconv.Itoa(0)},
{Name: "anotherMetaData", Value: "val"},
}
// 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 c71da80

Please sign in to comment.