From 3c518940b0bdb7acd0692d280e1b4e2337fb5236 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Sat, 1 Mar 2025 02:57:41 +0000 Subject: [PATCH] [CI] Make Metrics Container Use Python Logging This patch makes the metrics container use the python logging library. This is more of what we want given we're essentially just logging the status of things. It also means we do not have to explicitly specify an output file and lets us control verbosity a bit more cleanly. --- .ci/metrics/metrics.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.ci/metrics/metrics.py b/.ci/metrics/metrics.py index 354b5058100e..0dc61dbaeb99 100644 --- a/.ci/metrics/metrics.py +++ b/.ci/metrics/metrics.py @@ -3,6 +3,7 @@ import time import os from dataclasses import dataclass import sys +import logging import github from github import Github @@ -220,7 +221,7 @@ def upload_metrics(workflow_metrics, metrics_userid, api_key): """ if len(workflow_metrics) == 0: - print("No metrics found to upload.", file=sys.stderr) + logging.info("No metrics found to upload.") return metrics_batch = [] @@ -249,9 +250,7 @@ def upload_metrics(workflow_metrics, metrics_userid, api_key): ) if response.status_code < 200 or response.status_code >= 300: - print( - f"Failed to submit data to Grafana: {response.status_code}", file=sys.stderr - ) + logging.info(f"Failed to submit data to Grafana: {response.status_code}") def main(): @@ -275,7 +274,7 @@ def main(): current_metrics += get_sampled_workflow_metrics(github_repo) upload_metrics(current_metrics, grafana_metrics_userid, grafana_api_key) - print(f"Uploaded {len(current_metrics)} metrics", file=sys.stderr) + logging.info(f"Uploaded {len(current_metrics)} metrics") for workflow_metric in reversed(current_metrics): if isinstance(workflow_metric, JobMetrics): @@ -287,4 +286,5 @@ def main(): if __name__ == "__main__": + logging.basicConfig(level=logging.INFO) main()