Repository navigation
test infra: use shared datadog-mock-intake crate and add standalone mock-intake binary
#1392
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
lucaspimentel
wants to merge
12
commits into
main
Choose a base branch
from
lpimentel/mock-intake-consume
base: main
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
12 commits
Select commit
Hold shift + click to select a range
1c4c700
Use shared datadog-mock-intake crate and add standalone fake-intake b…
lucaspimentel 66c1453
Rename the fake-intake binary, feature, and env vars to mock-intake
lucaspimentel f9454a0
Clean up mock-intake env parsing and dev-deps
lucaspimentel 3bac66b
Point mock-intake smoke docs at test-mode PR
lucaspimentel 30add93
Use pipeline_stats_url() in mock-intake startup output
lucaspimentel c777d38
Accept non-UTF-8 paths for MOCK_INTAKE_DUMP_DIR
lucaspimentel dbf46a2
Lint all targets in every GitLab clippy run
lucaspimentel fd6c31b
Rename fake intake references in tests to mock intake
lucaspimentel 463c8b5
Remove orphaned empty tests/common module
lucaspimentel 58dfa65
Move mock-intake detail docs to binary README
lucaspimentel b474a2e
Pin datadog-mock-intake to the merged serverless-components rev
lucaspimentel 68e033e
Simplify mock intake configuration and fixtures
lucaspimentel 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
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
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
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,62 @@ | ||
| # mock-intake | ||
|
|
||
| A standalone mock Datadog APM intake for local APM debugging: a small HTTP server that accepts the same APM endpoints the extension flushes to, decodes the payloads, and reports them locally. | ||
|
|
||
| Built behind the `mock-intake` feature, which is never part of `default` or `fips` production builds: | ||
|
|
||
| ```bash | ||
| cd bottlecap | ||
| cargo build --bin mock-intake --features mock-intake | ||
| ``` | ||
|
|
||
| The binary wraps the shared `datadog-mock-intake` crate from the `serverless-components` repository. The same crate backs the `apm_integration_test` and `dsm_integration_test` integration tests, which run in every test build via a dev-dependency. | ||
|
|
||
| ## Configuration | ||
|
|
||
| | Variable | Default | Meaning | | ||
| |---|---|---| | ||
| | `MOCK_INTAKE_PORT` | `8127` | Loopback listener port; `0` picks a free port (the bound address is printed at startup) | | ||
| | `MOCK_INTAKE_FAIL_STATS_FIRST_N` | `0` | Return HTTP 500 for the first N stats request attempts | | ||
| | `MOCK_INTAKE_DUMP_DIR` | unset | Write one JSON envelope per successfully decoded request into this directory | | ||
|
|
||
| Malformed configuration values cause a clear error and a nonzero exit. Bind failures and dump-directory creation failures are also reported instead of being ignored. | ||
|
|
||
| ## Endpoints and response codes | ||
|
|
||
| - `POST /api/v0.2/stats`: MessagePack `StatsPayload` (gzip, zstd, and identity accepted): `202 Accepted` when stored | ||
| - `POST /api/v0.2/traces`: protobuf `AgentPayload` (gzip, zstd, and identity accepted): `202 Accepted` when stored | ||
| - `POST /api/v0.1/pipeline_stats`: MessagePack DSM pipeline stats: `202 Accepted` when stored | ||
| - Malformed payloads return `400 Bad Request` (unless inside the stats failure-injection window, which returns `500`) | ||
| - Request bodies above the 2 MiB wire-body limit return `413 Payload Too Large` without being decoded | ||
|
|
||
| ## Failure injection semantics | ||
|
|
||
| With `MOCK_INTAKE_FAIL_STATS_FIRST_N=N`, the first N stats *attempts* return 500 and their payloads are not captured by the intake. Attempts are counted per server instance, atomically, so concurrent requests cannot exceed the limit. Rejected attempts are still decoded, summarized, and dumped, so a rejected attempt and its successful retry are each visible with their own status. Trace and DSM requests do not consume the rejection budget. | ||
|
|
||
| ## Request summaries and stats grouping | ||
|
|
||
| Each handled request produces one summary line on stderr (prefix `mock-intake:`) with the request identity, endpoint, content encoding (`identity` when absent), response status, and decoded payload count. For stats requests, hits are grouped by the full aggregation key: client service/env/version plus origin context (hostname, container, tags, git/image metadata, process tags, aggregation mode) and grouped dimensions (service, name, resource, type, DB type, HTTP status, gRPC status, synthetics, span kind, trace-root flag, HTTP method/endpoint, service source, peer tags, deprecated span-derived primary tags, and additional metric tags). Measurements (hits, errors, duration, sketches) and delivery metadata are excluded from the key, so matching dimensions combine across time buckets. Tag lists are sorted in the summary without modifying captured payloads. | ||
|
|
||
| ## JSON dumps | ||
|
|
||
| With `MOCK_INTAKE_DUMP_DIR` set, each successfully decoded request attempt (including rejected stats attempts) writes one JSON file containing the request identity, endpoint, encoding, response status, and decoded payload. Trace payloads are serialized field by field because `AgentPayload` does not implement `Serialize` in `libdd-trace-protobuf` 4.0.1. DSM dumps contain only the fields the crate decodes. Filenames are collision-resistant and never overwrite earlier dumps. | ||
|
|
||
| ## Smoke procedure | ||
|
|
||
| Point the test-mode trace processor at a local mock intake. The `bottlecap-test-mode` binary is added in [#1216](https://github.com/DataDog/datadog-lambda-extension/pull/1216) (not yet merged); build it from a checkout of that branch: | ||
|
|
||
| ```bash | ||
| cd ../<test-mode-worktree>/bottlecap | ||
| cargo build --bin bottlecap-test-mode --features test-mode | ||
|
|
||
| cd ../<this-checkout>/bottlecap | ||
| cargo run --bin mock-intake --features mock-intake | ||
|
|
||
| # in another shell: | ||
| DD_APM_DD_URL=http://127.0.0.1:8127 \ | ||
| DD_LAMBDA_EXTENSION_COMPUTE_STATS=true \ | ||
| DD_SERVICE=mock-intake-smoke DD_ENV=local DD_VERSION=smoke \ | ||
| ./target/debug/bottlecap-test-mode | ||
| ``` | ||
|
|
||
| Unset `DD_SERVERLESS_FLUSH_STRATEGY` so flushing is manual, and make sure no ambient proxy intercepts localhost. Once `GET http://127.0.0.1:8126/info` succeeds, POST a MessagePack trace payload to `/v0.4/traces` (with `X-Datadog-Trace-Count`), then `POST /flush`. The `mock-intake:` summary lines should show the trace request and a stats request whose grouped hits match your spans, and the JSON dumps should contain both payloads. | ||
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.
When a developer follows this smoke procedure,
bottlecap-test-modeis built under<test-mode-worktree>, but the instructions then switch to<this-checkout>and later execute./target/debug/bottlecap-test-modethere, where that artifact was never built. The binary already exists in this commit's parent, so build it from the current checkout and remove the obsolete separate-worktree steps.Useful? React with 👍 / 👎.