#![cfg(feature = "metrics")]
use metrics::counter;
use scalo::metrics::{MetricsConfig, MetricsManager};
#[test]
fn a_manager_builds_and_records_with_no_tokio_runtime() {
let manager = MetricsManager::with_config(MetricsConfig {
namespace: String::new(),
enable_process_metrics: false,
enable_container_metrics: false,
..MetricsConfig::default()
});
counter!("sync_context_probe").increment(3);
let rendered = manager
.render_handle()
.expect("Prometheus recorder must install without a runtime")
.render();
assert!(
rendered.contains("sync_context_probe"),
"scrape endpoint must still work without a runtime:\n{rendered}"
);
}
#[test]
fn export_reports_itself_inactive_without_a_runtime() {
#[cfg(feature = "otel-metrics")]
{
let config = scalo::metrics::OtelMetricsConfig::default();
assert!(
!config.is_active(),
"export must stand down with no runtime rather than panicking"
);
}
}
#[tokio::test]
async fn export_is_active_again_once_a_runtime_exists() {
#[cfg(feature = "otel-metrics")]
{
let config = scalo::metrics::OtelMetricsConfig::default();
assert!(
config.is_active(),
"the runtime guard must not switch export off where it CAN work"
);
}
}