Skip to content

Commit 01404bc

Browse files
committed
feat(metrics): add dedicated timeout metric
Introduce a new gauge metric `git_mirror_timeout` which tracks projects that encounter a `GitError::GitCommandTimeout` during the mirroring step. Projects that fail for other reasons continue to increment the existing `git_mirror_fail gauge`. These two gauges are mutually exclusive.
1 parent 8ecb409 commit 01404bc

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Add a new `git_mirror_timeout` gauge metric to track how many projects run into a timeout.
12+
913
## [0.14.16] - 2025-10-20
1014

1115
### Added

src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use prometheus::{Encoder, TextEncoder};
4141

4242
use provider::{MirrorError, MirrorResult, Provider};
4343

44-
use git::{Git, GitWrapper};
44+
use git::{Git, GitError, GitWrapper};
4545

4646
use error::{GitMirrorError, Result};
4747

@@ -114,6 +114,8 @@ fn run_sync_task(v: &[MirrorResult], label: &str, opts: &MirrorOptions) -> TestS
114114
let proj_skip =
115115
register_gauge_vec!("git_mirror_skip", "Skipped projects", &["mirror"]).unwrap();
116116
let proj_fail = register_gauge_vec!("git_mirror_fail", "Failed projects", &["mirror"]).unwrap();
117+
let proj_timeout =
118+
register_gauge_vec!("git_mirror_timeout", "Timed-out projects", &["mirror"]).unwrap();
117119
let proj_ok = register_gauge_vec!("git_mirror_ok", "OK projects", &["mirror"]).unwrap();
118120
let proj_start = register_gauge_vec!(
119121
"git_mirror_project_start",
@@ -140,6 +142,7 @@ fn run_sync_task(v: &[MirrorResult], label: &str, opts: &MirrorOptions) -> TestS
140142
let name = format!("{} -> {}", x.origin, x.destination);
141143
let proj_fail = proj_fail.clone();
142144
let proj_ok = proj_ok.clone();
145+
let proj_timeout = proj_timeout.clone();
143146
let proj_start = proj_start.clone();
144147
let proj_end = proj_end.clone();
145148
let label = label.to_string();
@@ -199,7 +202,15 @@ fn run_sync_task(v: &[MirrorResult], label: &str, opts: &MirrorOptions) -> TestS
199202
proj_end
200203
.with_label_values(&[&x.origin, &x.destination, &label])
201204
.set(OffsetDateTime::now_utc().unix_timestamp() as f64);
202-
proj_fail.with_label_values(&[&label]).inc();
205+
if matches!(
206+
&e,
207+
GitMirrorError::GitError(inner)
208+
if matches!(**inner, GitError::GitCommandTimeout { .. })
209+
) {
210+
proj_timeout.with_label_values(&[&label]).inc();
211+
} else {
212+
proj_fail.with_label_values(&[&label]).inc();
213+
}
203214
error!("Unable to sync repo {name} ({e})");
204215
TestCaseBuilder::error(
205216
&name,

0 commit comments

Comments
 (0)