@@ -47,36 +47,51 @@ def get_sampled_workflow_metrics(github_repo: github.Repository):
4747 # Other states are available (pending, waiting, etc), but the meaning
4848 # is not documented (See #70540).
4949 # "queued" seems to be the info we want.
50- queued_workflow_count = len (
51- [
52- x
53- for x in github_repo .get_workflow_runs (status = "queued" )
54- if x .name in WORKFLOWS_TO_TRACK
55- ]
56- )
57- running_workflow_count = len (
58- [
59- x
60- for x in github_repo .get_workflow_runs (status = "in_progress" )
61- if x .name in WORKFLOWS_TO_TRACK
62- ]
63- )
50+ queued_job_counts = {}
51+ for queued_workflow in github_repo .get_workflow_runs (status = "queued" ):
52+ if queued_workflow .name not in WORKFLOWS_TO_TRACK :
53+ continue
54+ for queued_workflow_job in queued_workflow .jobs ():
55+ job_name = queued_workflow_job .name
56+ if queued_workflow_job .status != "queued" :
57+ continue
58+
59+ if job_name not in queued_job_counts :
60+ queued_job_counts [job_name ] = 1
61+ else :
62+ queued_job_counts [job_name ] += 1
63+
64+ running_job_counts = {}
65+ for running_workflow in github_repo .get_workflow_runs (status = "in_progress" ):
66+ if running_workflow .name not in WORKFLOWS_TO_TRACK :
67+ continue
68+ for running_workflow_job in running_workflow .jobs ():
69+ job_name = running_workflow_job .name
70+ if running_workflow_job .status != "in_progress" :
71+ continue
72+
73+ if job_name not in running_job_counts :
74+ running_job_counts [job_name ] = 1
75+ else :
76+ running_job_counts [job_name ] += 1
6477
6578 workflow_metrics = []
66- workflow_metrics .append (
67- GaugeMetric (
68- "workflow_queue_size" ,
69- queued_workflow_count ,
70- time .time_ns (),
79+ for queued_job in queued_job_counts :
80+ workflow_metrics .append (
81+ GaugeMetric (
82+ f"workflow_queue_size_{ queued_job } " ,
83+ queued_job_counts [queued_job ],
84+ time .time_ns (),
85+ )
7186 )
72- )
73- workflow_metrics .append (
74- GaugeMetric (
75- "running_workflow_count" ,
76- running_workflow_count ,
77- time .time_ns (),
87+ for running_job in running_job_counts :
88+ workflow_metrics .append (
89+ GaugeMetric (
90+ f"running_workflow_count_{ running_job } " ,
91+ running_job_counts [running_job ],
92+ time .time_ns (),
93+ )
7894 )
79- )
8095 # Always send a hearbeat metric so we can monitor is this container is still able to log to Grafana.
8196 workflow_metrics .append (
8297 GaugeMetric ("metrics_container_heartbeat" , 1 , time .time_ns ())
0 commit comments