diff --git a/clients/pkg/promtail/targets/lokipush/pushtarget.go b/clients/pkg/promtail/targets/lokipush/pushtarget.go index 63630c6e5ac2..1ec021c0b28a 100644 --- a/clients/pkg/promtail/targets/lokipush/pushtarget.go +++ b/clients/pkg/promtail/targets/lokipush/pushtarget.go @@ -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 { diff --git a/clients/pkg/promtail/targets/lokipush/pushtarget_test.go b/clients/pkg/promtail/targets/lokipush/pushtarget_test.go index 3fe48b599a5e..d94a34eca397 100644 --- a/clients/pkg/promtail/targets/lokipush/pushtarget_test.go +++ b/clients/pkg/promtail/targets/lokipush/pushtarget_test.go @@ -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" @@ -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"}, + }, }, } } @@ -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())