Skip to content

Fix 1005 dynamodb item size - #1009

Open
DashRam64 wants to merge 2 commits into
aws:mainfrom
DashRam64:fix-1005-dynamodb-item-size
Open

DashRam64 wants to merge 2 commits into
aws:mainfrom
DashRam64:fix-1005-dynamodb-item-size

Conversation

@DashRam64

Copy link
Copy Markdown

Issue #, if available

Fixes #1005

Description of changes

Before: DynamoDBExporter was size-limited by the length of the record's JSON. DynamoDB counts the item, which can be larger: each list or map element costs one byte of overhead that JSON pays only as a comma. A record of 130,000 empty arrays is about 390 KB as JSON, under the 400,000-byte default, so truncation was skipped, but about 520 KB as an item, so PutItem failed and the record was lost.

After: the size limiter measures the DynamoDB item that export() writes, key attributes included. The same record now has its oldest results dropped until the item fits, and is written.

How: DynamoDBExporter gets a measure(rendered) method, the optional hook the size limiter already uses for LambdaLogExporter. It builds the item exactly as export() does (one shared _item method, so keys and number marshalling cannot drift apart) and sums attribute sizes using the rules in the DynamoDB developer guide.

Design

See Rules for every change.

  • Design note (rule 3): the change adds one public member, DynamoDBExporter.measure, which implements the existing optional measure hook of TelemetryExporter. Problem: the limit is checked against a size DynamoDB does not use. Cause: the limiter's default measure is compact JSON bytes. Options: (a) lower the default limit to leave headroom, which still fails for element-heavy records and wastes space for others; (b) a new item-size limiter path in truncation.py, which duplicates the existing hook; (c) implement the existing measure hook on the exporter. Chosen: (c), it reuses the mechanism LambdaLogExporter already uses and changes nothing for other exporters. Nothing is removed.
  • Simpler options considered (rule 2): lowering the default limit (above) does not bound the item for every record. Measuring the marshalled item through the existing hook is the smallest change that does.
  • Root cause (rule 5): truncate_record measured compact_dumps(render(record)) for this exporter, while the destination limit applies to the marshalled DynamoDB item.
  • Net change in source lines and in public API members: +51 source lines in dynamodb_exporter.py; +1 public member (DynamoDBExporter.measure).

Assumptions

Each assumption about the service, Lambda, the runtime or another library, with its evidence, or marked "unverified" (rule 6):

  • Attribute, list, map, string, number, boolean and null sizes follow the DynamoDB developer guide, "DynamoDB item sizes and formats" (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CapacityUnitCalculations.html). Not checked against the service: unverified.
  • The guide calls the number size approximate ("1 byte per two significant digits, plus 1 byte") and says nothing about negative numbers. The code uses that formula as written and adds nothing for a sign: unverified.

Decisions not covered by the issue or the design note

  • The default limit stays 400,000 bytes, now measured as item size, which leaves room under DynamoDB's 400 KB (409,600-byte) item limit.
  • Key attributes (pk, and sk when set) are counted, because they are part of the item DynamoDB stores.
  • A value with no UTF-8 encoding (a lone surrogate) makes measure return None, so the record is written unchanged, as the default JSON measure already does.
  • Only the DynamoDB exporter changes here. The issue notes the JS, Java, Go and Rust SDKs share the gap; this PR follows the documented rules so the other SDKs can match it, and the approach can change if the team settles on another one.
  • No conformance test is added or changed.

Checklist

  • Every new branch has a test that fails without it (rule 4)
  • For a bug fix: the first commit adds a test that fails on the current code (rule 5)
  • Every edited test expectation is listed in the description, with the reason (rule 5): none edited

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Add unit tests for DynamoDBExporter.measure, which should return
  the DynamoDB item size of the item that export() writes, key
  attributes included
- Add a public-path test where the record JSON fits the 400,000-byte
  default but the DynamoDB item does not

These tests fail on the current code, which measures the record's
JSON text instead of the item (aws#1005).
- Add DynamoDBExporter.measure, which returns the DynamoDB item size
  of the item that export() writes, key attributes included, using
  the sizing rules in the DynamoDB developer guide
- Build the item in one place, so export() and measure() use the
  same keys and the same number marshalling
- Document the measured size in the README

The size limiter measured the record's JSON text, but DynamoDB
counts the item: a list element costs one byte more than its JSON
comma, so a record could pass the 400,000-byte check, skip
truncation and still fail PutItem.

Fixes aws#1005

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telemetry exporter: the DynamoDB exporter's record limit measures JSON size, not item size

1 participant