@@ -71,6 +71,26 @@ stage.labels {
71
71
}
72
72
`
73
73
74
+ var pipelineStagesStructuredMetadataFromStaticLabels = `
75
+ stage.static_labels {
76
+ values = {"component" = "querier", "pod" = "loki-querier-664f97db8d-qhnwg"}
77
+ }
78
+
79
+ stage.structured_metadata {
80
+ values = {"pod" = ""}
81
+ }
82
+ `
83
+
84
+ var pipelineStagesStructuredMetadataFromStaticLabelsDifferentKey = `
85
+ stage.static_labels {
86
+ values = {"component" = "querier", "pod" = "loki-querier-664f97db8d-qhnwg"}
87
+ }
88
+
89
+ stage.structured_metadata {
90
+ values = {"pod_name" = "pod"}
91
+ }
92
+ `
93
+
74
94
func Test_StructuredMetadataStage (t * testing.T ) {
75
95
tests := map [string ]struct {
76
96
pipelineStagesYaml string
@@ -104,6 +124,18 @@ func Test_StructuredMetadataStage(t *testing.T) {
104
124
expectedStructuredMetadata : push.LabelsAdapter {push.LabelAdapter {Name : "app" , Value : "loki" }},
105
125
expectedLabels : model.LabelSet {model .LabelName ("component" ): model .LabelValue ("ingester" )},
106
126
},
127
+ "expected structured metadata and regular labels to be extracted with static labels stage and to be added to entry" : {
128
+ pipelineStagesYaml : pipelineStagesStructuredMetadataFromStaticLabels ,
129
+ logLine : `sample log line` ,
130
+ expectedStructuredMetadata : push.LabelsAdapter {push.LabelAdapter {Name : "pod" , Value : "loki-querier-664f97db8d-qhnwg" }},
131
+ expectedLabels : model.LabelSet {model .LabelName ("component" ): model .LabelValue ("querier" )},
132
+ },
133
+ "expected structured metadata and regular labels to be extracted with static labels stage using different structured key" : {
134
+ pipelineStagesYaml : pipelineStagesStructuredMetadataFromStaticLabelsDifferentKey ,
135
+ logLine : `sample log line` ,
136
+ expectedStructuredMetadata : push.LabelsAdapter {push.LabelAdapter {Name : "pod_name" , Value : "loki-querier-664f97db8d-qhnwg" }},
137
+ expectedLabels : model.LabelSet {model .LabelName ("component" ): model .LabelValue ("querier" )},
138
+ },
107
139
}
108
140
for name , test := range tests {
109
141
t .Run (name , func (t * testing.T ) {
0 commit comments