@@ -130,34 +130,6 @@ def get_per_workflow_metrics(
130130 workflow_jobs = workflow_run .jobs ()
131131 if workflow_jobs .totalCount == 0 :
132132 continue
133- if workflow_jobs .totalCount > 1 :
134- raise ValueError (
135- f"Encountered an unexpected number of jobs: { workflow_jobs .totalCount } "
136- )
137-
138- created_at = workflow_jobs [0 ].created_at
139- started_at = workflow_jobs [0 ].started_at
140- completed_at = workflow_jobs [0 ].completed_at
141-
142- job_result = int (workflow_jobs [0 ].conclusion == "success" )
143- if job_result :
144- # We still might want to mark the job as a failure if one of the steps
145- # failed. This is required due to use setting continue-on-error in
146- # the premerge pipeline to prevent sending emails while we are
147- # testing the infrastructure.
148- # TODO(boomanaiden154): Remove this once the premerge pipeline is no
149- # longer in a testing state and we can directly assert the workflow
150- # result.
151- for step in workflow_jobs [0 ].steps :
152- if step .conclusion != "success" :
153- job_result = 0
154- break
155-
156- queue_time = started_at - created_at
157- run_time = completed_at - started_at
158-
159- if run_time .seconds == 0 :
160- continue
161133
162134 if (
163135 workflows_to_track [workflow_run .name ] is None
@@ -170,20 +142,45 @@ def get_per_workflow_metrics(
170142 ):
171143 break
172144
173- # The timestamp associated with the event is expected by Grafana to be
174- # in nanoseconds.
175- created_at_ns = int (created_at .timestamp ()) * 10 ** 9
176-
177- workflow_metrics .append (
178- JobMetrics (
179- workflow_run .name ,
180- queue_time .seconds ,
181- run_time .seconds ,
182- job_result ,
183- created_at_ns ,
184- workflow_run .id ,
145+ for workflow_job in workflow_jobs :
146+ created_at = workflow_job .created_at
147+ started_at = workflow_job .started_at
148+ completed_at = workflow_job .completed_at
149+
150+ job_result = int (workflow_job .conclusion == "success" )
151+ if job_result :
152+ # We still might want to mark the job as a failure if one of the steps
153+ # failed. This is required due to use setting continue-on-error in
154+ # the premerge pipeline to prevent sending emails while we are
155+ # testing the infrastructure.
156+ # TODO(boomanaiden154): Remove this once the premerge pipeline is no
157+ # longer in a testing state and we can directly assert the workflow
158+ # result.
159+ for step in workflow_job .steps :
160+ if step .conclusion != "success" :
161+ job_result = 0
162+ break
163+
164+ queue_time = started_at - created_at
165+ run_time = completed_at - started_at
166+
167+ if run_time .seconds == 0 :
168+ continue
169+
170+ # The timestamp associated with the event is expected by Grafana to be
171+ # in nanoseconds.
172+ created_at_ns = int (created_at .timestamp ()) * 10 ** 9
173+
174+ workflow_metrics .append (
175+ JobMetrics (
176+ workflow_run .name + "-" + workflow_job .name ,
177+ queue_time .seconds ,
178+ run_time .seconds ,
179+ job_result ,
180+ created_at_ns ,
181+ workflow_run .id ,
182+ )
185183 )
186- )
187184
188185 return workflow_metrics
189186
0 commit comments