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

Add OTEL information for operation limits #5884

Merged
merged 5 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changesets/docs_feature_operationlimitsotel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Add OTEL information for operation limits ([PR #5884](https://github.com/apollographql/router/pull/5884))

Add OTEL information for operation limits to docs.
andrewmcgivery marked this conversation as resolved.
Show resolved Hide resolved

By [@andrewmcgivery](https://github.com/andrewmcgivery) in https://github.com/apollographql/router/pull/5884
86 changes: 86 additions & 0 deletions docs/source/configuration/operation-limits.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ limits:
Each limit takes an integer value. You can define any combination of [supported limits](#supported-limits).

## Supported limits

### `max_depth`

Limits the deepest nesting of selection sets in an operation, including fields in fragments.
Expand Down Expand Up @@ -143,3 +144,88 @@ Whenever your router rejects a request because it exceeds an operation limit, th
```

If you run your router in [`warn_only` mode](#warn_only-mode), the router logs the limit violation but executes the operation as normal, returning a 200 status code with the expected response.

## Measuring for appropriate values with telemetry
andrewmcgivery marked this conversation as resolved.
Show resolved Hide resolved

It may be difficult to decide what values to set for operation limits if you have a large number of existing operations. A good option to help make this decision is to measure incoming operations for a set period of time and then use the resulting data as a baseline for your configuration.
andrewmcgivery marked this conversation as resolved.
Show resolved Hide resolved

### Logging values

You can configure the Router with a [custom event](https://www.apollographql.com/docs/router/configuration/telemetry/instrumentation/events#custom-events) to log the values of aliases, depth, height, and root_fields on each operation with the following configuration:
andrewmcgivery marked this conversation as resolved.
Show resolved Hide resolved

```
andrewmcgivery marked this conversation as resolved.
Show resolved Hide resolved
telemetry:
instrumentation:
events:
supergraph:
OPERATION_LIMIT_INFO:
message: operation limit info
on: response
level: info
attributes:
graphql.operation.name: true
query.aliases:
query: aliases
query.depth:
query: depth
query.height:
query: height
query.root_fields:
query: root_fields
```

This may not be a good model for a large amount of traffic so it may be preferred to instead collect metrics and export them to your APM.
andrewmcgivery marked this conversation as resolved.
Show resolved Hide resolved

### Collecting metrics

You can configure the Router to collect [custom metrics](/router/configuration/telemetry/instrumentation/instruments#custom-instruments) on the values of aliases, depth, height, and root_fields on each operation with the following configuration:
andrewmcgivery marked this conversation as resolved.
Show resolved Hide resolved

```
andrewmcgivery marked this conversation as resolved.
Show resolved Hide resolved
telemetry:
exporters:
metrics:
common:
views:
# Define a custom view because operation limits are different than the default latency-oriented view of OpenTelemetry
- name: oplimits.*
aggregation:
histogram:
buckets:
- 0
- 5
- 10
- 25
- 50
- 100
- 500
- 1000
instrumentation:
instruments:
supergraph:
oplimits.aliases:
value:
query: aliases
type: histogram
unit: number
description: "Aliases for an operation"
oplimits.depth:
value:
query: depth
type: histogram
unit: number
description: "Depth for an operation"
oplimits.height:
value:
query: height
type: histogram
unit: number
description: "Height for an operation"
oplimits.root_fields:
value:
query: root_fields
type: histogram
unit: number
description: "Root fields for an operation"
```

You should also configure the Router to [export metrics](/router/configuration/telemetry/exporters/metrics/overview) to your APM tool.
andrewmcgivery marked this conversation as resolved.
Show resolved Hide resolved
Loading