Skip to content

Commit e8b2acc

Browse files
authored
ref(server): Move from actix-web to axum (#1938)
Replaces `actix-web` with `axum` in the web endpoint layer and upgrades related dependencies. ## Motivation Relay has used `actix-web` as web framework. Due to a failed upgrade attempts in the past, Relay has remained on a version from 2018, which relies on outdated dependencies and predates modern language features such as `Futures` in the standard library. As such, the development experience has been suboptimal. Most importantly, however, some of the dependencies required by actix-web contain vulnerabilities or are unmaintained and advised against at this point. The latest version (4.3.1) of `actix-web` supports standard futures and has added support for the stable version of `tokio`, the async runtime. However, the differences between these versions are large enough to consider other web frameworks. The community currently prefers `axum`, which is developed closer to the `tokio` project and provides quicker upgrade paths on more recent tokio versions. Additionally, `axum` is a relatively thin routing layer built on top of `hyper`, which is already used inside `reqwest` as our HTTP client for outbound requests. Additionally, `axum` is built on top of `tower`, a composable service library with wide-spread community support offering building blocks for common HTTP functionality. ## Details Actix-web required a proprietary system executor built on top of an older version of the `tokio` runtime. It runs a central accept loop and an additional thread pool to handle web requests. This system has been removed. Web requests are now handled within the main executor. Similar to actix-web, axum offers handler functions for endpoints and extractors to resolve structured information from web requests. Changes to the prior implementation include: - The maximum body size is no longer checked directly in the extractor or endpoint implementation. Instead, this is now handled via a body size limit middleware. - The server no longer consumes request bodies if the request is terminated early. This can be expanded to more cases in follow-ups to speed up request handling. Hyper offers low-level SSL utilities. Achieving SSL support via `native-tls` is slightly more involving, and we are not yet ready to move to `rustls`. Since the best practices in operating guidelines require to use a reverse proxy in front of Relay, we're dropping native SSL support. Outbound HTTPS support and TLS for redis and kafka are now enabled by default. As part of this migration, we're embracing extraction more than before. Instead of functional utilities, many inputs to endpoint handlers composed from and written as extractors, which reduces endpoints to a minimal set of processing logic, mostly delegating to services. Axum's router is less capable than actix-web. Most notably, endpoints that used to fall back to forwarding now need to handle forwarding explicitly. For this reason, the forward endpoint is written as a function that can be called directly on a request for convenience. Other differences are minor, for instance that non-numeric project IDs are now reported as error instead of 404. ## Dependencies Since the actix-web framework was the last dependency to rely on `failure`, `futures 0.1` and `bytes 0.4`, these dependencies have now been removed from the dependency tree. This also resolves outstanding security issues and ensures Relay continues to build with upcoming compiler releases. ## Performance Impact Performance was tested using the load testing infrastructure. CPU usage is similar to the actix-web baseline, usually even faster. Same for request roundtrip times. Memory consumption is 20% less. Note that most of Relay's resource consumption occurs outside of HTTP request handling, either in endpoint logic or internal services. ## Breaking Changes Configuration: - SSL support has been dropped. As per [official guidelines](https://docs.sentry.io/product/relay/operating-guidelines/), Relay should be operated behind a reverse proxy, which can perform SSL termination. - Connection config options `max_connections`, `max_pending_connections`, and `max_connection_rate` no longer have an effect. Instead, configure the reverse proxy to handle connection concurrency as needed. Endpoints: - The security endpoint no longer forwards to upstream if the mime type doesn't match supported mime types. Instead, the request is rejected with a corresponding error. - Passing store payloads as `?sentry_data=<base64>` query parameter is restricted to `GET` requests on the store endpoint. Other endpoints require the payload to be passed in the request body. - Requests with an invalid `content-encoding` header will now be rejected. Exceptions to this are an empty string and `UTF-8`, which have been sent historically by some SDKs and are now treated as identity (no encoding). Previously, all unknown encodings were treated as identity. - Temporarily, response bodies for some errors are rendered as plain text instead of JSON. This will be addressed in an upcoming release. Metrics: - The `route` tag of request metrics uses the route pattern instead of schematic names. There is an exact replacement for every previous route. For example, `"store-default"` is now tagged as `"/api/:project_id/store/"`. - Statsd metrics `event.size_bytes.raw` and `event.size_bytes.uncompressed` have been removed.
1 parent dac9b06 commit e8b2acc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2205
-3973
lines changed

.github/workflows/build_binary.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
run: scripts/docker-build-linux.sh
2323
env:
2424
BUILD_ARCH: x86_64
25-
RELAY_FEATURES: ssl
25+
RELAY_FEATURES:
2626

2727
- name: Bundle Debug File
2828
run: |

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ jobs:
113113

114114
- name: Run Cargo Tests
115115
run: cargo test --workspace
116-
env:
117-
RUSTFLAGS: -Dwarnings
118116

119117
test_all:
120118
timeout-minutes: 15

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,31 @@
22

33
## Unreleased
44

5-
**Features**
5+
**Breaking Changes**:
6+
7+
This release contains major changes to the web layer, including TCP and HTTP handling as well as all web endpoint handlers. Due to these changes, some functionality was retired and Relay responds differently in specific cases.
8+
9+
Configuration:
10+
- SSL support has been dropped. As per [official guidelines](https://docs.sentry.io/product/relay/operating-guidelines/), Relay should be operated behind a reverse proxy, which can perform SSL termination.
11+
- Connection config options `max_connections`, `max_pending_connections`, and `max_connection_rate` no longer have an effect. Instead, configure the reverse proxy to handle connection concurrency as needed.
12+
13+
Endpoints:
14+
- The security endpoint no longer forwards to upstream if the mime type doesn't match supported mime types. Instead, the request is rejected with a corresponding error.
15+
- Passing store payloads as `?sentry_data=<base64>` query parameter is restricted to `GET` requests on the store endpoint. Other endpoints require the payload to be passed in the request body.
16+
- Requests with an invalid `content-encoding` header will now be rejected. Exceptions to this are an empty string and `UTF-8`, which have been sent historically by some SDKs and are now treated as identity (no encoding). Previously, all unknown encodings were treated as identity.
17+
- Temporarily, response bodies for some errors are rendered as plain text instead of JSON. This will be addressed in an upcoming release.
18+
19+
Metrics:
20+
- The `route` tag of request metrics uses the route pattern instead of schematic names. There is an exact replacement for every previous route. For example, `"store-default"` is now tagged as `"/api/:project_id/store/"`.
21+
- Statsd metrics `event.size_bytes.raw` and `event.size_bytes.uncompressed` have been removed.
22+
23+
**Features**:
624

725
- Allow monitor checkins to paass `monitor_config` for monitor upserts. ([#1962](https://github.com/getsentry/relay/pull/1962))
826

927
**Internal**:
1028

29+
- Upgrade the web framework and related dependencies. ([#1938](https://github.com/getsentry/relay/pull/1938))
1130
- Apply transaction clustering rules before UUID scrubbing rules. ([#1964](https://github.com/getsentry/relay/pull/1964))
1231

1332
## 23.3.1

0 commit comments

Comments
 (0)