Repository navigation
fix(logs): put camelCase member names on the wire for the read operations (#528) - #538
Merged
Merged
Conversation
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
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": [{}, {}]}. Alen(...)assertionpassed — the right number of groups came back — while every field read raised
KeyError. That is the shape this repo keeps finding: substrate reports success wherethe observable is wrong.
Three of the four reads were affected:
DescribeLogGroups,DescribeLogStreams,GetLogEvents.FilterLogEventswas already correct, and why is the whole story.Cause: one struct doing two jobs
CWLogGroup,CWLogStreamandCWLogEventare tagged PascalCase because they are thestate encoding — what the plugin marshals into the state manager, what
MemoryStateManager.Snapshot/Restoreround-trips, whatbetty_debugreplays, and whatLambdaPlugin.autoCreateLambdaLogGroupwrites directly to dodge a registry cycle. Theywere 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.
FilterLogEventsescaped because it does not reuse the state struct: it declares alocal
filteredEventwith camelCase tags. That is the pattern this follows.Fix: response-only element types
cwLogGroupOut,cwLogStreamOutandcwOutputLogEventOutincloudwatchlogs_types.go, withcwLogGroupWire/cwLogStreamWire/cwOutputLogEventWireprojecting 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
jsonunmarshalscase-insensitively absent an exact match, but not free, and not something to do silently.
TestCWLogs_StateEncodingIsUnchangedreads the state manager directly and asserts thepersisted bytes still carry
"LogGroupName"/"ARN"/"CreationTime"/"RetentionInDays"and not
"logGroupArn", so that separation is an assertable property rather than anintention.
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:arnandlogGroupArnare both documented, as distinct members, differing only in a trailing:*.logGroupArn(no suffix) is what alogGroupIdentifierinput and the tagging APIswant;
arn(with suffix) is what an IAM policy wants for most actions. Reporting onevalue under both names would hand a caller a policy resource the real service rejects, so
DescribeLogGroupsreports both, andTestCWLogs_DescribeLogGroupsReportsBothARNFormspins
arn == logGroupArn + ":*".LogStreamdocuments a singlearnwith no suffix variant, so there is deliberately nologStreamArninvented for symmetry — a test asserts its absence.cwLogGroupPolicyARNleaves an empty ARN empty rather than producing a bare":*", andis 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) whileRetentionInDayswas already modeled andreported — a group's retention could be read but never set except at create time.
retentionInDaysaccepts 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 thatthe real service rejects.
than in map order: a nondeterministic error message is one a consumer's test cannot
assert on.
RetentionInDays *int, notint. The member is required and0is not a valid value, so an absent member and an explicit0are both errors — butonly 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.
DeleteRetentionPolicyships withPutbecause it is how the API says to make eventsnever expire — there is no
retentionInDaysvalue meaning "never", so the member'sabsence 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.
retentionInDaysrather than reporting0.Provenance
ResourceNotFoundExceptionis reported at HTTP 400, not 404. That is not substrate'schoice: JSON-1.1 carries the error code in the body's
__typerather than in the statusline, and the CloudWatch Logs reference documents every error for these operations at 400.
cwLogsErrorTypereads__typein the tests for the same reason — a code that reachedonly 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.mdnowsays 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 JSONbytes, 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.gopassed — it declaredstruct{ LogGroupName string \json:"LogGroupName"` }and thereby **encoded the defect in its own assertion struct**. Five such structs (four incloudwatchlogs_plugin_test.go, one incloudwatch_extra_test.go` for Lambda's auto-created group) are retagged tocamelCase 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_FilterLogEventsStaysCorrectguards theoperation 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_CFNLogGroupRetentionIsReadablecovers the create-then-verify-then-cleanupshape 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 vetgate,-race, restore between each.The first pass had three real survivors, each a test-design defect:
cwLogGroupPolicyARN's empty-ARN and idempotence guards — unreachable throughHTTP, so untested. Closed with
CWLogGroupPolicyARNForTestandCWPutLogGroupStateForTestexport seams plusTestCWLogs_ARNlessStateReportsNoARN,which carries the empty case through to the wire where it would actually be seen.
ingestionTimeset to zero — the test asserted the member name was present, notthat it carried a value. A member present with a plausible
0behind it is the samesilent-success failure in subtler form. Now asserted non-zero.
retentionInDaystreated as an explicit0— both paths returnedInvalidParameterExceptionat 400, so a code-and-status assertion could not tell themapart. The table now asserts the message too.
A fourth reported BROKEN rather than SURVIVED: deleting the guard left
stringsimportedand 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 ./...→ 0issues ·
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 theissue's own reproduction — all four reads parse, both ARN forms appear, retention
round-trips, and the CloudFormation route the issue reported is confirmed:
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