diff --git a/scripts/jobs_status_exporter/metrics.py b/scripts/jobs_status_exporter/metrics.py index 252495271..7631d9ff7 100644 --- a/scripts/jobs_status_exporter/metrics.py +++ b/scripts/jobs_status_exporter/metrics.py @@ -23,24 +23,32 @@ def fetch_jobs_by_runner(runner_id): """Fetch jobs from a specific GitLab Runner and update Prometheus metrics.""" - headers = {'PRIVATE-TOKEN': GITLAB_PRIVATE_TOKEN} - response = requests.get(GITLAB_API_ENDPOINT.format(runner_id), headers=headers) - response.raise_for_status() - jobs = response.json() - - for gauge in status_gauges.values(): - gauge.set(0) - - for job in jobs: - status = job.get('status') - if status in status_gauges: - status_gauges[status].inc() + page = 1 + while True: + headers = {'PRIVATE-TOKEN': GITLAB_PRIVATE_TOKEN} + params = {'page': page, 'per_page': 100} + response = requests.get(GITLAB_API_ENDPOINT.format(runner_id), headers=headers, params=params) + response.raise_for_status() + + jobs = response.json() + if not jobs: + break + + for job in jobs: + status = job.get('status') + if status in status_gauges: + status_gauges[status].inc() + + page += 1 def main(): start_http_server(8000) print("Metrics server running on port 8000") while True: + for gauge in status_gauges.values(): + gauge.set(0) + fetch_jobs_by_runner(RUNNER_ID) time.sleep(60)