Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove activate() from the plugin API #1569

Merged
merged 3 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ By [@USERNAME](https://github.com/USERNAME) in https://github.com/apollographql/

## ❗ BREAKING ❗

### Remove `activate()` from the plugin API ([PR #1569](https://github.com/apollographql/router/pull/1569))

Recent changes to configuration reloading means that the only known consumer of this API, telemetry, is no longer using it.

Let's remove it since it's simple to add back if later required.

By [@garypen](https://github.com/garypen) in https://github.com/apollographql/router/pull/1569

### QueryPlan::usage_reporting and QueryPlannerContent are private ([Issue #1556](https://github.com/apollographql/router/issues/1556))

These items have been removed from the public API of `apollo_router::services::execution`.
Expand All @@ -36,4 +44,4 @@ By [@SimonSapin](https://github.com/SimonSapin) in https://github.com/apollograp
## 🚀 Features
## 🐛 Fixes
## 🛠 Maintenance
## 📚 Documentation
## 📚 Documentation
13 changes: 0 additions & 13 deletions apollo-router/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ pub trait Plugin: Send + Sync + 'static + Sized {
/// plugins are registered.
async fn new(init: PluginInit<Self::Config>) -> Result<Self, BoxError>;

/// This is invoked after all plugins have been created and we're ready to go live.
/// This method MUST not panic.
fn activate(&mut self) {}

/// This service runs at the very beginning and very end of the request lifecycle.
/// Define supergraph_service if your customization needs to interact at the earliest or latest point possible.
/// For example, this is a good opportunity to perform JWT verification before allowing a request to proceed further.
Expand Down Expand Up @@ -216,10 +212,6 @@ fn get_type_of<T>(_: &T) -> &'static str {
/// For more information about the plugin lifecycle please check this documentation <https://www.apollographql.com/docs/router/customizations/native/#plugin-lifecycle>
#[async_trait]
pub(crate) trait DynPlugin: Send + Sync + 'static {
/// This is invoked after all plugins have been created and we're ready to go live.
/// This method MUST not panic.
fn activate(&mut self);

/// This service runs at the very beginning and very end of the request lifecycle.
/// It's the entrypoint of every requests and also the last hook before sending the response.
/// Define supergraph_service if your customization needs to interact at the earliest or latest point possible.
Expand Down Expand Up @@ -253,11 +245,6 @@ where
T: Plugin,
for<'de> <T as Plugin>::Config: Deserialize<'de>,
{
#[allow(deprecated)]
fn activate(&mut self) {
self.activate()
}

fn supergraph_service(&self, service: supergraph::BoxService) -> supergraph::BoxService {
self.supergraph_service(service)
}
Expand Down
11 changes: 1 addition & 10 deletions apollo-router/src/router_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,7 @@ impl SupergraphServiceConfigurator for YamlSupergraphServiceFactory {
builder = builder.with_dyn_plugin(plugin_name, plugin);
}

// We're good to go with the new service. Let the plugins know that this is about to happen.
// This is needed so that the Telemetry plugin can swap in the new propagator.
// The alternative is that we introduce another service on Plugin that wraps the request
// at a much earlier stage.
for (_, plugin) in builder.plugins_mut() {
tracing::debug!("activating plugin {}", plugin.name());
plugin.activate();
tracing::debug!("activated plugin {}", plugin.name());
}

// We're good to go with the new service.
let pluggable_router_service = builder.build().await?;

Ok(pluggable_router_service)
Expand Down
4 changes: 0 additions & 4 deletions apollo-router/src/services/supergraph_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ impl PluggableSupergraphServiceBuilder {
self
}

pub(crate) fn plugins_mut(&mut self) -> &mut Plugins {
&mut self.plugins
}

pub(crate) async fn build(self) -> Result<RouterCreator, crate::error::ServiceBuildError> {
// Note: The plugins are always applied in reverse, so that the
// fold is applied in the correct sequence. We could reverse
Expand Down
6 changes: 1 addition & 5 deletions docs/source/customizations/native.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ impl Plugin for HelloWorld {
Ok(HelloWorld { configuration: init.config })
}

/// This is invoked after all plugins have been created and we're ready to go live.
/// This method MUST not panic.
fn activate(&mut self);

// Only define the hooks you need to modify. Each default hook
// implementation returns its associated service with no changes.
fn supergraph_service(
Expand Down Expand Up @@ -242,7 +238,7 @@ There is no sequencing for plugin registration, and registrations might even exe

### Activate

When the router is ready to start serving requests, it calls each plugin's `activate` method. Plugins are started in the same order they're declared in your [YAML configuration file](../configuration/overview/#yaml-config-file).
Plugins are started in the same order they're declared in your [YAML configuration file](../configuration/overview/#yaml-config-file).

Note that if a plugin is registered but is _not_ listed in the configuration file, the router does _not_ call `startup` on it. If any plugin fails to start, the router terminates with helpful error messages.

Expand Down