Skip to content

Commit

Permalink
FLEET-19 Implement new activate hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanrainer committed Nov 8, 2024
1 parent 51cc5ae commit 2918ce5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 10 additions & 0 deletions apollo-router/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ pub(crate) trait PluginPrivate: Send + Sync + 'static {
fn web_endpoints(&self) -> MultiMap<ListenAddr, Endpoint> {
MultiMap::new()
}

/// This is invoked once after the OTEL meter has been refreshed.
async fn activate(&self) {}
}

#[async_trait]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions apollo-router/src/services/supergraph/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>() {
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.
Expand Down

0 comments on commit 2918ce5

Please sign in to comment.