-
Notifications
You must be signed in to change notification settings - Fork 17
fix(lifecycle): raise axum body limit to 6 MB for large Lambda payloads #1044
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
Merged
+235
−1
Merged
Changes from all commits
Commits
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # No Lambda RIE — runs the extension directly against a minimal mock | ||
| # Extensions API server. Uses amazonlinux:2 to match the build environment | ||
| # (same glibc / library versions as Dockerfile.build-bottlecap). | ||
| FROM --platform=linux/amd64 amazonlinux:2 | ||
|
|
||
| RUN yum install -y curl python3 | ||
|
|
||
| RUN mkdir -p /opt/extensions | ||
| COPY datadog-agent /opt/extensions/datadog-agent | ||
| RUN chmod +x /opt/extensions/datadog-agent | ||
|
|
||
| COPY mock-extensions-api.py /mock-extensions-api.py | ||
| COPY entrypoint.sh /entrypoint.sh | ||
| RUN chmod +x /entrypoint.sh | ||
|
|
||
| # Extension configuration | ||
| ENV DD_API_KEY=fake-key-for-local-test | ||
| ENV DD_APM_DD_URL=http://127.0.0.1:3333 | ||
| ENV DD_DD_URL=http://127.0.0.1:3333 | ||
| ENV DD_TRACE_ENABLED=false | ||
| ENV DD_LOG_LEVEL=DEBUG | ||
|
|
||
| # Point the extension at our mock Lambda Extensions API | ||
| ENV AWS_LAMBDA_RUNTIME_API=127.0.0.1:9001 | ||
| ENV AWS_LAMBDA_FUNCTION_NAME=large-payload-test | ||
| ENV AWS_LAMBDA_FUNCTION_MEMORY_SIZE=512 | ||
| ENV AWS_REGION=us-east-1 | ||
|
|
||
| ENTRYPOINT ["/entrypoint.sh"] |
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,122 @@ | ||
| #!/bin/bash | ||
| # repro-large-payload.sh | ||
| # Reproduces GitHub issue #1041: extension errors on Lambda payloads > 2 MB. | ||
| # | ||
| # Strategy: POST the large payload directly to the extension's | ||
| # /lambda/start-invocation endpoint (port 8124), exactly as the DD Java agent | ||
| # does in production. The extension binds to 127.0.0.1:8124 (loopback only), | ||
| # so we write the payload to a file, docker-cp it into the container, and | ||
| # send the request from inside the container via docker exec. | ||
| # | ||
| # Run from the repo root: | ||
| # bash local_tests/repro-large-payload.sh | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
| IMAGE_NAME="dd-extension-large-payload-repro" | ||
| CONTAINER_ID="" | ||
| LOG_FILE="$SCRIPT_DIR/large-payload-repro.log" | ||
| PAYLOAD_FILE=$(mktemp /tmp/large-payload-XXXXXX.json) | ||
|
|
||
| # 3 MB — above the old 2 MB axum default, below the new 6 MB limit. | ||
| PAYLOAD_CHARS=3200000 | ||
|
|
||
| cleanup() { | ||
| rm -f "$PAYLOAD_FILE" | ||
| if [[ -n "$CONTAINER_ID" ]]; then | ||
| docker logs "$CONTAINER_ID" > "$LOG_FILE" 2>&1 || true | ||
| docker stop "$CONTAINER_ID" > /dev/null 2>&1 || true | ||
| docker rm "$CONTAINER_ID" > /dev/null 2>&1 || true | ||
| fi | ||
| docker rmi "$IMAGE_NAME" > /dev/null 2>&1 || true | ||
| } | ||
| trap cleanup EXIT INT TERM | ||
|
|
||
| # Always rebuild the Linux x86_64 binary from the current source. | ||
| # Mirrors the official AL2 build environment (images/Dockerfile.bottlecap.compile). | ||
| echo "==> Building Linux extension binary (~10-20 min first run, cached after)..." | ||
| rm -f "$SCRIPT_DIR/datadog-agent" | ||
| docker build \ | ||
| --platform linux/amd64 \ | ||
| -f "$SCRIPT_DIR/Dockerfile.build-bottlecap" \ | ||
| -t dd-bottlecap-builder \ | ||
| "$REPO_ROOT" | ||
| cid=$(docker create dd-bottlecap-builder) | ||
| docker cp "$cid:/bottlecap" "$SCRIPT_DIR/datadog-agent" | ||
| docker rm "$cid" > /dev/null | ||
| docker rmi dd-bottlecap-builder > /dev/null 2>&1 || true | ||
| chmod +x "$SCRIPT_DIR/datadog-agent" | ||
|
|
||
| echo "==> Building test image..." | ||
| docker build \ | ||
| --no-cache \ | ||
| --platform linux/amd64 \ | ||
| -f "$SCRIPT_DIR/Dockerfile.LargePayload" \ | ||
| -t "$IMAGE_NAME" \ | ||
| "$SCRIPT_DIR" | ||
|
|
||
| echo "==> Starting container..." | ||
| CONTAINER_ID=$(docker run -d --platform linux/amd64 "$IMAGE_NAME") | ||
|
|
||
| echo "==> Waiting for extension to bind port 8124..." | ||
| READY=false | ||
| for _ in $(seq 1 30); do | ||
| if ! docker inspect "$CONTAINER_ID" --format='{{.State.Running}}' 2>/dev/null | grep -q "true"; then | ||
| echo "ERROR: Container exited during init. Logs:" | ||
| docker logs "$CONTAINER_ID" 2>&1 | tail -30 | ||
| exit 1 | ||
| fi | ||
| if docker exec "$CONTAINER_ID" \ | ||
| curl -sf -o /dev/null \ | ||
| -X POST "http://localhost:8124/lambda/start-invocation" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{}' --max-time 2 2>/dev/null; then | ||
| READY=true | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
|
|
||
| if [[ "$READY" != "true" ]]; then | ||
| echo "ERROR: Extension did not become ready after 30s. Logs:" | ||
| docker logs "$CONTAINER_ID" 2>&1 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "==> Sending ~3 MB payload to /lambda/start-invocation..." | ||
| python3 -c " | ||
| import json | ||
| payload = {'description': 'Large payload repro for GitHub issue #1041', 'data': 'x' * $PAYLOAD_CHARS} | ||
| print(json.dumps(payload)) | ||
| " > "$PAYLOAD_FILE" | ||
|
|
||
| PAYLOAD_SIZE=$(wc -c < "$PAYLOAD_FILE") | ||
| docker cp "$PAYLOAD_FILE" "$CONTAINER_ID:/tmp/large-payload.json" | ||
|
|
||
| HTTP_CODE=$(docker exec "$CONTAINER_ID" \ | ||
| curl -s -o /dev/null -w "%{http_code}" \ | ||
| -X POST "http://localhost:8124/lambda/start-invocation" \ | ||
| -H "Content-Type: application/json" \ | ||
| -H "lambda-runtime-aws-request-id: test-large-payload-request" \ | ||
| -H "datadog-meta-lang: java" \ | ||
| --data-binary "@/tmp/large-payload.json" \ | ||
| --max-time 15) || HTTP_CODE="error" | ||
| sleep 1 | ||
|
|
||
| ERRORS=$(docker logs "$CONTAINER_ID" 2>&1 | grep -E "length limit|extract request body" || true) | ||
|
|
||
| echo "" | ||
| echo "────────────────────────────────────────────────────────────" | ||
| if [[ -n "$ERRORS" ]]; then | ||
| echo "RESULT: BUG REPRODUCED (fix not applied or not working)" | ||
| echo "" | ||
| echo "$ERRORS" | ||
| else | ||
| echo "RESULT: OK — no 'length limit exceeded' error (fix is working)" | ||
| echo " HTTP $HTTP_CODE returned for a ${PAYLOAD_SIZE}-byte payload" | ||
| fi | ||
| echo "────────────────────────────────────────────────────────────" | ||
| echo "" | ||
| echo "Full logs saved to: $LOG_FILE" |
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.
Wondering how would this look like with streaming lambda payload... do we have guards to not send the payload if it goes over the limit?
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.
Because in streaming the max is 200MB
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.
I mean good for now, but we might want to leave a comment about streaming