@@ -90,17 +90,17 @@ func Test_parseKubernetesLog(t *testing.T) {
9090 }
9191}
9292
93- func Test_processLogStream_duplicateTimestamps (t * testing.T ) {
93+ func Test_processLogStream (t * testing.T ) {
9494 baseTime := time .Date (2023 , time .January , 23 , 17 , 0 , 10 , 0 , time .UTC )
9595
9696 tt := []struct {
97- name string
98- logLines []string
99- lastReadTime time.Time
100- expectLines []string
97+ name string
98+ preserveMetaLabels bool
99+ logLines []string
100+ lastReadTime time.Time
101+ expectLines []string
101102 }{
102- {
103- name : "duplicate timestamps are not discarded" ,
103+ {name : "duplicate timestamps are not discarded" ,
104104 logLines : []string {
105105 "2023-01-23T17:00:10Z line1\n " ,
106106 "2023-01-23T17:00:10Z line2\n " ,
@@ -150,22 +150,27 @@ func Test_processLogStream_duplicateTimestamps(t *testing.T) {
150150 "2023-01-23T17:00:10Z line3\n " ,
151151 "2023-01-23T17:00:10Z line4\n " ,
152152 },
153- lastReadTime : baseTime ,
154- expectLines : []string {"line1\n " , "line2\n " , "line3\n " , "line4\n " },
153+ lastReadTime : baseTime ,
154+ expectLines : []string {"line1\n " , "line2\n " , "line3\n " , "line4\n " },
155+ preserveMetaLabels : true ,
155156 },
156157 }
157158
158159 for _ , tc := range tt {
159160 t .Run (tc .name , func (t * testing.T ) {
160161 // Create a mock tailer with minimal setup
161162 lset := labels .FromStrings (
162- LabelPodNamespace , "default " ,
163- LabelPodName , "test-pod " ,
164- LabelPodContainerName , "test-container" ,
165- LabelPodUID , "test-uid-123" ,
163+ kubePodName , "test-pod " ,
164+ kubePodNamespace , "default " ,
165+ kubePodContainerName , "test-container" ,
166+ kubePodUID , "test-uid-123" ,
166167 "test" , "value" ,
167168 )
168- target := NewTarget (lset , lset )
169+
170+ lset , err := PrepareLabelsWithMetaPreservation (lset , "test" , tc .preserveMetaLabels )
171+ require .NoError (t , err )
172+
173+ target := NewTarget (lset , lset , tc .preserveMetaLabels )
169174 opts := & Options {
170175 Positions : & mockPositions {},
171176 }
@@ -215,6 +220,22 @@ func Test_processLogStream_duplicateTimestamps(t *testing.T) {
215220 }
216221
217222 require .Equal (t , tc .expectLines , receivedLines , "received lines should match expected lines" )
223+
224+ if tc .preserveMetaLabels {
225+ lbls := target .Labels ()
226+ require .Equal (t , "test" , lbls .Get ("job" ))
227+ require .Equal (t , "value" , lbls .Get ("test" ))
228+ require .Equal (t , "default/test-pod:test-container" , lbls .Get ("instance" ))
229+ require .Equal (t , "test-pod" , lbls .Get (kubePodName ))
230+ require .Equal (t , "default" , lbls .Get (kubePodNamespace ))
231+ require .Equal (t , "test-container" , lbls .Get (kubePodContainerName ))
232+ require .Equal (t , "test-uid-123" , lbls .Get (kubePodUID ))
233+ } else {
234+ lbls := target .Labels ()
235+ require .Equal (t , "test" , lbls .Get ("job" ))
236+ require .Equal (t , "value" , lbls .Get ("test" ))
237+ require .Equal (t , "default/test-pod:test-container" , lbls .Get ("instance" ))
238+ }
218239 })
219240 }
220241}
0 commit comments