Skip to content

Commit 07fb21b

Browse files
committed
pr-feedback
1 parent 5f79857 commit 07fb21b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

.ci/metrics/metrics.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,25 @@ def upload_metrics(workflow_metrics, metrics_userid, api_key):
199199
metrics_userid: The userid to use for the upload.
200200
api_key: The API key to use for the upload.
201201
"""
202+
203+
if len(workflow_metrics) == 0:
204+
print("No metrics found to upload.", file=sys.stdout)
205+
return
206+
202207
metrics_batch = []
203208
for workflow_metric in workflow_metrics:
204209
if isinstance(workflow_metric, GaugeMetric):
205210
name = workflow_metric.name.lower().replace(" ", "_")
206211
metrics_batch.append(
207212
f"{name} value={workflow_metric.value} {workflow_metric.time_ns}"
208213
)
209-
else:
214+
elif isinstance(workflow_metric, JobMetrics):
210215
name = workflow_metric.job_name.lower().replace(" ", "_")
211216
metrics_batch.append(
212217
f"{name} queue_time={workflow_metric.queue_time},run_time={workflow_metric.run_time},status={workflow_metric.status} {workflow_metric.created_at_ns}"
213218
)
219+
else:
220+
raise ValueError(f"Unsupported object type {type(workflow_metric)}: {str(workflow_metric)}")
214221

215222
request_data = "\n".join(metrics_batch)
216223
response = requests.post(
@@ -244,8 +251,8 @@ def main():
244251
while True:
245252
current_metrics = get_per_workflow_metrics(github_repo, workflows_to_track)
246253
current_metrics += get_sampled_workflow_metrics(github_repo)
247-
if len(current_metrics) == 0:
248-
print("No metrics found to upload.", file=sys.stdout)
254+
# Always send a hearbeat metric so we can monitor is this container is still able to log to Grafana.
255+
current_metrics.append(GaugeMetric("metrics_container_heartbeat", 1, time.time_ns()))
249256

250257
upload_metrics(current_metrics, grafana_metrics_userid, grafana_api_key)
251258
print(f"Uploaded {len(current_metrics)} metrics", file=sys.stdout)

0 commit comments

Comments
 (0)