Skip to content

fix(logs): put camelCase member names on the wire for the read operations (#528) - #538

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/528-logs-casing
Aug 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/528-logs-casing

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

The defect

CloudWatch Logs is a JSON-1.1 service whose response members are camelCase, and
botocore matches response members against the service model case-sensitively. That
matters more than it sounds: a PascalCase member does not fail to parse, it parses to
nothing. The caller gets one empty object per resource, with an HTTP 200 and no error.

So describe_log_groups() returned {"logGroups": [{}, {}]}. A len(...) assertion
passed — the right number of groups came back — while every field read raised
KeyError. That is the shape this repo keeps finding: substrate reports success where
the observable is wrong.

Three of the four reads were affected: DescribeLogGroups, DescribeLogStreams,
GetLogEvents. FilterLogEvents was already correct, and why is the whole story.

Cause: one struct doing two jobs

CWLogGroup, CWLogStream and CWLogEvent are tagged PascalCase because they are the
state encoding — what the plugin marshals into the state manager, what
MemoryStateManager.Snapshot/Restore round-trips, what betty_debug replays, and what
LambdaPlugin.autoCreateLambdaLogGroup writes directly to dodge a registry cycle. They
were also embedded in each response envelope. The envelopes are declared inline per
handler with correct camelCase tags, which is why only the members were wrong.

FilterLogEvents escaped because it does not reuse the state struct: it declares a
local filteredEvent with camelCase tags. That is the pattern this follows.

Fix: response-only element types

cwLogGroupOut, cwLogStreamOut and cwOutputLogEventOut in
cloudwatchlogs_types.go, with cwLogGroupWire/cwLogStreamWire/cwOutputLogEventWire
projecting state onto them. Retagging the state structs would have fixed the wire and
changed the persisted format in the same edit — survivable, since Go's json unmarshals
case-insensitively absent an exact match, but not free, and not something to do silently.
TestCWLogs_StateEncodingIsUnchanged reads the state manager directly and asserts the
persisted bytes still carry "LogGroupName"/"ARN"/"CreationTime"/"RetentionInDays"
and not "logGroupArn", so that separation is an assertable property rather than an
intention.

Two of the three projections are type conversions rather than field-by-field literals.
That is deliberate beyond satisfying staticcheck: a conversion stops compiling if a field
is added to only one of the pair, which is exactly the drift this issue came from.

Both ARN forms

The plan for this work recorded that substrate emits the unsuffixed ARN "so the accurate
tag is logGroupArn". Checking the reference rather than the paraphrase: arn and
logGroupArn are both documented, as distinct members, differing only in a trailing
:*. logGroupArn (no suffix) is what a logGroupIdentifier input and the tagging APIs
want; arn (with suffix) is what an IAM policy wants for most actions. Reporting one
value under both names would hand a caller a policy resource the real service rejects, so
DescribeLogGroups reports both, and TestCWLogs_DescribeLogGroupsReportsBothARNForms
pins arn == logGroupArn + ":*".

LogStream documents a single arn with no suffix variant, so there is deliberately no
logStreamArn invented for symmetry — a test asserts its absence.

cwLogGroupPolicyARN leaves an empty ARN empty rather than producing a bare ":*", and
is idempotent over its own output. Neither case is reachable through CreateLogGroup
(which always stores substrate's own unsuffixed ARN); both are reachable from a restored
snapshot, which is why they are tested through an export seam.

PutRetentionPolicy and DeleteRetentionPolicy

Both were unrouted (400 InvalidAction) while RetentionInDays was already modeled and
reported — a group's retention could be read but never set except at create time.

  • retentionInDays accepts only the API's enumerated values (1, 3, 5, 7, 14, 30, 60, 90,
    120, 150, 180, 365, 400, 545, 731, 1096, 1827, 2192, 2557, 2922, 3288, 3653). It is an
    enumeration, not a range, so a plausible-looking 45 or 100 is an
    InvalidParameterException — accepting one would let a template pass under test that
    the real service rejects.
  • The error message enumerates the valid values in ascending order, sorted rather
    than in map order: a nondeterministic error message is one a consumer's test cannot
    assert on.
  • The request struct takes RetentionInDays *int, not int. The member is required and
    0 is not a valid value, so an absent member and an explicit 0 are both errors — but
    only a pointer can tell substrate which one the caller sent, and reporting "0 is not
    valid" about a value they never sent sends them looking in the wrong place. The two
    messages are asserted separately.
  • DeleteRetentionPolicy ships with Put because it is how the API says to make events
    never expire — there is no retentionInDays value meaning "never", so the member's
    absence is the signal. It is idempotent; deleting a policy that is not there is not
    an error, and a cleanup path that runs twice must not fail the second time.
  • A group with no policy omits retentionInDays rather than reporting 0.

Provenance

ResourceNotFoundException is reported at HTTP 400, not 404. That is not substrate's
choice: JSON-1.1 carries the error code in the body's __type rather than in the status
line, and the CloudWatch Logs reference documents every error for these operations at 400.
cwLogsErrorType reads __type in the tests for the same reason — a code that reached
only the header would be invisible to a caller.

Substrate's older group- and stream-level not-found responses on the other Logs
operations still use 404/409. Those are wrong against the reference too, but changing
them is a wider change than this issue, so they are left alone and docs/services.md now
says so explicitly — the inconsistency is a stated decision, not an oversight.

Tests

emulator/cloudwatchlogs_casing_test.go, 13 tests. Every assertion is on the raw JSON
bytes
, because a Go round-trip cannot see this defect: a struct marshaled and
unmarshaled by the same definition agrees with itself whatever the casing. That is
precisely why the existing cloudwatchlogs_plugin_test.go passed — it declared
struct{ LogGroupName string \json:"LogGroupName"` }and thereby **encoded the defect in its own assertion struct**. Five such structs (four incloudwatchlogs_plugin_test.go, one in cloudwatch_extra_test.go` for Lambda's auto-created group) are retagged to
camelCase so a regression turns them red.

Each read gets a positive on the camelCase member and a negative on the PascalCase one,
since a body carrying both would satisfy the positive while still telling a caller
something the API never says. TestCWLogs_FilterLogEventsStaysCorrect guards the
operation that was already right — it is both why the defect was easy to miss and the
pattern the fix copied, so a regression there would mean the pattern itself was undone.
TestCWLogs_CFNLogGroupRetentionIsReadable covers the create-then-verify-then-cleanup
shape the reporting consumer's ECS path needs.

Mutation testing

30 mutants, 30 CAUGHT, 0 survivors, 0 equivalents. Anchor-count assert before
applying, gofmt -w && go vet gate, -race, restore between each.

The first pass had three real survivors, each a test-design defect:

  1. cwLogGroupPolicyARN's empty-ARN and idempotence guards — unreachable through
    HTTP, so untested. Closed with CWLogGroupPolicyARNForTest and
    CWPutLogGroupStateForTest export seams plus TestCWLogs_ARNlessStateReportsNoARN,
    which carries the empty case through to the wire where it would actually be seen.
  2. ingestionTime set to zero — the test asserted the member name was present, not
    that it carried a value. A member present with a plausible 0 behind it is the same
    silent-success failure in subtler form. Now asserted non-zero.
  3. Absent retentionInDays treated as an explicit 0 — both paths returned
    InvalidParameterException at 400, so a code-and-status assertion could not tell them
    apart. The table now asserts the message too.

A fourth reported BROKEN rather than SURVIVED: deleting the guard left strings imported
and unused, so the harness measured a compile error instead of the behaviour. Rewritten to
keep the import live.

Verification

gofmt -l . clean · go build ./... · go vet ./... · golangci-lint run ./... → 0
issues
· make test (race) green · make docs-reference docs-reference-check docs-versions · npm --prefix docs run build · go vet -C test/e2e ./... ·
go test -C test/e2e ./...

End to end against a live server (substrate server --address :4599), which is the
issue's own reproduction — all four reads parse, both ARN forms appear, retention
round-trips, and the CloudFormation route the issue reported is confirmed:

$ aws logs describe-log-groups --log-group-name-prefix /ecs/
{"logGroups": [{"logGroupName": "/ecs/e2e-worker", "creationTime": 1785748565371,
  "arn": "arn:aws:logs:us-east-1:123456789012:log-group:/ecs/e2e-worker:*",
  "logGroupArn": "arn:aws:logs:us-east-1:123456789012:log-group:/ecs/e2e-worker"}]}

$ aws logs put-retention-policy --log-group-name /ecs/e2e-worker --retention-in-days 45
An error occurred (InvalidParameterException): retentionInDays value of 45 is not
valid; possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545,
731, 1096, 1827, 2192, 2557, 2922, 3288, 3653

$ aws cloudformation create-stack --stack-name lg528 --template-body file:///tmp/lg528.yml
$ aws logs describe-log-groups --log-group-name-prefix /ecs/cfn-e2e
{"logGroups": [{"logGroupName": "/ecs/cfn-e2e-family", "creationTime": 1785748582870,
  "retentionInDays": 30, "arn": "...:log-group:/ecs/cfn-e2e-family:*", ...}]}

Compatibility

A consumer reading these responses through an AWS SDK sees fields appear where empty
objects were — nothing they could have been relying on, since the old members were
invisible to the SDK. A consumer parsing the raw JSON by PascalCase key must switch to the
API's names. The persisted state format is unchanged, so existing snapshots and recorded
event logs replay identically.

Closes #528

…ions (#528)

CloudWatch Logs is a JSON-1.1 service whose members are camelCase, and an SDK
matches response members against the service model case-sensitively. A
PascalCase member does not fail to parse — it parses to nothing — so
DescribeLogGroups, DescribeLogStreams and GetLogEvents returned one empty
object per resource with an HTTP 200 and no error.

Each read now projects state onto a response-only element type rather than
retagging CWLogGroup/CWLogStream/CWLogEvent, which are also the persisted
encoding. Adds PutRetentionPolicy and DeleteRetentionPolicy, unrouted before
while RetentionInDays was already modeled and reported.
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.90566% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/cloudwatchlogs_plugin.go 82.41% 8 Missing and 8 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 7c6b317 into main Aug 3, 2026
18 of 19 checks passed
@scttfrdmn
scttfrdmn deleted the fix/528-logs-casing branch August 3, 2026 09:34
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.

Logs: DescribeLogGroups/DescribeLogStreams/GetLogEvents return PascalCase members, so an SDK parses every field to null

1 participant