Skip to content

Commit e693d1d

Browse files
authored
Set xDS registry (#1162)
1 parent 64d2a67 commit e693d1d

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

crates/xds/src/metrics.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
use arc_swap::ArcSwap;
1817
use once_cell::sync::Lazy;
1918
use prometheus::{IntCounterVec, IntGaugeVec, Registry};
2019

@@ -23,20 +22,20 @@ pub(crate) const CONTROL_PLANE_LABEL: &str = "control_plane";
2322
pub(crate) const TYPE_LABEL: &str = "type";
2423

2524
/// TODO: Remove and replace with a local registry.
26-
static REGISTRY: Lazy<ArcSwap<Registry>> = Lazy::new(|| {
27-
ArcSwap::new(std::sync::Arc::new(
28-
Registry::new_custom(Some("quilkin".into()), None).unwrap(),
29-
))
30-
});
25+
static REGISTRY_ONCE: parking_lot::Once = parking_lot::Once::new();
26+
static mut REGISTRY: Option<&'static Registry> = None;
3127

3228
/// Sets the [`Registry`] containing all the metrics registered in xDS.
33-
pub fn set_registry(registry: std::sync::Arc<Registry>) {
34-
REGISTRY.store(registry);
29+
pub fn set_registry(registry: &'static Registry) {
30+
REGISTRY_ONCE.call_once(|| unsafe {
31+
REGISTRY = Some(registry);
32+
});
3533
}
3634

3735
/// Returns the [`Registry`] containing all the metrics registered in xDS.
38-
pub fn registry() -> arc_swap::Guard<std::sync::Arc<Registry>> {
39-
REGISTRY.load()
36+
#[inline]
37+
pub fn registry() -> &'static Registry {
38+
unsafe { REGISTRY }.expect("set_registry must be called")
4039
}
4140

4241
pub(crate) fn active_control_planes(control_plane: &str) -> prometheus::IntGauge {

src/cli/service.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ impl Service {
246246
config: &Arc<Config>,
247247
shutdown_rx: &crate::signal::ShutdownRx,
248248
) -> crate::Result<tokio::task::JoinHandle<crate::Result<()>>> {
249+
quilkin_xds::metrics::set_registry(crate::metrics::registry());
250+
249251
let mut shutdown_rx = shutdown_rx.clone();
250252
let mds_task = self.publish_mds(config)?;
251253
let (phoenix_task, phoenix_finalizer) = self.publish_phoenix(config)?;

0 commit comments

Comments
 (0)