Repository navigation
feat: process OTLP requests in bounded chunks - #158
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…re built (red) Ports the measurements of the budget review as assertions, with a per-thread test allocator (moved out of strict.rs; a reallocation now counts the old and the new block at its peak). Each case must stay under one chunk of rows (2 x 16 MiB + 8 MiB), which no longer grows with the rows of the request: - the events, the links of one span and the data points of one gauge (131,072 / 65,536 / 131,072 empty children); - 1000 tiny resource attributes copied into 2000 rows; - a 10 MiB log body of JSON text, parsed before anything was charged; - 3,600 exemplars with distinct keys, whose column table holds 13M null cells; - maps sized by the raw count of attributes without a value. All fail on this commit; the following commits turn them green. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ded chunks The flatteners built every row of a request (and every event, link and data point row of one span or metric) before handing any over. They now hand each row to a RowSink as soon as it is built; shared resource, scope, span and metric fields are still built once per parent, and rows are byte-identical (bench digests unchanged). The Vec-returning functions remain as wrappers. A Chunker collects rows into chunks of at most 8192 rows or 16 MiB of estimated row memory and passes each full chunk on before the next is built. row_bytes estimates Value memory (128 B per map entry, 72 B per Value, string capacities plus 16 B per heap block, and the null cells structural flattening adds for arrays of objects), not JSON length: allocated/estimated is 1.02 for realistic rows and 1.25 for rows of 1000 tiny fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s after a client error Both encodings now flatten into a Chunker whose chunks are staged through the push_logs path; all chunks of a request share one stream lookup and one p_timestamp, and read the stream schema afresh. A request that fits one chunk is staged exactly as before. A sizing pass over the decoded message counts records, data points and rows without building them. Before any chunk is staged, errors are returned as before. After one was: a client error (4xx: schema conflict, field limit, flatten limit) returns 200 with the OTLP partial_success message in the request's encoding (rejected_log_records / rejected_data_points / rejected_spans = records not staged in full); a server error keeps its 5xx, and as the exporter then retries the whole request, the chunks already staged are staged twice. The *_collected counters count what was staged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the payload limit Chunking bounds memory, not what a request writes to staging: 500 resource attributes over 262,144 empty records (0.5 MiB) expand to 23.7 GiB of rows. The sizing pass now refuses, with 400 and before anything is staged, a request whose estimated rows exceed 1024 x P_MAX_EVENT_PAYLOAD_SIZE (10 GiB at the default). Realistic requests at the payload limit expand to at most 459x (short log records or bare gauge points under 30 Kubernetes resource attributes); every measured shape is accepted (realistic_tests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e values inserted Data point, exemplar, metadata and resource maps of metrics, the temporary maps of flatten_attributes and key-value lists, and the Vec of array values were sized by the raw count of entries in the request, including entries without a value (two bytes each on the wire, skipped when rows are built). 50,000 of them reserved about 5.5 MB per map. They are now sized like attribute_capacity: entries with a value, capped at 128. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…re parsing it
Bodies were parsed into Values before anything was charged: a 10 MiB body
{"a":[0,0,...]} peaked at 586 MiB. Text that could parse into more than what
is left of 64 MiB (four chunks) for the record is first scanned without
allocating, which yields its type and the memory parsing takes; text that is
not an object is no longer parsed at all (its parse was discarded anyway),
and an object that would take more is refused (LogBodyTooLarge, a 400 limit
error). Typical JSON parses into about 8 bytes per byte, so bodies of several
MiB are still accepted; small bodies take the old path unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f objects Structural flattening turns an array of objects into one column per distinct key with a cell for every element, null where an element lacks the key; each null is a 72-byte Value. 3,600 exemplars with distinct keys held 13M of them, 890 MiB. The elements are now flattened first, and the null cells are charged to the request's flatten budget at 72 bytes each before the columns are built, so such a table is refused at the 64 MiB default. flatten() takes the budget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…0 MiB requests An ignored test, run alone on a release build, that decodes a request and hands its rows over in chunks, printing the resident memory decoding takes and the peak (VmHWM, reset through clear_refs) over the whole: the review's two worst cases and a 10 MiB Kubernetes-attributed request per signal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…test-only import Clippy: type_complexity in memory_tests.rs, and JsonFlattenError imported by ingest_utils.rs only for a cfg(test) function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The request, resource and scope levels are small prost::Message impls that prost itself drives, so keys, wire-type checks, the recursion limit, unknown fields and error paths are prost's. Their singular fields (resource, scope, schema_url) are merged as prost merges them; their repeated children are kept as offsets into the body (zero-copy) with the DecodeContext prost would use, and decoded once the level is read whole, from the rest of the body as prost decodes them. A leaf record (LogRecord, Span, Metric) is decoded on its own with message::merge and handed to the stage-1 flatteners, then dropped. Each record's decoded size is estimated without allocating (decoded_size.rs, from the budget-opus branch, trimmed to leaf records) and a record over 16 x P_MAX_EVENT_PAYLOAD_SIZE is refused (400) before it is decoded. The body is read twice: a sizing pass (expansion cap, record totals), then the staged pass. A body that does not decode is refused before anything is staged, with the error whole-request decoding gives: on a decode error the sizing pass re-reads the body in wire order (first_error) to report the break prost meets first. JSON requests are still decoded whole. Differential properties against whole-request decoding: rows byte-identical for bodies re-encoded with shuffled fields, split singular fields, replaced schema_url and unknown fields of every wire type; identical errors for truncated and byte-damaged bodies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g the configuration The protobuf path read P_MAX_EVENT_PAYLOAD_SIZE and the exemplar option before decoding, so a garbage body no longer failed before the global configuration was touched (test_process_otel_content_protobuf_variants_reach_protobuf_decoding then exited the unfiltered test run). The request level is now checked first, with prost's error, and the options are read after. Imports that only the test-only whole-request decoder uses are cfg(test). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ws as they are staged The sizing pass is gone, for both encodings. It decoded every protobuf record once to total the request's rows and refuse it whole above the expansion cap, then the staging pass decoded every record again (+3-6 % instructions per realistic request; one span of 2 million empty events was held twice). - Expansion cap: a running total of the estimated row bytes (`row_bytes`) of the chunks handed to staging; the chunk that would pass 1024x the payload limit is refused like any other client error, so after staging began it is a partial success, the same in both encodings. `src/otel/expansion.rs` is removed; the factor lives with the chunker. - Protobuf: `outline` walks the request, resource and scope levels without decoding a record (a body broken there is still refused with prost's exact text before anything is staged, and before the configuration is read for a body with no record), then every leaf record is decoded once. A record that does not decode or is over the decoded-size cap, met after chunks were staged, is a partial success. - Rejected counts stay exact without costing the success path: log records and spans are counted by the outline; data points are read from the wire only after a failure (`metric_points`, following prost's oneof merging), an undecodable metric counted up to its break. - The decoded-size scan runs only on records long enough to reach the cap: at most 128 (log records), 208 (spans) or 416 (metrics) estimated bytes per wire byte beyond the record's struct, twice the largest repeated element, with the argument in `bytes_per_wire_byte` and crafted and random checks. - Differential properties follow the new semantics: decode whole and stream alike, or stream the rows of the records before the first that prost can not decode (checked against a shallow decoding of the levels above the records), or refuse with nothing staged when those levels are broken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only records long enough to reach the cap are scanned now, but a 10 MiB metric still is, and the scan cost it +1.0 % instructions over stage 1 end to end. One-byte varints (keys, lengths) take a fast path, a string's capacity is computed directly, and a message without a repeated field adds no `Vec`s: the same estimate, +0.64 % for that request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resource, scope, span and metric maps are sized from the attribute count, which counts repeated keys, and IndexMap::clone keeps the capacity. A scope of 128 attributes with one key made every row cloned from it hold 25,956 B while row_bytes counted 2,828 B, and a 1.25 MiB request peaked at 159 MiB. When attributes make fewer entries than were counted, the map is now rebuilt with room for that many fewer; distinct keys rebuild nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne chunk A JSON text body was parsed when its parse was estimated under 64 MiB (a 3 MiB body of 241,980 fields was accepted and peaked at 180 MiB), and a body estimated over it refused its record with LogBodyTooLarge (450,000 fields, which b8c7d979 accepted). Now at most one chunk's worth (16 MiB) of parsed memory is allowed per record; a body over it is not parsed and is kept as its text, as text that is not JSON is. Nothing is refused for this any more, so LogBodyTooLarge is removed. The scan before parsing estimated under 64 MiB for 400,000 fields whose parse held 74.5 MiB. It now counts the table and entries an IndexMap grows to, the capacity a Vec doubles to (at least 4), the old block of the last growth, and the scratch buffer escaped strings are unescaped into; checked against the allocator for 28 shapes (estimate/peak 1.00-1.95). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… stream
Three changes to staging one OTLP request:
- The expansion cap was 1024 x P_MAX_EVENT_PAYLOAD_SIZE (10 GiB) for any
body, so a 45 KB body staged 460 MB of rows. It is now 4096 x the
length of the decompressed body, at least one chunk (16 MiB). The 15
realistic shapes at the payload limit stay under it with at least 8x
headroom (worst 458 row bytes per body byte), and so do the same
shapes with 1, 10 and 100 records.
- An empty request (an empty protobuf body, or `{}` for JSON) is answered
200 without the stream. The dataset field check counts a missing
stream as having no fields; staging a request that has rows still
needs the stream (404). `{}` was refused by serde before, and an empty
request to a missing stream got 404 at b8c7d979 too.
- For OTLP JSON the dataset field count is checked before the body is
decoded into a request, as at b8c7d979.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The security review found the request, resource and scope levels indexed before the first was read: a 10 MiB body of 5.2 million empty two-byte resource_logs entries held 384 MiB. At f0f75899 they are already walked as they are read; this pins it for empty resources and for empty scopes of one resource, for all three signals, in outline, flatten_request and count_points (peak at most 1.8 KB). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… staged OTLP/HTTP exporters retry only 429, 502, 503 and 504. A 500 is permanent: the staged chunks stay and the client counts the batch as failed. Only a 503 makes the client send the whole request again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s schema Each chunk of a request is staged as its own event and typed against the schema the chunk before it committed, so a value whose type changes between records of a request cut into several chunks can land in a differently named column than one batch would put it in, exactly as two separate requests would. Pinned with the reviewer's two cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in full The security review found the sizing pass charged job and instance at 32 bytes each while they copy service.name and service.instance.id. There is no sizing pass any more: the running total is the row_bytes of the staged rows, labels included. With a 64 KiB service.name each row counts 133,889 bytes and the request stops at the cap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bench digests and the JSON-versus-protobuf properties cannot show that a flattener change keeps rows identical: the bench covers one request shape, and both sides of the properties run the same flattener. This corpus generates 3000 requests per signal from a fixed SplitMix64 seed, every timestamp set, and pins one digest per signal over the rows serialised in order (key order included, since it decides column order). The generator covers attribute keys that collide with the fixed row fields of all three signals and with each other across resource, scope, record, event, link and data point; one key repeated many times in a list; attributes without a value; string, bool, int, double (including 1e20, -0.0, NaN, infinity), bytes (invalid UTF-8 too), arrays and key-value lists, nested three deep; missing and empty resources and scopes; log bodies of every kind including JSON text; every metric type, exemplars and metadata, a metric with data but no points; spans with up to 80 events and 40 links. Metrics are flattened with and without exemplar flattening. Digests at this commit: logs 13,819 rows 5247f2af863c6427, metrics 42,718 rows b299fcc3bdad0047, traces 65,400 rows 2f813bb532c511a5. Each of these mutations changed the digests it should, so the corpus reaches them: resource fields not overriding a log record's fields, span fields not overriding an event's, metric metadata not overriding a data point's (all three digests); the first of repeated attribute keys winning (all three); a double label hashed with Rust's float formatting (metrics). DST_SEED and DST_ITERS change the corpus; the digests are checked only for the defaults. The tests do not touch PARSEABLE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bytes The repeated-keys regression test covered the maps that are cloned into rows (resource, scope, span, metric metadata). Add the maps that are rows themselves: a log record's own fields, a span event, a span link and a metric data point, each with 128 attributes of one key. Measured at 98ae3903 (held/estimated): log record 1.19, under the 2x bound like the shared maps. Event 3.09, link 3.25 and data point 5.03 are already over it: those maps are sized from their own attribute count, repeats included, which the fix in e77e6b51 left alone (their slack is bounded by the record's wire bytes). They get bounds just above those values so the slack cannot grow unnoticed; fitting them is a separate change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compute_series_hash ran once per data point. It collected every label as a Cow: a non-string label (an int or bool attribute, a start time) was formatted into its own String, so one row allocated one string per such label. The known-field set was a SipHash HashSet, the sort was stable, and the hash was written from the Cow text. Collect &Value references instead and hash a number from a reused buffer with the same bytes Value::to_string prints; look up a known field in an FxHashSet; sort unstably (keys are unique). The hash value is unchanged: the metrics rows digest f12385b9f510100b still passes. Flatten benchmark, instructions:u per row, A/B/B/A x 4 on one box, OTEL_BENCH_ITERS 10 vs 110: metrics 69,741-69,780 -> 63,382-63,383 (-9.1%). Logs and traces do not call this function. Verified by Claude Opus 5.5 on top of 98ae3903: the hash bytes are the same for every label kind (serde_json prints a Number through the same itoa/zmij formatters in Display and in Value::to_string; bool, null, arrays and objects unchanged); the unstable sort only sees distinct map keys; FxHashSet comes from rustc-hash, already a dependency. The seeded corpus digests (logs 5247f2af863c6427, metrics b299fcc3bdad0047, traces 2f813bb532c511a5) and bench digests unchanged; a mutation hashing doubles with Rust's float formatting changes the metrics corpus digest, so double labels are covered. Memory tests unchanged. Release flatten bench, instructions:u per row, A/B/B/A x 4 against 98ae3903: metrics 69,734-69,760 -> 63,317 (-9.2%); logs and traces 0.00%. Co-Authored-By: DeepSeek V4.1 Flash 1017 <noreply@deepseek.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A row is built by merging maps one after the other, and serde_json's Map has no reserve: every merge could rehash the whole row. A 60-entry trace row grew two or three times, and `reserve_rehash` was 4.1% of the traces flatten benchmark, 4.6% of metrics and 4.1% of logs. Size the map for all the entries it will hold, from the lengths of the maps merged into it, then fill it without growing: - logs: `log_record_row` sizes the row for scope + record + resource fields and clones the two shared maps in entry by entry, instead of cloning the scope map and extending it. - traces: `event_row`, `link_row` and `flatten_span_fields` take the number of scope, schema URL, resource and span fields that are merged over them; `SpanParents::finish` inserts the resource fields one by one instead of cloning the resource map first. - metrics: `metric_rows` takes the envelope length and passes it through the data point row builders, which add the metric fields' size to their capacity. `event_row` also stops copying the 30-byte event timestamp it just formatted (`.to_string()` on a String). Flatten benchmark, instructions:u per row, A/B/B/A x 4 on one box, OTEL_BENCH_ITERS 10 vs 110, spread under 0.06%: logs 68,585-68,590 -> 66,275 (-3.4%); traces 93,148 -> 85,803 (-7.9%); metrics on top of the previous commit 63,382 -> 58,247 (-8.1%), against f0f75899 69,730-69,826 -> 58,247 (-16.5%). The rows digests a4cec43f538fd2cd, f12385b9f510100b and a2c661dfe91e9cde still pass. Changed in verification (Claude Opus 5.5, on top of 98ae3903): sizing a span event, span link or metric data point row for the merged fields made the room counted for repeated attribute keys stay empty: with 128 attributes of one key those rows went from 3.09/3.25/5.03 to 3.56/3.76/5.43 times what row_bytes counts. The fields merged later used to fill that room. Those rows now give it back like the shared maps do since e77e6b51 (`insert_attributes_fitted`, and `fit_map` for the prefixed event and link attributes), which also fixes the old excess: 0.85/0.88/0.89. The span map counted 40 fixed slots that already allowed for the scope and resource fields, so adding them again left span rows at 1.42; it now counts its 20 own fields (0.87). The repeated-keys regression test covers these rows at the 2x bound. The rustfmt of the original 6242f2b1 is folded in. Verified: seeded corpus digests (logs 5247f2af863c6427, metrics b299fcc3bdad0047, traces 2f813bb532c511a5) and bench digests unchanged. Memory tests (peak, bound 40 MiB), 98ae3903 -> this commit: events of one span 14.8 -> 13.6 MiB, links 16.2 -> 14.4, points 15.2 -> 15.2, tiny copied fields 20.7 -> 12.6, repeated-key request 21.8 -> 13.7. Row allocated/estimated: realistic 1.02 -> 0.80, tiny fields 1.25 -> 0.77 (rows are no longer grown by doubling, so they hold less than row_bytes counts). Release flatten bench, instructions:u per row, A/B/B/A x 4 against 98ae3903, on top of the previous commit: logs 68,923-68,928 -> 66,553 (-3.4%), metrics 63,317 -> 58,334 (-7.9%), traces 93,296 -> 85,809 (-8.0%). Co-Authored-By: DeepSeek V4.1 Flash 1017 <noreply@deepseek.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every attribute of a record, data point, span event or link was cloned as a whole OTEL `AnyValue` before conversion: for the array-valued attributes common in HTTP telemetry that copied the field's `Vec<AnyValue>` and the strings inside it, and the copy was thrown away right after. Key-value lists were cloned again for every element of an array of lists. Add `insert_json_from_ref`, which converts from `&OtelValue` (copying only the strings that end up in the row), and use it from `insert_attributes`, `flatten_attributes`, `collect_json_from_values` and the key-value list converter. The consuming `insert_json_from_value` keeps its move for the one caller that has an owned value. Flatten benchmark, instructions:u per row, A/B/B/A x 4 on one box, OTEL_BENCH_ITERS 10 vs 110, spread under 0.01%: logs 66,275 -> 65,212 (-1.6%, one array attribute per record), metrics 58,247 -> 58,044 (-0.35%), traces 85,803 -> 85,724 (-0.09%, no array attribute in the benchmark). Rows digests a4cec43f538fd2cd, f12385b9f510100b and a2c661dfe91e9cde still pass. Verified by Claude Opus 5.5 on top of 98ae3903: insert_json_from_ref converts every value kind as insert_json_from_value does (a string is cloned with capacity equal to its length, as prost and serde leave it). The seeded corpus digests (logs 5247f2af863c6427, metrics b299fcc3bdad0047, traces 2f813bb532c511a5) and bench digests unchanged. Memory tests unchanged except the valueless-attributes span peak, 3,206,027 -> 11,065 B. Release flatten bench, instructions:u per row, A/B/B/A x 4 against 98ae3903, on top of the previous commit: logs 66,553 -> 65,469 (-1.6%), metrics 58,334 -> 57,529 (-1.4%), traces 85,809 -> 85,661 (-0.2%). Co-Authored-By: DeepSeek V4.1 Flash 1017 <noreply@deepseek.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`log_record_row` built the record's fields into a map of their own and then moved them into the row: every record key was hashed twice, a second hash table was allocated and grown, and its entries were copied and freed before the row was handed over. `flatten_log_record_into` now inserts the record's fields straight into the row, after the scope fields and before the resource fields, in the same order as before. `flatten_log_record` stays as the wrapper that makes the standalone record map the tests use. Flatten benchmark, instructions:u per row, A/B/B/A x 4 on one box, OTEL_BENCH_ITERS 10 vs 110, spread under 0.01%: logs 65,212-65,213 -> 56,020-56,021 (-14.1%). Metrics and traces do not take this path. The rows digest a4cec43f538fd2cd still passes. Changed in verification (Claude Opus 5.5, on top of 98ae3903): the row is now created with room for 16 + attribute_capacity of the record, and it is kept as the row; before, the record's own map held that room and was moved into a row that grew to its real size. A record of 128 attributes of one key made its row hold 6.12 times what row_bytes counts (1.19 before). The record's attributes are now inserted with `insert_attributes_fitted`, which gives back what repeated keys, and keys the scope fields already have, did not use: 1.05. Verified: insertion order and which value wins on a collision are as before (every record field is inserted in the same order; a key keeps the position of its first insertion and the value of its last, merged into a scratch map first or not); seeded corpus digests (logs 5247f2af863c6427, metrics b299fcc3bdad0047, traces 2f813bb532c511a5) and bench digests unchanged. Memory tests: row allocated/estimated realistic 0.80 -> 0.88, tiny fields 0.77 -> 0.78 (the 16 fixed slots), repeated-key request 13.7 -> 18.1 MiB (98ae3903: 21.8, bound 40). Release flatten bench, instructions:u per row, A/B/B/A x 4 against 98ae3903, on top of the previous commit: logs 65,469 -> 56,216 (-14.1%); metrics and traces unchanged. Co-Authored-By: DeepSeek V4.1 Flash 1017 <noreply@deepseek.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
directly `flatten_severity`, `flatten_flags`, `flatten_kind` and `flatten_status` built a map of two or three fixed fields only for the caller to extend the record with it: the map was allocated, each key hashed and the key/value moved and hashed again. Logs also cloned the severity text a second time. Insert the same fields, in the same order, straight into the record. The helper maps stay for the tests that check their values. Flatten benchmark, instructions:u per row, A/B/B/A x 4 on one box, OTEL_BENCH_ITERS 10 vs 110, spread under 0.01%: logs 56,020-56,021 -> 54,360-54,361 (-3.0%); traces 85,724 -> 83,161-83,162 (-3.0%). Metrics do not take this path. Rows digests a4cec43f538fd2cd and a2c661dfe91e9cde still pass. Verified by Claude Opus 5.5 on top of 98ae3903: the fields are inserted in the order the helper maps had (severity number, text; flags, description; kind, description; status message, code, description), and an insert over an existing key keeps its position as the merge did. The seeded corpus digests (logs 5247f2af863c6427, metrics b299fcc3bdad0047, traces 2f813bb532c511a5) and bench digests unchanged. Memory tests unchanged. Release flatten bench, instructions:u per row, A/B/B/A x 4 against 98ae3903, on top of the previous commit: logs 56,216 -> 54,531 (-3.0%), traces 85,661 -> 83,135 (-2.9%). Metrics 57,529 -> 58,133 (+1.05%) although no metrics code changed: in this build the known-field set lookup in compute_series_hash is no longer inlined (HashMap::contains_key is 2.9% of the profile). The whole series, against 98ae3903: logs -20.9%, metrics -16.7%, traces -10.9%. Co-Authored-By: DeepSeek V4.1 Flash 1017 <noreply@deepseek.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The expansion cap was 4096 times the length of the body with no upper bound, so one body of the full payload limit (10 MiB) could stage 40 GiB of estimated rows, about 6 GiB of record batches held in staging. Keep the factor, which gives ordinary requests 8x headroom over the largest realistic expansion measured, and add a ceiling of 1024 times P_MAX_EVENT_PAYLOAD_SIZE (10 GiB by default). The ceiling decides for bodies over a quarter of the payload limit. The largest realistic request measured at the limit takes 4.1 GiB, 2.4x under it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Bounds the memory one OTLP request makes the server hold, for JSON and protobuf and for logs, metrics and traces.
Before this change a request was decoded whole, flattened into one list of rows and staged in one call. Every row carries its own copy of the resource and scope fields, so memory grew with rows × copied fields: a legitimate 10 MiB request held about 1 GiB, and small crafted bodies held gigabytes.
This PR contains the protobuf PR (#156) and the flattener PR (#157). The commits that are new here start at
63d96da0. Merge those two first and this diff shrinks to the chunking work.How it works
src/otel/sink.rs). The flatteners no longer build a list per request, resource, scope, span or metric.src/otel/protobuf_stream.rs). The request, resource and scope levels are walked by hand and eachLogRecord,SpanorMetricis decoded once with prost. A body that prost would reject is refused with prost's own message before anything is staged.Measured
Behaviour changes
partial_successmessage and an exact rejected count, in the request's encoding. A request that fails before anything is stored keeps today's status and text. A server error keeps its 5xx.P_MAX_EVENT_PAYLOAD_SIZE(10 GiB by default). The largest realistic request measured, short log records under 30 Kubernetes resource attributes filling the 10 MiB limit, takes 4.1 GiB.{}, answers 200 without needing the stream to exist. The setup scripts' protobuf probe relies on this.P_MAX_FLATTEN_BYTES_PER_REQUEST, so an array of about a thousand objects with distinct keys can be refused on datasets with the older schema version.Still unbounded
Verified
cargo test --lib: 1,500 passed, 0 failed, 21 ignored. Clippy and rustfmt add no warnings tomain's.The collector and multi-chunk runs were made on the commit before the expansion ceiling was added; the full test suite was run on this head.
With all six PRs of this set merged together (#156–#161):
cargo test --lib1,515 passed, 0 failed, and on a running server every one of 17 protobuf requests (15 realistic shapes filling the 10 MiB payload limit, 2 crafted) returned 200 and stored the expected number of rows, authenticated with an API key. Row counts ranged from 22,653 to 2,097,152 per request. Server peak memory over the whole run was 2.1 GiB on a debug build, from the record batches staging keeps until conversion (see "Still unbounded").Not verified
This PR has:
🤖 Generated with Claude Code