|
| 1 | +# JSON flattening limits |
| 2 | + |
| 3 | +Generic flattening turns every nested array of an event into rows: an event becomes one row |
| 4 | +for each combination of the values of its arrays. Sibling arrays multiply, so |
| 5 | +`{"a": [0..999], "b": [0..999], "c": [0..999]}`, about 11 KiB of JSON, would expand into |
| 6 | +10^9 rows. Three limits cap that expansion. Parseable checks them before it builds any row, |
| 7 | +and rejects the whole request with `400 Bad Request` when one is exceeded. Nothing from a |
| 8 | +rejected request is ingested. |
| 9 | + |
| 10 | +| Environment variable | Flag | Default | Limit | |
| 11 | +| --------------------------------- | --------------------------------- | -------------------- | --------------------------------------------------------- | |
| 12 | +| `P_MAX_FLATTEN_ROWS_PER_EVENT` | `--max-flatten-rows-per-event` | `1000` | Rows a single event may expand into | |
| 13 | +| `P_MAX_FLATTEN_ROWS_PER_REQUEST` | `--max-flatten-rows-per-request` | `10000` | Rows all events of one request may expand into together | |
| 14 | +| `P_MAX_FLATTEN_BYTES_PER_REQUEST` | `--max-flatten-bytes-per-request` | `67108864` (64 MiB) | Bytes all those rows may add up to, measured as compact JSON | |
| 15 | + |
| 16 | +Each value must be a positive integer. A limit cannot be set to zero or switched off. |
| 17 | + |
| 18 | +The byte limit counts the size of the expanded rows as compact JSON, including keys, |
| 19 | +quotes, escapes and delimiters. It also counts what is copied into every row afterwards: |
| 20 | +Kinesis request metadata and OTEL body key prefixes (see below). It is not a measure of the |
| 21 | +memory a request uses. |
| 22 | + |
| 23 | +After generic flattening, every row is flattened structurally: nested objects become fields |
| 24 | +named after the keys on their path, joined with `_`. A parent's name is repeated in every |
| 25 | +field below it, so `{"<128 character name>": {"f0": 0, ..., "f31": 31}, "r": [0, 1, 2, 3]}` |
| 26 | +expands into 4 rows of about 400 bytes, but each of them structurally flattened takes about |
| 27 | +4.4 KiB. Every event is therefore charged the larger of the two: the compact JSON of its |
| 28 | +generic rows, or of those rows structurally flattened. Both are computed in one pass over |
| 29 | +the event, before any row or field name is built. The structurally flattened size counts |
| 30 | +every scalar as a field of its own, even when its joined name collides with another field |
| 31 | +(for example `{"a_b": 1, "a": {"b": 2}}`, where one `a_b` overwrites the other), so with |
| 32 | +such collisions it is an overestimate. Empty objects add no field. |
| 33 | + |
| 34 | +## What counts as an event |
| 35 | + |
| 36 | +The limits apply only where generic flattening runs: |
| 37 | + |
| 38 | +- **JSON and custom sources** (`/api/v1/ingest`, `/api/v1/logstream/{name}`) on datasets using |
| 39 | + schema version V1. Every object in the request body is one event, after any nested |
| 40 | + top-level arrays are spliced in. Bodies nested deeper than `P_MAX_FLATTEN_LEVEL` skip |
| 41 | + generic flattening, so these limits do not apply to them. |
| 42 | +- **Kinesis**: every decoded `data` record is one event, even when it holds a JSON array. |
| 43 | + Each of its rows also gets the request's `requestId` and `timestamp`, so their compact |
| 44 | + JSON size, with keys and delimiters, is counted once per row, on top of the larger of the |
| 45 | + generic and structurally flattened sizes. It is counted in full even for rows that |
| 46 | + already have these fields. |
| 47 | +- **OTEL logs**: a log record whose body (or a body field) is a string holding a JSON object |
| 48 | + has that object flattened. All flattened bodies of one log record together are one event. |
| 49 | + This counts every intermediate row, even though the rows end up merged into the single |
| 50 | + log record. Each top-level field of a flattened body is renamed to `{body key}_{field}` |
| 51 | + before the merge, so the body key, with its escapes and the `_`, is counted again for |
| 52 | + every such field in every row. Structurally flattening the record afterwards repeats the |
| 53 | + body key in the name of every field nested below those too, `{body key}_{field}_{name}`. |
| 54 | + A body is charged the larger of its generic rows with the renamed top-level fields, or |
| 55 | + of its structurally flattened rows with the body key in every field name. This counts |
| 56 | + the rows of a body as if they were all kept, though only the last value of each field |
| 57 | + ends up in the record. |
| 58 | +- **Schema detection** (`/api/v1/logstream/schema/detect`) counts the request body the same |
| 59 | + way as JSON ingestion, structurally flattened rows included. |
| 60 | + |
| 61 | +Every request has a budget of its own. All events of a request share that budget, across |
| 62 | +custom partition elements, Kinesis records, and OTEL resources and scopes. OTEL metrics and |
| 63 | +traces, Kafka, and V0 datasets do not use generic flattening, so these limits do not apply |
| 64 | +to them. |
| 65 | + |
| 66 | +Internal dataset statistics (`pstats`) use the configured byte limit. Their row limits come |
| 67 | +from the size of the stats payload, which is the field count times `P_MAX_FIELD_STATISTICS`. |
| 68 | + |
| 69 | +## When a request is rejected |
| 70 | + |
| 71 | +The error message names the limit that was exceeded and its value. To get under the limit, |
| 72 | +reduce the number or length of the nested arrays in each event, or split the batch into |
| 73 | +smaller requests. You can also raise the limit. |
| 74 | + |
| 75 | +`tools/flatten-bench/http_smoke.py` checks these responses against a built server binary. |
0 commit comments