Skip to content
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
25 changes: 25 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ By [@USERNAME](https://github.com/USERNAME) in https://github.com/apollographql/

## ❗ BREAKING ❗

### Rename traffic shaping deduplication options ([PR #1540](https://github.com/apollographql/router/pull/1540))

In the traffic shaping module:
- `variables_deduplication` configuration option is renamed to `deduplicate_variables`.
- `query_deduplication` configuration option is renamed to `deduplicate_query`.

```diff
- traffic_shaping:
- variables_deduplication: true # Enable the variables deduplication optimization
- all:
- query_deduplication: true # Enable query deduplication for all subgraphs.
- subgraphs:
- products:
- query_deduplication: false # Disable query deduplication for products.
+ traffic_shaping:
+ deduplicate_variables: true # Enable the variables deduplication optimization
+ all:
+ deduplicate_query: true # Enable query deduplication for all subgraphs.
+ subgraphs:
+ products:
+ deduplicate_query: false # Disable query deduplication for products.
```

By [@garypen](https://github.com/garypen)

### Put `query_plan_options` in private and wrap `QueryPlanContent` in an opaque type ([PR #1486](https://github.com/apollographql/router/pull/1486))

`QueryPlanOptions::query_plan_options` is no longer available in public.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: apollo-router/src/configuration/mod.rs
assertion_line: 909
expression: "&schema"
---
{
Expand Down Expand Up @@ -1884,6 +1883,11 @@ expression: "&schema"
],
"nullable": true
},
"deduplicate_query": {
"description": "Enable query deduplication",
"type": "boolean",
"nullable": true
},
"global_rate_limit": {
"description": "Enable global rate limiting",
"type": "object",
Expand All @@ -1906,11 +1910,6 @@ expression: "&schema"
"additionalProperties": false,
"nullable": true
},
"query_deduplication": {
"description": "Enable query deduplication",
"type": "boolean",
"nullable": true
},
"timeout": {
"description": "Enable timeout for incoming requests",
"default": null,
Expand All @@ -1920,6 +1919,11 @@ expression: "&schema"
"additionalProperties": false,
"nullable": true
},
"deduplicate_variables": {
"description": "Enable variable deduplication optimization when sending requests to subgraphs (https://github.com/apollographql/router/issues/87)",
"type": "boolean",
"nullable": true
},
"router": {
"description": "Applied at the router level",
"type": "object",
Expand Down Expand Up @@ -1971,6 +1975,11 @@ expression: "&schema"
],
"nullable": true
},
"deduplicate_query": {
"description": "Enable query deduplication",
"type": "boolean",
"nullable": true
},
"global_rate_limit": {
"description": "Enable global rate limiting",
"type": "object",
Expand All @@ -1993,11 +2002,6 @@ expression: "&schema"
"additionalProperties": false,
"nullable": true
},
"query_deduplication": {
"description": "Enable query deduplication",
"type": "boolean",
"nullable": true
},
"timeout": {
"description": "Enable timeout for incoming requests",
"default": null,
Expand All @@ -2006,11 +2010,6 @@ expression: "&schema"
},
"additionalProperties": false
}
},
"variables_deduplication": {
"description": "Enable variable deduplication optimization when sending requests to subgraphs (https://github.com/apollographql/router/issues/87)",
"type": "boolean",
"nullable": true
}
},
"additionalProperties": false
Expand Down
18 changes: 9 additions & 9 deletions apollo-router/src/plugins/traffic_shaping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trait Merge {
#[serde(deny_unknown_fields)]
struct Shaping {
/// Enable query deduplication
query_deduplication: Option<bool>,
deduplicate_query: Option<bool>,
/// Enable compression for subgraphs (available compressions are deflate, br, gzip)
compression: Option<Compression>,
/// Enable global rate limiting
Expand All @@ -69,7 +69,7 @@ impl Merge for Shaping {
match fallback {
None => self.clone(),
Some(fallback) => Shaping {
query_deduplication: self.query_deduplication.or(fallback.query_deduplication),
deduplicate_query: self.deduplicate_query.or(fallback.deduplicate_query),
compression: self.compression.or(fallback.compression),
timeout: self.timeout.or(fallback.timeout),
global_rate_limit: self
Expand Down Expand Up @@ -106,7 +106,7 @@ struct Config {
/// Applied on specific subgraphs
subgraphs: HashMap<String, Shaping>,
/// Enable variable deduplication optimization when sending requests to subgraphs (https://github.com/apollographql/router/issues/87)
variables_deduplication: Option<bool>,
deduplicate_variables: Option<bool>,
}

#[derive(PartialEq, Debug, Clone, Deserialize, JsonSchema)]
Expand Down Expand Up @@ -205,7 +205,7 @@ impl Plugin for TrafficShaping {
.clone()
});
ServiceBuilder::new()
.option_layer(config.query_deduplication.unwrap_or_default().then(|| {
.option_layer(config.deduplicate_query.unwrap_or_default().then(|| {
// Buffer is required because dedup layer requires a clone service.
ServiceBuilder::new()
.layer(QueryDeduplicationLayer::default())
Expand Down Expand Up @@ -237,10 +237,10 @@ impl Plugin for TrafficShaping {
&self,
service: query_planner::BoxService,
) -> query_planner::BoxService {
if matches!(self.config.variables_deduplication, Some(true)) {
if matches!(self.config.deduplicate_variables, Some(true)) {
service
.map_request(|mut req: QueryPlannerRequest| {
req.query_plan_options.enable_variable_deduplication = true;
req.query_plan_options.enable_deduplicate_variables = true;
req
})
.boxed()
Expand Down Expand Up @@ -381,7 +381,7 @@ mod test {
async fn it_returns_valid_response_for_deduplicated_variables() {
let config = serde_yaml::from_str::<serde_json::Value>(
r#"
variables_deduplication: true
deduplicate_variables: true
"#,
)
.unwrap();
Expand Down Expand Up @@ -436,10 +436,10 @@ mod test {
let config = serde_yaml::from_str::<Config>(
r#"
all:
query_deduplication: true
deduplicate_query: true
subgraphs:
products:
query_deduplication: false
deduplicate_query: false
"#,
)
.unwrap();
Expand Down
8 changes: 4 additions & 4 deletions apollo-router/src/query_planner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod selection;
#[derive(Clone, Eq, Hash, PartialEq, Debug, Default)]
pub(crate) struct QueryPlanOptions {
/// Enable the variable deduplication optimization on the QueryPlan
pub(crate) enable_variable_deduplication: bool,
pub(crate) enable_deduplicate_variables: bool,
}

/// A planner key.
Expand Down Expand Up @@ -811,7 +811,7 @@ pub(crate) mod fetch {
current_dir: &Path,
request: &Arc<http_ext::Request<Request>>,
schema: &Schema,
enable_variable_deduplication: bool,
enable_deduplicate_variables: bool,
) -> Option<Variables> {
let body = request.body();
if !requires.is_empty() {
Expand All @@ -824,7 +824,7 @@ pub(crate) mod fetch {
}));

let mut paths: HashMap<Path, usize> = HashMap::new();
let (paths, representations) = if enable_variable_deduplication {
let (paths, representations) = if enable_deduplicate_variables {
let mut values: IndexSet<Value> = IndexSet::new();
data.select_values_and_paths(current_dir, |path, value| {
if let Value::Object(content) = value {
Expand Down Expand Up @@ -924,7 +924,7 @@ pub(crate) mod fetch {
// Needs the original request here
parameters.originating_request,
parameters.schema,
parameters.options.enable_variable_deduplication,
parameters.options.enable_deduplicate_variables,
)
.await
{
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions docs/source/configuration/traffic-shaping.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ To enable traffic shaping, add the `traffic_shaping` plugin to your [YAML config

```yaml title="router.yaml"
traffic_shaping:
variables_deduplication: true # Enable the variable deduplication optimization.
deduplicate_variables: true # Enable the variable deduplication optimization.
router: # Rules applied to requests from clients to the router
global_rate_limit: # Accept a maximum of 10 requests per 5 secs. Excess requests must be rejected.
capacity: 10
interval: 5s # Must not be greater than 18_446_744_073_709_551_615 milliseconds and not less than 0 milliseconds
timeout: 50s # If a request to the router takes more than 50secs then cancel the request (30 sec by default)
all:
query_deduplication: true # Enable query deduplication for all subgraphs.
deduplicate_query: true # Enable query deduplication for all subgraphs.
compression: br # Enable brotli compression for all subgraphs.
subgraphs: # Rules applied to requests from the router to individual subgraphs
products:
query_deduplication: false # Disable query for the products subgraph.
deduplicate_query: false # Disable query deduplication for the products subgraph.
compression: gzip # Enable gzip compression only for the products subgraph.
global_rate_limit: # Accept a maximum of 10 requests per 5 secs from the router. Excess requests must be rejected.
capacity: 10
Expand Down