Skip to main content

loadwise_core/
metrics.rs

1//! Optional observability hooks — bring your own Prometheus / OpenTelemetry.
2
3use std::fmt;
4
5use crate::health::HealthStatus;
6
7/// Callback interface for observability. The library never pulls in metrics/tracing
8/// dependencies — users implement this to bridge to their own stack.
9pub trait MetricsCollector: Send + Sync {
10    /// Called each time a strategy selects a node.
11    fn on_selection(&self, node_id: &dyn fmt::Debug, strategy_name: &str);
12    /// Called when a node's health status transitions.
13    fn on_health_change(&self, node_id: &dyn fmt::Debug, from: HealthStatus, to: HealthStatus);
14}
15
16/// Default no-op implementation.
17pub struct NoopCollector;
18
19impl MetricsCollector for NoopCollector {
20    fn on_selection(&self, _node_id: &dyn fmt::Debug, _strategy_name: &str) {}
21    fn on_health_change(&self, _node_id: &dyn fmt::Debug, _from: HealthStatus, _to: HealthStatus) {
22    }
23}