[llvm] [CI] Upstream metrics script and container definition (PR #117461)
Nathan Gauër via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 29 04:38:31 PST 2024
================
@@ -0,0 +1,185 @@
+import requests
+import time
+import os
+from dataclasses import dataclass
+import sys
+
+import github
+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"]
+SCRAPE_INTERVAL_SECONDS = 5 * 60
+
+
+ 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: github.Repository, workflows_to_track: dict[str, int]):
+ """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 = set(workflows_to_track.keys())
+
+ while len(workflows_to_include) > 0:
+ workflow_run = next(workflow_runs)
+ if workflow_run.status != "completed":
+ continue
+
+ # This workflow is not tracked at all. Ignoring.
+ if workflow_run.name not in workflows_to_track:
+ continue
+
----------------
Keenuts wrote:
```suggestion
```
Actually now that I look at it: `workflows_to_include` is a subset (or copy for 1st iteration) of `workflows_to_track`. So this statement is redundant.
https://github.com/llvm/llvm-project/pull/117461
More information about the llvm-commits
mailing list