diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 08:47:08 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 08:47:08 +0000 |
| commit | 61d4796d84960ec9f25392635afceea3a3bd0916 (patch) | |
| tree | 98bd7c10d34decc2f7c96f50ddead8e8dc63f473 /tests/common/sync_helpers.rs | |
| parent | ffcf8a7bc679f0aff9135063d343be3161b3b439 (diff) | |
refactor: move metrics tests to tests/sync/ structure (Phase 7)
Diffstat (limited to 'tests/common/sync_helpers.rs')
| -rw-r--r-- | tests/common/sync_helpers.rs | 31 |
1 files changed, 31 insertions, 0 deletions
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 { | |||
| 561 | ) | 561 | ) |
| 562 | } | 562 | } |
| 563 | 563 | ||
| 564 | // ============================================================================ | ||
| 565 | // Metrics Helpers | ||
| 566 | // ============================================================================ | ||
| 567 | |||
| 568 | /// Fetch Prometheus metrics from a relay's `/metrics` endpoint. | ||
| 569 | /// | ||
| 570 | /// Converts the WebSocket URL to HTTP and fetches the metrics endpoint. | ||
| 571 | /// Useful for verifying sync-related metrics in tests. | ||
| 572 | /// | ||
| 573 | /// # Arguments | ||
| 574 | /// * `relay_url` - WebSocket URL of the relay (e.g., "ws://127.0.0.1:8080") | ||
| 575 | /// | ||
| 576 | /// # Returns | ||
| 577 | /// * `Ok(String)` - The metrics text in Prometheus format | ||
| 578 | /// * `Err(reqwest::Error)` - If the request fails | ||
| 579 | /// | ||
| 580 | /// # Example | ||
| 581 | /// ```ignore | ||
| 582 | /// let metrics = fetch_metrics("ws://127.0.0.1:8080").await?; | ||
| 583 | /// assert!(metrics.contains("ngit_sync_")); | ||
| 584 | /// ``` | ||
| 585 | pub async fn fetch_metrics(relay_url: &str) -> Result<String, reqwest::Error> { | ||
| 586 | // Convert ws:// URL to http:// for metrics endpoint | ||
| 587 | let http_url = relay_url | ||
| 588 | .replace("ws://", "http://") | ||
| 589 | .replace("/", "") | ||
| 590 | + "/metrics"; | ||
| 591 | |||
| 592 | reqwest::get(&http_url).await?.text().await | ||
| 593 | } | ||
| 594 | |||
| 564 | #[cfg(test)] | 595 | #[cfg(test)] |
| 565 | mod tests { | 596 | mod tests { |
| 566 | use super::*; | 597 | use super::*; |