Skip to content

Commit 785d277

Browse files
mahipdeora25claude
andauthored
[gitlab_runner] Add gitlab_runner_job_queue_duration_seconds metric (DataDog#22621)
Add support for the `gitlab_runner_job_queue_duration_seconds` histogram metric which tracks how long jobs wait in the queue before being picked up by a runner. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1aa4b33 commit 785d277

10 files changed

Lines changed: 272 additions & 54 deletions

File tree

gitlab_runner/assets/configuration/spec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ files:
2020
- ci_runner_errors
2121
- ci_ssh_docker_machines_provider_machine_creation_duration_seconds
2222
- ci_ssh_docker_machines_provider_machine_states
23+
- gitlab_runner_api_request_duration_seconds
2324
- gitlab_runner_autoscaling_machine_creation_duration_seconds
2425
- gitlab_runner_autoscaling_machine_states
2526
- gitlab_runner_errors_total
27+
- gitlab_runner_job_queue_duration_seconds
2628
- gitlab_runner_jobs
2729
- gitlab_runner_version_info
2830
- go_gc_duration_seconds
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add default metrics list to automatically collect all standard GitLab Runner metrics. Add `gitlab_runner_job_queue_duration_seconds` and `gitlab_runner_api_request_duration_seconds` metrics.

gitlab_runner/datadog_checks/gitlab_runner/data/conf.yaml.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ init_config:
1212
- ci_runner_errors
1313
- ci_ssh_docker_machines_provider_machine_creation_duration_seconds
1414
- ci_ssh_docker_machines_provider_machine_states
15+
- gitlab_runner_api_request_duration_seconds
1516
- gitlab_runner_autoscaling_machine_creation_duration_seconds
1617
- gitlab_runner_autoscaling_machine_states
1718
- gitlab_runner_errors_total
19+
- gitlab_runner_job_queue_duration_seconds
1820
- gitlab_runner_jobs
1921
- gitlab_runner_version_info
2022
- go_gc_duration_seconds

gitlab_runner/datadog_checks/gitlab_runner/gitlab_runner.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from datadog_checks.base.checks.openmetrics import OpenMetricsBaseCheck
1111
from datadog_checks.base.errors import CheckException
1212

13+
from .metrics import METRICS_LIST
14+
1315

1416
class GitlabRunnerCheck(OpenMetricsBaseCheck):
1517
"""
@@ -66,8 +68,10 @@ def _create_gitlab_runner_prometheus_instance(self, instance, init_config):
6668
"""
6769
Set up the gitlab_runner instance so it can be used in OpenMetricsBaseCheck
6870
"""
69-
# Mapping from Prometheus metrics names to Datadog ones
70-
# For now it's a 1:1 mapping
71+
# Hardcoded metrics that are always collected
72+
metrics = list(METRICS_LIST)
73+
74+
# Add user-configured allowed_metrics
7175
allowed_metrics = init_config.get('allowed_metrics')
7276
if allowed_metrics is None:
7377
raise CheckException("At least one metric must be whitelisted in `allowed_metrics`.")
@@ -77,6 +81,9 @@ def _create_gitlab_runner_prometheus_instance(self, instance, init_config):
7781
if 'ci_runner_version_info' in allowed_metrics:
7882
allowed_metrics.remove('ci_runner_version_info')
7983

84+
metrics.extend(allowed_metrics)
85+
metrics = list(set(metrics))
86+
8087
gitlab_runner_instance = deepcopy(instance)
8188

8289
# gitlab_runner uses 'prometheus_endpoint' and not 'prometheus_url', so we have to rename the key
@@ -85,7 +92,7 @@ def _create_gitlab_runner_prometheus_instance(self, instance, init_config):
8592
gitlab_runner_instance.update(
8693
{
8794
'namespace': 'gitlab_runner',
88-
'metrics': allowed_metrics,
95+
'metrics': metrics,
8996
# Defaults that were set when gitlab_runner was based on PrometheusCheck
9097
'send_monotonic_counter': instance.get('send_monotonic_counter', False),
9198
'health_service_check': instance.get('health_service_check', False),
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# (C) Datadog, Inc. 2026-present
2+
# All rights reserved
3+
# Licensed under a 3-clause BSD style license (see LICENSE)
4+
5+
METRICS_LIST = [
6+
'ci_docker_machines_provider_machine_creation_duration_seconds',
7+
'ci_docker_machines_provider_machine_states',
8+
'ci_runner_builds',
9+
'ci_runner_errors',
10+
'ci_ssh_docker_machines_provider_machine_creation_duration_seconds',
11+
'ci_ssh_docker_machines_provider_machine_states',
12+
'gitlab_runner_api_request_duration_seconds',
13+
'gitlab_runner_autoscaling_machine_creation_duration_seconds',
14+
'gitlab_runner_autoscaling_machine_states',
15+
'gitlab_runner_errors_total',
16+
'gitlab_runner_job_queue_duration_seconds',
17+
'gitlab_runner_jobs',
18+
'gitlab_runner_version_info',
19+
'go_gc_duration_seconds',
20+
'go_goroutines',
21+
'go_memstats_alloc_bytes',
22+
'go_memstats_alloc_bytes_total',
23+
'go_memstats_buck_hash_sys_bytes',
24+
'go_memstats_frees_total',
25+
'go_memstats_gc_sys_bytes',
26+
'go_memstats_heap_alloc_bytes',
27+
'go_memstats_heap_idle_bytes',
28+
'go_memstats_heap_inuse_bytes',
29+
'go_memstats_heap_objects',
30+
'go_memstats_heap_released_bytes_total',
31+
'go_memstats_heap_sys_bytes',
32+
'go_memstats_last_gc_time_seconds',
33+
'go_memstats_lookups_total',
34+
'go_memstats_mallocs_total',
35+
'go_memstats_mcache_inuse_bytes',
36+
'go_memstats_mcache_sys_bytes',
37+
'go_memstats_mspan_inuse_bytes',
38+
'go_memstats_mspan_sys_bytes',
39+
'go_memstats_next_gc_bytes',
40+
'go_memstats_other_sys_bytes',
41+
'go_memstats_stack_inuse_bytes',
42+
'go_memstats_stack_sys_bytes',
43+
'go_memstats_sys_bytes',
44+
'process_cpu_seconds_total',
45+
'process_max_fds',
46+
'process_open_fds',
47+
'process_resident_memory_bytes',
48+
'process_start_time_seconds',
49+
'process_virtual_memory_bytes',
50+
]

0 commit comments

Comments
 (0)