-
Notifications
You must be signed in to change notification settings - Fork 328
feat(limits): add per-subgraph and per-connector response size limits #9160
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
Open
carodewig
wants to merge
20
commits into
dev
Choose a base branch
from
caroline/subgraph-limits
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4c3bb32
feat(limits): add per-subgraph response size limits
carodewig 4ba780d
test: confirm function of into_bytes_limited
carodewig 6c40d57
test: ensure configuration of limits works
carodewig 3fec01f
test: ensure config and body limit work together
carodewig 83554ee
doc: add subgraph response size limits to page
carodewig 0421215
fix: only some errors are due to limit excess
carodewig 86207e6
chore: add metric for when response is aborted
carodewig 3daa5a5
doc: describe using metric to set limit
carodewig 1f86a96
doc: add metric to standard instruments page
carodewig 104b7ff
chore: record reason for stream stop in span
carodewig f7e32cf
doc: add span info to doc
carodewig 18852b1
Revert "doc: add metric to standard instruments page"
carodewig d73f571
feat: implement for connectors as well
carodewig e704446
chore: regenerate schema snapshot for connector limits config
carodewig 34537b4
chore: fmt and lint
carodewig 2a876e7
chore: add changeset for subgraph/connector response size limits
carodewig b76a317
Merge branch 'dev' into caroline/subgraph-limits
carodewig 474014e
test: config migration
carodewig 935a710
docs: apply 8 AI review suggestions across 2 files
apollo-librarian[bot] c136467
Merge branch 'dev' into caroline/subgraph-limits
carodewig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
.changesets/feat_caroline_subgraph_connector_response_size_limits.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ### Add per-subgraph and per-connector HTTP response size limits ([PR #9160](https://github.com/apollographql/router/pull/9160)) | ||
|
|
||
| The router can now cap the number of bytes it reads from subgraph and connector HTTP response bodies, protecting against out-of-memory conditions when a downstream service returns an unexpectedly large payload. | ||
|
|
||
| The limit is enforced as the response body streams in — the router stops reading and returns a GraphQL error as soon as the limit is exceeded, without buffering the full body first. | ||
|
|
||
| Configure a global default and optional per-subgraph or per-source overrides: | ||
|
|
||
| ```yaml | ||
| limits: | ||
| subgraph: | ||
| all: | ||
| http_max_response_bytes: 10485760 # 10 MB for all subgraphs | ||
| subgraphs: | ||
| products: | ||
| http_max_response_bytes: 20971520 # 20 MB override for 'products' | ||
|
|
||
| connector: | ||
| all: | ||
| http_max_response_bytes: 5242880 # 5 MB for all connector sources | ||
| sources: | ||
| products.rest: | ||
| http_max_response_bytes: 10485760 # 10 MB override for 'products.rest' | ||
| ``` | ||
|
|
||
| There is no default limit; responses are unrestricted unless you configure this option. | ||
|
|
||
| When a response is aborted due to the limit, the router: | ||
| - Returns a GraphQL error to the client with extension code `SUBREQUEST_HTTP_ERROR` | ||
| - Increments the `apollo.router.limits.subgraph_response_size.exceeded` or `apollo.router.limits.connector_response_size.exceeded` counter | ||
| - Records `apollo.subgraph.response.aborted: "response_size_limit"` or `apollo.connector.response.aborted: "response_size_limit"` on the relevant span | ||
|
|
||
| **Configuration migration**: Existing `limits` fields (previously at the top level of `limits`) are now nested under `limits.router`. A configuration migration is included that updates your config file automatically. | ||
|
|
||
| By [@carodewig](https://github.com/carodewig) in https://github.com/apollographql/router/pull/9160 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
apollo-router/src/configuration/migrations/2045-limits-router-subgraph.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| description: > | ||
| limits config restructured: existing fields moved under `limits.router`, | ||
| new `limits.subgraph` section added for per-subgraph response size limits. | ||
| actions: | ||
| - type: move | ||
| from: limits.http_max_request_bytes | ||
| to: limits.router.http_max_request_bytes | ||
| - type: move | ||
| from: limits.max_depth | ||
| to: limits.router.max_depth | ||
| - type: move | ||
| from: limits.max_height | ||
| to: limits.router.max_height | ||
| - type: move | ||
| from: limits.max_root_fields | ||
| to: limits.router.max_root_fields | ||
| - type: move | ||
| from: limits.max_aliases | ||
| to: limits.router.max_aliases | ||
| - type: move | ||
| from: limits.warn_only | ||
| to: limits.router.warn_only | ||
| - type: move | ||
| from: limits.parser_max_recursion | ||
| to: limits.router.parser_max_recursion | ||
| - type: move | ||
| from: limits.parser_max_tokens | ||
| to: limits.router.parser_max_tokens | ||
| - type: move | ||
| from: limits.http1_max_request_headers | ||
| to: limits.router.http1_max_request_headers | ||
| - type: move | ||
| from: limits.http1_max_request_buf_size | ||
| to: limits.router.http1_max_request_buf_size | ||
| - type: move | ||
| from: limits.http2_max_headers_list_bytes | ||
| to: limits.router.http2_max_headers_list_bytes | ||
| - type: move | ||
| from: limits.introspection_max_depth | ||
| to: limits.router.introspection_max_depth |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use the friendly
ByteSizeto get something like10mb?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I just cribbed from
router.http_max_request_bytesbut bytesize would be much friendlier.