@@ -2,6 +2,7 @@ package gitlabreceiver
2
2
3
3
import (
4
4
"encoding/hex"
5
+ "fmt"
5
6
"io"
6
7
"net/http"
7
8
"strings"
@@ -145,42 +146,92 @@ func PipelineEvent_SetAttributes(t *testing.T) {
145
146
expected map [string ]string
146
147
}{
147
148
{
148
- name : "With parent pipeline" ,
149
+ name : "With parent pipeline and variables " ,
149
150
event : glPipelineEvent {
150
151
Pipeline : Pipeline {
151
- Url : "https://gitlab.com/test-pipeline" ,
152
- Id : 123 ,
153
- Source : "parent_pipeline" ,
154
- Status : "success" ,
152
+ Url : "https://gitlab.com/test-pipeline" ,
153
+ Id : 123 ,
154
+ Source : "parent_pipeline" ,
155
+ Status : "success" ,
156
+ Duration : 3600 ,
157
+ QueuedDuration : 120 ,
158
+ Variables : []Variables {
159
+ {Key : "ENV" , Value : "production" },
160
+ {Key : "DEBUG" , Value : "false" },
161
+ },
155
162
},
156
163
ParentPipeline : ParentPipeline {
157
164
Id : 456 ,
158
165
Project : Project {
159
166
Url : "https://gitlab.com/test-parent-project" ,
160
167
},
161
168
},
169
+ User : User {
170
+ Name : "John Doe" ,
171
+ Username : "johndoe" ,
172
+
173
+ },
174
+ Commit : Commit {
175
+ Message : "Fix pipeline issue" ,
176
+ Title : "Pipeline fix" ,
177
+ Timestamp : "2024-10-19T12:00:00Z" ,
178
+ URL : "https://gitlab.com/commit/789" ,
179
+ Author :
Author {
Email :
"[email protected] " },
180
+ },
162
181
},
163
182
expected : map [string ]string {
164
- conventionsAttributeCiCdPipelineUrl : "https://gitlab.com/test-pipeline" ,
165
- conventionsAttributeCidCPipelineRunId : "123" ,
166
- conventionsAttributeCiCdParentPipelineId : "456" ,
167
- conventionsAttributeCiCdParentPipelineUrl : "https://gitlab.com/test-parent-project/pipelines/456" ,
183
+ conventionsAttributeCiCdPipelineUrl : "https://gitlab.com/test-pipeline" ,
184
+ conventionsAttributeCidCPipelineRunId : "123" ,
185
+ conventionsAttributeCiCdPipelineDuration : "3600" ,
186
+ conventionsAttributeCiCdPipelineQueuedDuration : "120" ,
187
+ conventionsAttributeCiCdPipelineUser : "John Doe" ,
188
+ conventionsAttributeCiCdPipelineUsername : "johndoe" ,
189
+ conventionsAttributeCiCdPipelineUserEmail :
"[email protected] " ,
190
+ conventionsAttributeCiCdPipelineCommitMessage : "Fix pipeline issue" ,
191
+ conventionsAttributeCiCdPipelineCommitTitle : "Pipeline fix" ,
192
+ conventionsAttributeCiCdPipelineCommitTimestamp : "2024-10-19T12:00:00Z" ,
193
+ conventionsAttributeCiCdPipelineCommitUrl : "https://gitlab.com/commit/789" ,
194
+ conventionsAttributeCiCdPipelineCommitAuthorEmail :
"[email protected] " ,
195
+ conventionsAttributeCiCdParentPipelineId : "456" ,
196
+ conventionsAttributeCiCdParentPipelineUrl : "https://gitlab.com/test-parent-project/pipelines/456" ,
197
+
198
+ // Variable assertions
199
+ fmt .Sprintf ("%s.%s" , conventionsAttributeCiCdPipelineVariable , "ENV" ): "production" ,
200
+ fmt .Sprintf ("%s.%s" , conventionsAttributeCiCdPipelineVariable , "DEBUG" ): "false" ,
168
201
},
169
202
},
170
203
{
171
- name : "Without parent pipeline" ,
204
+ name : "Without parent pipeline and commit info " ,
172
205
event : glPipelineEvent {
173
206
Pipeline : Pipeline {
174
- Url : "https://gitlab.com/test-pipeline" ,
175
- Id : 124 ,
176
- Source : "direct" ,
177
- Status : "failed" ,
207
+ Url : "https://gitlab.com/test-pipeline" ,
208
+ Id : 124 ,
209
+ Source : "direct" ,
210
+ Status : "failed" ,
211
+ Duration : 1800 ,
212
+ QueuedDuration : 60 ,
213
+ Variables : []Variables {
214
+ {Key : "ENV" , Value : "staging" },
215
+ },
178
216
},
179
217
ParentPipeline : ParentPipeline {}, // No parent
218
+ User : User {
219
+ Name : "Jane Doe" ,
220
+ Username : "janedoe" ,
221
+
222
+ },
223
+ Commit : Commit {}, // No commit info
180
224
},
181
225
expected : map [string ]string {
182
- conventionsAttributeCiCdPipelineUrl : "https://gitlab.com/test-pipeline" ,
183
- conventionsAttributeCidCPipelineRunId : "124" ,
226
+ conventionsAttributeCiCdPipelineUrl : "https://gitlab.com/test-pipeline" ,
227
+ conventionsAttributeCidCPipelineRunId : "124" ,
228
+ conventionsAttributeCiCdPipelineDuration : "1800" ,
229
+ conventionsAttributeCiCdPipelineQueuedDuration : "60" ,
230
+ conventionsAttributeCiCdPipelineUser : "Jane Doe" ,
231
+ conventionsAttributeCiCdPipelineUsername : "janedoe" ,
232
+ conventionsAttributeCiCdPipelineUserEmail :
"[email protected] " ,
233
+ // Variable assertions
234
+ fmt .Sprintf ("%s.%s" , conventionsAttributeCiCdPipelineVariable , "ENV" ): "staging" ,
184
235
},
185
236
},
186
237
}
@@ -208,71 +259,57 @@ func Job_SetAttributes(t *testing.T) {
208
259
{
209
260
name : "Successful job" ,
210
261
job : Job {
211
- Id : 789 ,
212
- Url : "https://gitlab.com/test-job-success" ,
213
- Stage : "test" ,
214
- Status : "success" ,
215
- },
216
- expected : map [string ]string {
217
- conventionsAttributeCiCdTaskRunId : "789" ,
218
- conventionsAttributeCiCdTaskRunUrl : "https://gitlab.com/test-job-success" ,
219
- conventionsAttributeCiCdPipelineTaskType : "test" ,
220
- },
221
- },
222
- {
223
- name : "Failed job" ,
224
- job : Job {
225
- Id : 790 ,
226
- Url : "https://gitlab.com/test-job-fail" ,
227
- Stage : "deploy" ,
228
- Status : "failed" ,
229
- },
230
- expected : map [string ]string {
231
- conventionsAttributeCiCdTaskRunId : "790" ,
232
- conventionsAttributeCiCdTaskRunUrl : "https://gitlab.com/test-job-fail" ,
233
- conventionsAttributeCiCdPipelineTaskType : "deploy" ,
234
- },
235
- },
236
- {
237
- name : "Job with empty URL" ,
238
- job : Job {
239
- Id : 791 ,
240
- Url : "" ,
241
- Stage : "build" ,
242
- Status : "success" ,
243
- },
244
- expected : map [string ]string {
245
- conventionsAttributeCiCdTaskRunId : "791" ,
246
- conventionsAttributeCiCdTaskRunUrl : "" ,
247
- conventionsAttributeCiCdPipelineTaskType : "build" ,
248
- },
249
- },
250
- {
251
- name : "Job with empty stage" ,
252
- job : Job {
253
- Id : 792 ,
254
- Url : "https://gitlab.com/test-job-empty-stage" ,
255
- Stage : "" ,
256
- Status : "success" ,
262
+ Id : 789 ,
263
+ Url : "https://gitlab.com/test-job-success" ,
264
+ Stage : "test" ,
265
+ Status : "success" ,
266
+ Environment : Environment {Name : "prod" },
267
+ Runner : Runner {
268
+ Id : 101 ,
269
+ Description : "High performance runner" ,
270
+ IsActive : true ,
271
+ IsShared : false ,
272
+ Tags : []string {"docker" , "linux" },
273
+ },
257
274
},
258
275
expected : map [string ]string {
259
- conventionsAttributeCiCdTaskRunId : "792" ,
260
- conventionsAttributeCiCdTaskRunUrl : "https://gitlab.com/test-job-empty-stage" ,
261
- conventionsAttributeCiCdPipelineTaskType : "" ,
276
+ conventionsAttributeCiCdTaskRunId : "789" ,
277
+ conventionsAttributeCiCdTaskRunUrl : "https://gitlab.com/test-job-success" ,
278
+ conventionsAttributeCiCdPipelineTaskType : "test" ,
279
+ conventionsAttributeCiCdJobEnvironment : "prod" ,
280
+ conventionsAttributeCiCdJobRunnerId : "101" ,
281
+ conventionsAttributeCiCdJobRunnerDescription : "High performance runner" ,
282
+ conventionsAttributeCiCdJobRunnerIsActive : "true" ,
283
+ conventionsAttributeCiCdJobRunnerIsShared : "false" ,
284
+ conventionsAttributeCiCdJobRunnerTag : "docker" ,
262
285
},
263
286
},
264
287
{
265
- name : "Job with special characters in URL " ,
288
+ name : "Failed job with runner tags " ,
266
289
job : Job {
267
- Id : 793 ,
268
- Url : "https://gitlab.com/test-job-@#$%&" ,
269
- Stage : "integration" ,
270
- Status : "success" ,
290
+ Id : 790 ,
291
+ Url : "https://gitlab.com/test-job-fail" ,
292
+ Stage : "deploy" ,
293
+ Status : "failed" ,
294
+ Environment : Environment {Name : "staging" },
295
+ Runner : Runner {
296
+ Id : 102 ,
297
+ Description : "Backup runner" ,
298
+ IsActive : false ,
299
+ IsShared : true ,
300
+ Tags : []string {"backup" , "windows" },
301
+ },
271
302
},
272
303
expected : map [string ]string {
273
- conventionsAttributeCiCdTaskRunId : "793" ,
274
- conventionsAttributeCiCdTaskRunUrl : "https://gitlab.com/test-job-@#$%&" ,
275
- conventionsAttributeCiCdPipelineTaskType : "integration" ,
304
+ conventionsAttributeCiCdTaskRunId : "790" ,
305
+ conventionsAttributeCiCdTaskRunUrl : "https://gitlab.com/test-job-fail" ,
306
+ conventionsAttributeCiCdPipelineTaskType : "deploy" ,
307
+ conventionsAttributeCiCdJobEnvironment : "staging" ,
308
+ conventionsAttributeCiCdJobRunnerId : "102" ,
309
+ conventionsAttributeCiCdJobRunnerDescription : "Backup runner" ,
310
+ conventionsAttributeCiCdJobRunnerIsActive : "false" ,
311
+ conventionsAttributeCiCdJobRunnerIsShared : "true" ,
312
+ conventionsAttributeCiCdJobRunnerTag : "backup" ,
276
313
},
277
314
},
278
315
}
@@ -287,6 +324,13 @@ func Job_SetAttributes(t *testing.T) {
287
324
t .Errorf ("expected %s to be %s, got %s" , key , expectedValue , actualValue .Str ())
288
325
}
289
326
}
327
+
328
+ // Special check for runner tags (since there may be multiple)
329
+ for _ , tag := range tt .job .Runner .Tags {
330
+ if actualTagValue , exists := span .Attributes ().Get (conventionsAttributeCiCdJobRunnerTag ); ! exists || actualTagValue .Str () != tag {
331
+ t .Errorf ("expected tag %s, but got %s" , tag , actualTagValue .Str ())
332
+ }
333
+ }
290
334
})
291
335
}
292
336
}
0 commit comments