fix: add Go and Raw registries to metrics detection and health endpoint (#97)

detect_registry() in metrics.rs was missing branches for /go/ and /raw/
paths, causing all requests to those registries to be labeled "other" in
Prometheus metrics. dashboard_metrics.rs already lists all seven
registries, so this was an oversight.

Also adds go and raw fields to RegistriesHealth so the /health endpoint
reports all seven registries consistently.

Fixes the test_detect_registry_go_path test which previously asserted
the wrong behavior ("other" instead of "go"), and adds tests for raw
path detection and prefix collision safety.

// ticktockbent

Co-authored-by: DevITWay | Pavel Volkov <devitway@gmail.com>
This commit is contained in:
Wes
2026-04-05 19:09:23 -04:00
committed by GitHub
parent 3fd92278c3
commit b949ef49b8
3 changed files with 26 additions and 1 deletions

View File

@@ -1,4 +1,10 @@
# Changelog # Changelog
## [Unreleased]
### Fixed
- Go and Raw registries missing from Prometheus metrics (`detect_registry` labeled both as "other")
- Go and Raw registries missing from `/health` endpoint `registries` object
## [0.4.0] - 2026-04-05 ## [0.4.0] - 2026-04-05
### Added ### Added

View File

@@ -31,6 +31,8 @@ pub struct RegistriesHealth {
pub npm: String, pub npm: String,
pub cargo: String, pub cargo: String,
pub pypi: String, pub pypi: String,
pub go: String,
pub raw: String,
} }
pub fn routes() -> Router<Arc<AppState>> { pub fn routes() -> Router<Arc<AppState>> {
@@ -70,6 +72,8 @@ async fn health_check(State(state): State<Arc<AppState>>) -> (StatusCode, Json<H
npm: "ok".to_string(), npm: "ok".to_string(),
cargo: "ok".to_string(), cargo: "ok".to_string(),
pypi: "ok".to_string(), pypi: "ok".to_string(),
go: "ok".to_string(),
raw: "ok".to_string(),
}, },
}; };

View File

@@ -121,6 +121,10 @@ fn detect_registry(path: &str) -> String {
"cargo".to_string() "cargo".to_string()
} else if path.starts_with("/simple") || path.starts_with("/packages") { } else if path.starts_with("/simple") || path.starts_with("/packages") {
"pypi".to_string() "pypi".to_string()
} else if path.starts_with("/go/") {
"go".to_string()
} else if path.starts_with("/raw/") {
"raw".to_string()
} else if path.starts_with("/ui") { } else if path.starts_with("/ui") {
"ui".to_string() "ui".to_string()
} else { } else {
@@ -205,8 +209,19 @@ mod tests {
fn test_detect_registry_go_path() { fn test_detect_registry_go_path() {
assert_eq!( assert_eq!(
detect_registry("/go/github.com/user/repo/@v/v1.0.0.info"), detect_registry("/go/github.com/user/repo/@v/v1.0.0.info"),
"other" "go"
); );
assert_eq!(detect_registry("/go/github.com/user/repo/@latest"), "go");
// Bare prefix without trailing slash should not match
assert_eq!(detect_registry("/goblin/something"), "other");
}
#[test]
fn test_detect_registry_raw_path() {
assert_eq!(detect_registry("/raw/my-project/artifact.tar.gz"), "raw");
assert_eq!(detect_registry("/raw/data/file.bin"), "raw");
// Bare prefix without trailing slash should not match
assert_eq!(detect_registry("/rawdata/file"), "other");
} }
#[test] #[test]