From 2918ce5aca61d4ee6477801055d4eb85d9c3d322 Mon Sep 17 00:00:00 2001 From: jonathanrainer Date: Thu, 7 Nov 2024 12:48:37 +0000 Subject: [PATCH] FLEET-19 Implement new `activate` hook --- apollo-router/src/plugin/mod.rs | 10 ++++++++++ apollo-router/src/services/supergraph/service.rs | 5 +---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apollo-router/src/plugin/mod.rs b/apollo-router/src/plugin/mod.rs index 33548684913..bb487df8e04 100644 --- a/apollo-router/src/plugin/mod.rs +++ b/apollo-router/src/plugin/mod.rs @@ -630,6 +630,9 @@ pub(crate) trait PluginPrivate: Send + Sync + 'static { fn web_endpoints(&self) -> MultiMap { MultiMap::new() } + + /// This is invoked once after the OTEL meter has been refreshed. + async fn activate(&self) {} } #[async_trait] @@ -733,6 +736,9 @@ pub(crate) trait DynPlugin: Send + Sync + 'static { /// Support downcasting #[cfg(test)] fn as_any_mut(&mut self) -> &mut dyn std::any::Any; + + /// This is invoked once after the OTEL meter has been refreshed. + async fn activate(&self) {} } #[async_trait] @@ -783,6 +789,10 @@ where fn as_any_mut(&mut self) -> &mut dyn std::any::Any { self } + + async fn activate(&self) { + self.activate().await; + } } /// Register a plugin with a group and a name diff --git a/apollo-router/src/services/supergraph/service.rs b/apollo-router/src/services/supergraph/service.rs index a217df0bd18..11edb0821e3 100644 --- a/apollo-router/src/services/supergraph/service.rs +++ b/apollo-router/src/services/supergraph/service.rs @@ -40,7 +40,6 @@ use crate::plugins::telemetry::config_new::events::log_event; use crate::plugins::telemetry::config_new::events::SupergraphEventResponse; use crate::plugins::telemetry::consts::QUERY_PLANNING_SPAN_NAME; use crate::plugins::telemetry::tracing::apollo_telemetry::APOLLO_PRIVATE_DURATION_NS; -use crate::plugins::telemetry::Telemetry; use crate::plugins::telemetry::LOGGING_DISPLAY_BODY; use crate::plugins::traffic_shaping::TrafficShaping; use crate::plugins::traffic_shaping::APOLLO_TRAFFIC_SHAPING; @@ -810,9 +809,7 @@ impl PluggableSupergraphServiceBuilder { // Activate the telemetry plugin. // We must NOT fail to go live with the new router from this point as the telemetry plugin activate interacts with globals. for (_, plugin) in self.plugins.iter() { - if let Some(telemetry) = plugin.as_any().downcast_ref::() { - telemetry.activate(); - } + plugin.activate().await; } // We need a non-fallible hook so that once we know we are going live with a pipeline we do final initialization.