@@ -14,6 +14,7 @@ import (
14
14
15
15
const (
16
16
CUSTOMPROP_LABEL_FMT = "prop_%s"
17
+ LABEL_VALUE_UNKNOWN = "<unknown>"
17
18
)
18
19
19
20
var (
@@ -78,6 +79,7 @@ func (m *MetricsCollectorGithubWorkflows) Setup(collector *collector.Collector)
78
79
"repo" ,
79
80
"workflowID" ,
80
81
"workflow" ,
82
+ "workflowUrl" ,
81
83
"state" ,
82
84
"path" ,
83
85
},
@@ -98,7 +100,11 @@ func (m *MetricsCollectorGithubWorkflows) Setup(collector *collector.Collector)
98
100
"org" ,
99
101
"repo" ,
100
102
"workflowID" ,
103
+ "workflowRunNumber" ,
101
104
"workflow" ,
105
+ "workflowUrl" ,
106
+ "workflowRun" ,
107
+ "workflowRunRul" ,
102
108
"event" ,
103
109
"branch" ,
104
110
"status" ,
@@ -117,6 +123,7 @@ func (m *MetricsCollectorGithubWorkflows) Setup(collector *collector.Collector)
117
123
"org" ,
118
124
"repo" ,
119
125
"workflowID" ,
126
+ "workflowRunNumber" ,
120
127
},
121
128
)
122
129
m .Collector .RegisterMetricList ("workflowRunRunningStartTime" , m .prometheus .workflowRunRunningStartTime , true )
@@ -133,7 +140,11 @@ func (m *MetricsCollectorGithubWorkflows) Setup(collector *collector.Collector)
133
140
"org" ,
134
141
"repo" ,
135
142
"workflowID" ,
143
+ "workflowRunNumber" ,
136
144
"workflow" ,
145
+ "workflowUrl" ,
146
+ "workflowRun" ,
147
+ "workflowRunRul" ,
137
148
"event" ,
138
149
"branch" ,
139
150
"conclusion" ,
@@ -152,6 +163,7 @@ func (m *MetricsCollectorGithubWorkflows) Setup(collector *collector.Collector)
152
163
"org" ,
153
164
"repo" ,
154
165
"workflowID" ,
166
+ "workflowRunNumber" ,
155
167
},
156
168
)
157
169
m .Collector .RegisterMetricList ("workflowLatestRunStartTime" , m .prometheus .workflowLatestRunStartTime , true )
@@ -165,6 +177,7 @@ func (m *MetricsCollectorGithubWorkflows) Setup(collector *collector.Collector)
165
177
"org" ,
166
178
"repo" ,
167
179
"workflowID" ,
180
+ "workflowRunNumber" ,
168
181
},
169
182
)
170
183
m .Collector .RegisterMetricList ("workflowLatestRunDuration" , m .prometheus .workflowLatestRunDuration , true )
@@ -181,7 +194,11 @@ func (m *MetricsCollectorGithubWorkflows) Setup(collector *collector.Collector)
181
194
"org" ,
182
195
"repo" ,
183
196
"workflowID" ,
197
+ "workflowRunNumber" ,
184
198
"workflow" ,
199
+ "workflowUrl" ,
200
+ "workflowRun" ,
201
+ "workflowRunRul" ,
185
202
"branch" ,
186
203
"actorLogin" ,
187
204
"actorType" ,
@@ -248,8 +265,8 @@ func (m *MetricsCollectorGithubWorkflows) getRepoList(org string) ([]*github.Rep
248
265
return repositories , nil
249
266
}
250
267
251
- func (m * MetricsCollectorGithubWorkflows ) getRepoWorkflows (org , repo string ) ([ ]* github.Workflow , error ) {
252
- var workflows [ ]* github.Workflow
268
+ func (m * MetricsCollectorGithubWorkflows ) getRepoWorkflows (org , repo string ) (map [ int64 ]* github.Workflow , error ) {
269
+ workflows := map [ int64 ]* github.Workflow {}
253
270
254
271
opts := github.ListOptions {PerPage : 100 , Page : 1 }
255
272
@@ -266,7 +283,9 @@ func (m *MetricsCollectorGithubWorkflows) getRepoWorkflows(org, repo string) ([]
266
283
return workflows , err
267
284
}
268
285
269
- workflows = append (workflows , result .Workflows ... )
286
+ for _ , row := range result .Workflows {
287
+ workflows [row .GetID ()] = row
288
+ }
270
289
271
290
// calc next page
272
291
if response .NextPage == 0 {
@@ -369,12 +388,13 @@ func (m *MetricsCollectorGithubWorkflows) Collect(callback chan<- func()) {
369
388
// workflow info metrics
370
389
for _ , workflow := range workflows {
371
390
labels := prometheus.Labels {
372
- "org" : org ,
373
- "repo" : repo .GetName (),
374
- "workflowID" : fmt .Sprintf ("%v" , workflow .GetID ()),
375
- "workflow" : workflow .GetName (),
376
- "state" : workflow .GetState (),
377
- "path" : workflow .GetPath (),
391
+ "org" : org ,
392
+ "repo" : repo .GetName (),
393
+ "workflowID" : fmt .Sprintf ("%v" , workflow .GetID ()),
394
+ "workflow" : workflow .GetName (),
395
+ "state" : workflow .GetState (),
396
+ "path" : workflow .GetPath (),
397
+ "workflowUrl" : workflow .GetURL (),
378
398
}
379
399
for labelName , labelValue := range propLabels {
380
400
labels [labelName ] = labelValue
@@ -389,15 +409,15 @@ func (m *MetricsCollectorGithubWorkflows) Collect(callback chan<- func()) {
389
409
}
390
410
391
411
if len (workflowRuns ) >= 1 {
392
- m .collectRunningRuns (Opts .GitHub .Organization , repo , workflowRuns , callback )
393
- m .collectLatestRun (Opts .GitHub .Organization , repo , workflowRuns , callback )
394
- m .collectConsecutiveFailures (Opts .GitHub .Organization , repo , workflowRuns , callback )
412
+ m .collectRunningRuns (Opts .GitHub .Organization , repo , workflows , workflowRuns , callback )
413
+ m .collectLatestRun (Opts .GitHub .Organization , repo , workflows , workflowRuns , callback )
414
+ m .collectConsecutiveFailures (Opts .GitHub .Organization , repo , workflows , workflowRuns , callback )
395
415
}
396
416
}
397
417
}
398
418
}
399
419
400
- func (m * MetricsCollectorGithubWorkflows ) collectRunningRuns (org string , repo * github.Repository , workflowRun []* github.WorkflowRun , callback chan <- func ()) {
420
+ func (m * MetricsCollectorGithubWorkflows ) collectRunningRuns (org string , repo * github.Repository , workflows map [ int64 ] * github. Workflow , workflowRun []* github.WorkflowRun , callback chan <- func ()) {
401
421
runMetric := m .Collector .GetMetricList ("workflowRunRunning" )
402
422
runStartTimeMetric := m .Collector .GetMetricList ("workflowRunRunningStartTime" )
403
423
@@ -415,29 +435,39 @@ func (m *MetricsCollectorGithubWorkflows) collectRunningRuns(org string, repo *g
415
435
}
416
436
417
437
infoLabels := prometheus.Labels {
418
- "org" : org ,
419
- "repo" : repo .GetName (),
420
- "workflowID" : fmt .Sprintf ("%v" , workflowRun .GetWorkflowID ()),
421
- "workflow" : workflowRun .GetName (),
422
- "event" : workflowRun .GetEvent (),
423
- "branch" : workflowRun .GetHeadBranch (),
424
- "status" : workflowRun .GetStatus (),
425
- "actorLogin" : workflowRun .Actor .GetLogin (),
426
- "actorType" : workflowRun .Actor .GetType (),
438
+ "org" : org ,
439
+ "repo" : repo .GetName (),
440
+ "workflowID" : fmt .Sprintf ("%v" , workflowRun .GetWorkflowID ()),
441
+ "workflowRunNumber" : fmt .Sprintf ("%v" , workflowRun .GetRunNumber ()),
442
+ "workflow" : LABEL_VALUE_UNKNOWN ,
443
+ "workflowUrl" : "" ,
444
+ "workflowRun" : workflowRun .GetName (),
445
+ "workflowRunUrl" : workflowRun .GetURL (),
446
+ "event" : workflowRun .GetEvent (),
447
+ "branch" : workflowRun .GetHeadBranch (),
448
+ "status" : workflowRun .GetStatus (),
449
+ "actorLogin" : workflowRun .Actor .GetLogin (),
450
+ "actorType" : workflowRun .Actor .GetType (),
451
+ }
452
+
453
+ if workflow , ok := workflows [workflowRun .GetWorkflowID ()]; ok {
454
+ infoLabels ["workflow" ] = workflow .GetName ()
455
+ infoLabels ["workflowUrl" ] = workflow .GetURL ()
427
456
}
428
457
429
458
statLabels := prometheus.Labels {
430
- "org" : org ,
431
- "repo" : repo .GetName (),
432
- "workflowID" : fmt .Sprintf ("%v" , workflowRun .GetWorkflowID ()),
459
+ "org" : org ,
460
+ "repo" : repo .GetName (),
461
+ "workflowID" : fmt .Sprintf ("%v" , workflowRun .GetWorkflowID ()),
462
+ "workflowRunNumber" : fmt .Sprintf ("%v" , workflowRun .GetRunNumber ()),
433
463
}
434
464
435
465
runMetric .AddInfo (infoLabels )
436
466
runStartTimeMetric .AddTime (statLabels , workflowRun .GetRunStartedAt ().Time )
437
467
}
438
468
}
439
469
440
- func (m * MetricsCollectorGithubWorkflows ) collectLatestRun (org string , repo * github.Repository , workflowRun []* github.WorkflowRun , callback chan <- func ()) {
470
+ func (m * MetricsCollectorGithubWorkflows ) collectLatestRun (org string , repo * github.Repository , workflows map [ int64 ] * github. Workflow , workflowRun []* github.WorkflowRun , callback chan <- func ()) {
441
471
runMetric := m .Collector .GetMetricList ("workflowLatestRun" )
442
472
runTimestampMetric := m .Collector .GetMetricList ("workflowLatestRunStartTime" )
443
473
runDurationMetric := m .Collector .GetMetricList ("workflowLatestRunDuration" )
@@ -466,21 +496,30 @@ func (m *MetricsCollectorGithubWorkflows) collectLatestRun(org string, repo *git
466
496
467
497
for _ , workflowRun := range latestJobs {
468
498
infoLabels := prometheus.Labels {
469
- "org" : org ,
470
- "repo" : repo .GetName (),
471
- "workflowID" : fmt .Sprintf ("%v" , workflowRun .GetWorkflowID ()),
472
- "workflow" : workflowRun .GetName (),
473
- "event" : workflowRun .GetEvent (),
474
- "branch" : workflowRun .GetHeadBranch (),
475
- "conclusion" : workflowRun .GetConclusion (),
476
- "actorLogin" : workflowRun .Actor .GetLogin (),
477
- "actorType" : workflowRun .Actor .GetType (),
499
+ "org" : org ,
500
+ "repo" : repo .GetName (),
501
+ "workflowID" : fmt .Sprintf ("%v" , workflowRun .GetWorkflowID ()),
502
+ "workflowRunNumber" : fmt .Sprintf ("%v" , workflowRun .GetRunNumber ()),
503
+ "workflow" : LABEL_VALUE_UNKNOWN ,
504
+ "workflowUrl" : "" ,
505
+ "workflowRun" : workflowRun .GetName (),
506
+ "workflowRunUrl" : workflowRun .GetURL (),
507
+ "event" : workflowRun .GetEvent (),
508
+ "branch" : workflowRun .GetHeadBranch (),
509
+ "conclusion" : workflowRun .GetConclusion (),
510
+ "actorLogin" : workflowRun .Actor .GetLogin (),
511
+ "actorType" : workflowRun .Actor .GetType (),
512
+ }
513
+ if workflow , ok := workflows [workflowRun .GetWorkflowID ()]; ok {
514
+ infoLabels ["workflow" ] = workflow .GetName ()
515
+ infoLabels ["workflowUrl" ] = workflow .GetURL ()
478
516
}
479
517
480
518
statLabels := prometheus.Labels {
481
- "org" : org ,
482
- "repo" : repo .GetName (),
483
- "workflowID" : fmt .Sprintf ("%v" , workflowRun .GetWorkflowID ()),
519
+ "org" : org ,
520
+ "repo" : repo .GetName (),
521
+ "workflowID" : fmt .Sprintf ("%v" , workflowRun .GetWorkflowID ()),
522
+ "workflowRunNumber" : fmt .Sprintf ("%v" , workflowRun .GetRunNumber ()),
484
523
}
485
524
486
525
runMetric .AddInfo (infoLabels )
@@ -489,7 +528,7 @@ func (m *MetricsCollectorGithubWorkflows) collectLatestRun(org string, repo *git
489
528
}
490
529
}
491
530
492
- func (m * MetricsCollectorGithubWorkflows ) collectConsecutiveFailures (org string , repo * github.Repository , workflowRun []* github.WorkflowRun , callback chan <- func ()) {
531
+ func (m * MetricsCollectorGithubWorkflows ) collectConsecutiveFailures (org string , repo * github.Repository , workflows map [ int64 ] * github. Workflow , workflowRun []* github.WorkflowRun , callback chan <- func ()) {
493
532
consecutiveFailuresMetric := m .Collector .GetMetricList ("workflowConsecutiveFailures" )
494
533
495
534
consecutiveFailMap := map [int64 ]* struct {
@@ -517,20 +556,31 @@ func (m *MetricsCollectorGithubWorkflows) collectConsecutiveFailures(org string,
517
556
}
518
557
519
558
if _ , exists := consecutiveFailMap [workflowId ]; ! exists {
559
+ infoLabels := prometheus.Labels {
560
+ "org" : org ,
561
+ "repo" : repo .GetName (),
562
+ "workflowID" : fmt .Sprintf ("%v" , workflowRun .GetWorkflowID ()),
563
+ "workflowRunNumber" : fmt .Sprintf ("%v" , workflowRun .GetRunNumber ()),
564
+ "workflow" : LABEL_VALUE_UNKNOWN ,
565
+ "workflowUrl" : "" ,
566
+ "workflowRun" : workflowRun .GetName (),
567
+ "workflowRunUrl" : workflowRun .GetURL (),
568
+ "branch" : workflowRun .GetHeadBranch (),
569
+ "actorLogin" : workflowRun .Actor .GetLogin (),
570
+ "actorType" : workflowRun .Actor .GetType (),
571
+ }
572
+
573
+ if workflow , ok := workflows [workflowRun .GetWorkflowID ()]; ok {
574
+ infoLabels ["workflow" ] = workflow .GetName ()
575
+ infoLabels ["workflowUrl" ] = workflow .GetURL ()
576
+ }
577
+
520
578
consecutiveFailMap [workflowId ] = & struct {
521
579
count int64
522
580
labels prometheus.Labels
523
581
}{
524
- count : 0 ,
525
- labels : prometheus.Labels {
526
- "org" : org ,
527
- "repo" : repo .GetName (),
528
- "workflowID" : fmt .Sprintf ("%v" , workflowRun .GetWorkflowID ()),
529
- "workflow" : workflowRun .GetName (),
530
- "branch" : workflowRun .GetHeadBranch (),
531
- "actorLogin" : workflowRun .Actor .GetLogin (),
532
- "actorType" : workflowRun .Actor .GetType (),
533
- },
582
+ count : 0 ,
583
+ labels : infoLabels ,
534
584
}
535
585
consecutiveFinishedMap [workflowId ] = false
536
586
}
0 commit comments