Skip to content

Commit

Permalink
[PTFE-423] ✨ Add workflow name (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspardmoindrot authored Jun 14, 2023
1 parent 16c0b9f commit 87a913d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
9 changes: 5 additions & 4 deletions gh_actions_exporter/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class Metrics(object):
def __init__(self, settings: Settings):
self.settings = settings
self.cost = Cost(settings)
self.workflow_labelnames = [

self.common_labelnames = [
"repository",
"workflow_name",
"repository_visibility",
]
self.job_labelnames = [
"repository",
self.workflow_labelnames = self.common_labelnames.copy()
self.job_labelnames = self.common_labelnames.copy() + [
"job_name",
"repository_visibility",
"runner_type",
]
for relabel in self.settings.job_relabelling:
Expand Down Expand Up @@ -144,6 +144,7 @@ def job_labels(self, webhook: WebHook, settings: Settings) -> dict:
job_name=webhook.workflow_job.name,
repository_visibility=webhook.repository.visibility,
repository=webhook.repository.full_name,
workflow_name=webhook.workflow_job.workflow_name,
)

for relabel in settings.job_relabelling:
Expand Down
3 changes: 2 additions & 1 deletion gh_actions_exporter/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

from datetime import datetime
from typing import Optional

from pydantic import BaseModel


Expand All @@ -16,6 +16,7 @@ class Steps(BaseModel):
class WorkflowJob(BaseModel):
id: int
run_id: int
workflow_name: str
run_url: str
run_attempt: int
runner_name: Optional[str] = None
Expand Down
1 change: 1 addition & 0 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def workflow_job():
"workflow_job": {
"id": 4355026428,
"run_id": 1468134741,
"workflow_name": "test",
"run_url": "https://api.github.com/repos/-devl/fake",
"run_attempt": 1,
"node_id": "CR_kwDOFqdmms8AAAABA5Rt_A",
Expand Down
4 changes: 4 additions & 0 deletions tests/api/metrics/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def test_multiple_job_runs(client, workflow_job, headers):

metrics = client.get("/metrics")
assert metrics.status_code == 200
assert (
f"workflow_name=\"{workflow_job['workflow_job']['workflow_name']}\""
in metrics.text
)

for line in metrics.text.split("\n"):
if "job_duration_seconds_sum{" in line:
Expand Down

0 comments on commit 87a913d

Please sign in to comment.