From 61d4796d84960ec9f25392635afceea3a3bd0916 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 11 Dec 2025 08:47:08 +0000 Subject: refactor: move metrics tests to tests/sync/ structure (Phase 7) --- tests/common/sync_helpers.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/common/sync_helpers.rs') diff --git a/tests/common/sync_helpers.rs b/tests/common/sync_helpers.rs index 50d0d7a..7788783 100644 --- a/tests/common/sync_helpers.rs +++ b/tests/common/sync_helpers.rs @@ -561,6 +561,37 @@ pub fn repo_coord(keys: &Keys, identifier: &str) -> String { ) } +// ============================================================================ +// Metrics Helpers +// ============================================================================ + +/// Fetch Prometheus metrics from a relay's `/metrics` endpoint. +/// +/// Converts the WebSocket URL to HTTP and fetches the metrics endpoint. +/// Useful for verifying sync-related metrics in tests. +/// +/// # Arguments +/// * `relay_url` - WebSocket URL of the relay (e.g., "ws://127.0.0.1:8080") +/// +/// # Returns +/// * `Ok(String)` - The metrics text in Prometheus format +/// * `Err(reqwest::Error)` - If the request fails +/// +/// # Example +/// ```ignore +/// let metrics = fetch_metrics("ws://127.0.0.1:8080").await?; +/// assert!(metrics.contains("ngit_sync_")); +/// ``` +pub async fn fetch_metrics(relay_url: &str) -> Result { + // Convert ws:// URL to http:// for metrics endpoint + let http_url = relay_url + .replace("ws://", "http://") + .replace("/", "") + + "/metrics"; + + reqwest::get(&http_url).await?.text().await +} + #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3