Skip to content

Commit

Permalink
fix(subscription): force the deduplication to be enabled by default a…
Browse files Browse the repository at this point in the history
…s it's documented (#3773)

`subscription.enable_deduplication` was documented to be `true` by
default but it wasn't really the case.

---------

Signed-off-by: Benjamin Coenen <[email protected]>
Co-authored-by: Jeremy Lempereur <[email protected]>
  • Loading branch information
bnjjj and o0Ignition0o authored Sep 7, 2023
1 parent 99a26db commit 16a3c8d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .changesets/fix_bnjjj_subscription_default_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### fix(subscription): force the deduplication to be enabled by default as it's documented ([PR #3773](https://github.com/apollographql/router/pull/3773))

A bug was introduced in router v1.25.0 which caused [subscription deduplication](https://www.apollographql.com/docs/router/executing-operations/subscription-support#subscription-deduplication) to be disabled by default.
As documented, the router will enable deduplication by default, providing you with subscriptions that scale.

Should you decide to disable it, you can still explicitly set `enable_deduplication` to `false`.

By [@bnjjj](https://github.com/bnjjj) in https://github.com/apollographql/router/pull/3773
Original file line number Diff line number Diff line change
Expand Up @@ -1641,17 +1641,15 @@ expression: "&schema"
"subscription": {
"description": "Subscriptions configuration",
"type": "object",
"required": [
"enabled"
],
"properties": {
"enable_deduplication": {
"description": "Enable the deduplication of subscription (for example if we detect the exact same request to subgraph we won't open a new websocket to the subgraph in passthrough mode) (default: true)",
"default": false,
"default": true,
"type": "boolean"
},
"enabled": {
"description": "Enable subscription",
"default": true,
"type": "boolean"
},
"max_opened_subscriptions": {
Expand Down
29 changes: 23 additions & 6 deletions apollo-router/src/plugins/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,32 @@ pub(crate) struct Subscription {

/// Subscriptions configuration
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(deny_unknown_fields)]
#[serde(deny_unknown_fields, default)]
pub(crate) struct SubscriptionConfig {
/// Enable subscription
pub(crate) enabled: bool,
/// Select a subscription mode (callback or passthrough)
#[serde(default)]
pub(crate) mode: SubscriptionModeConfig,
/// Enable the deduplication of subscription (for example if we detect the exact same request to subgraph we won't open a new websocket to the subgraph in passthrough mode)
/// (default: true)
#[serde(default)]
#[serde(default = "enable_deduplication_default")]
pub(crate) enable_deduplication: bool,
/// This is a limit to only have maximum X opened subscriptions at the same time. By default if it's not set there is no limit.
#[serde(default)]
pub(crate) max_opened_subscriptions: Option<usize>,
/// It represent the capacity of the in memory queue to know how many events we can keep in a buffer
#[serde(default)]
pub(crate) queue_capacity: Option<usize>,
}

fn enable_deduplication_default() -> bool {
true
}

impl Default for SubscriptionConfig {
fn default() -> Self {
Self {
enabled: true,
mode: Default::default(),
enable_deduplication: true,
enable_deduplication: enable_deduplication_default(),
max_opened_subscriptions: None,
queue_capacity: None,
}
Expand Down Expand Up @@ -1268,6 +1269,22 @@ mod tests {

let subgraph_cfg = config_without_mode.mode.get_subgraph_config("test");
assert_eq!(subgraph_cfg, None);

let sub_config: SubscriptionConfig = serde_json::from_value(serde_json::json!({
"mode": {
"preview_callback": {
"public_url": "http://localhost:4000",
"path": "/subscription/callback",
"subgraphs": ["test"]
}
}
}))
.unwrap();

assert!(sub_config.enabled);
assert!(sub_config.enable_deduplication);
assert!(sub_config.max_opened_subscriptions.is_none());
assert!(sub_config.queue_capacity.is_none());
}
}

Expand Down

0 comments on commit 16a3c8d

Please sign in to comment.