diff --git a/gh_actions_exporter/metrics.py b/gh_actions_exporter/metrics.py index 22518ff..4dbd1ec 100644 --- a/gh_actions_exporter/metrics.py +++ b/gh_actions_exporter/metrics.py @@ -187,6 +187,6 @@ def handle_job_duration(self, webhook: WebHook): - webhook.workflow_job.started_at.timestamp()) self.job_duration.labels(**labels).observe(duration) elif webhook.workflow_job.status == "in_progress": - duration = (webhook.workflow_job.steps[0].completed_at.timestamp() + duration = (webhook.workflow_job.steps[0].started_at.timestamp() - webhook.workflow_job.started_at.timestamp()) self.job_start_duration.labels(**labels).observe(duration) diff --git a/tests/api/conftest.py b/tests/api/conftest.py index 6558bb9..2bf3da7 100644 --- a/tests/api/conftest.py +++ b/tests/api/conftest.py @@ -64,8 +64,8 @@ def workflow_job(): "status": "in_progress", "conclusion": None, "number": 1, - "started_at": "2021-11-29T14:46:57Z", - "completed_at": "2021-11-29T14:54:57Z" + "started_at": "2021-11-29T14:50:57Z", + "completed_at": None } ], "labels": ["github-hosted"] diff --git a/tests/api/test_job.py b/tests/api/test_job.py index b5bc923..e10a0d8 100644 --- a/tests/api/test_job.py +++ b/tests/api/test_job.py @@ -24,7 +24,7 @@ def test_workflow_job_in_progress(client, workflow_job, headers): if 'inprogress_count_total{' in line: assert "1.0" in line if 'start_duration_seconds_sum{' in line: - assert '480.0' in line + assert '240.0' in line def test_workflow_job_label_self_hosted(client, workflow_job, headers): @@ -56,4 +56,4 @@ def test_multiple_job_runs(client, workflow_job, headers): if 'job_total_count_total{' in line: assert '1.0' in line if 'job_start_duration_seconds_sum{' in line: - assert '480.0' in line + assert '240.0' in line