[llvm] [CI] Upstream metrics script and container definition (PR #117461)
Nathan Gauër via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 25 04:49:13 PST 2024
================
@@ -0,0 +1,180 @@
+import requests
+import time
+import os
+from dataclasses import dataclass
+
+from github import Github
+from github import Auth
+
+GRAFANA_URL = (
+ "https://influx-prod-13-prod-us-east-0.grafana.net/api/v1/push/influx/write"
+)
+GITHUB_PROJECT = "llvm/llvm-project"
+WORKFLOWS_TO_TRACK = ["Check code formatting"]
+
+
+ at dataclass
+class JobMetrics:
+ job_name: str
+ queue_time: int
+ run_time: int
+ status: int
+ created_at_ns: int
+ workflow_id: int
+
+
+def get_metrics(github_repo, workflows_to_track):
+ """Gets the metrics for specified Github workflows.
+
+ This function takes in a list of workflows to track, and optionally the
+ workflow ID of the last tracked invocation. It grabs the relevant data
+ from Github, returning it to the caller.
+
+ Args:
+ github_repo: A github repo object to use to query the relevant information.
+ workflows_to_track: A dictionary mapping workflow names to the last
+ invocation ID where metrics have been collected, or None to collect the
+ last five results.
+
+ Returns:
+ Returns a list of JobMetrics objects, containing the relevant metrics about
+ the workflow.
+ """
+ workflow_runs = iter(github_repo.get_workflow_runs())
+
+ workflow_metrics = []
+
+ workflows_to_include = {}
+ for workflow_to_track in workflows_to_track:
+ workflows_to_include[workflow_to_track] = True
+ workflows_left_to_include = len(workflows_to_track)
+
+ while True:
+ workflow_run = next(workflow_runs)
+ if workflow_run.status != "completed":
+ continue
+
+ interesting_workflow = False
+ for workflow_name in workflows_to_track:
+ if workflow_run.name == workflow_name:
+ interesting_workflow = True
+ break
+ if not interesting_workflow:
+ continue
+
+ if not workflows_to_include[workflow_run.name]:
+ continue
----------------
Keenuts wrote:
This goes along the deletion of line 88 to 98.
```suggestion
# This workflow is not tracked at all. Ignoring.
if workflow_run.name not in workflows_to_track:
continue
# This workflow was already sampled for this run. Ignoring.
if workflow_run.name not in workflows_to_include
continue
# This exact workflow has already been sampled in a previous scrape.
# Also, the API returns a sorted list: most recent first.
# So stop looking for this particular workflow.
# We cannot however break out of the loop: if a new workflow was just
# added to the watchlist, its last run might have happened earlier than
# this one.
if workflows_to_track[workflow_run.name] == workflow_run.id:
workflows_to_include.remove(workflow_run.name)
continue
```
https://github.com/llvm/llvm-project/pull/117461
More information about the llvm-commits
mailing list