Repository navigation
fix(msk): return the response shape a Kafka SDK parses (#529) - #564
Merged
Merged
Conversation
Every kafka response substrate sent used PascalCase keys. botocore matches a response key against the model's locationName case-sensitively, and all 579 kafka response members are lowerCamel, so nothing substrate returned parsed: `aws kafka list-clusters` answered HTTP 200 with an empty result and no error. The defect was invisible from every direction. The request side works, because Go's json.Unmarshal matches keys case-insensitively and so accepts the lowerCamel body a real SDK sends into a PascalCase-tagged struct. State was written correctly. And the Go round-trip tests passed, because a struct marshaled and unmarshaled by its own definition agrees with itself whatever its tags say. Fixed as #528 fixed CloudWatch Logs: the state types keep their PascalCase tags and response-only element types tagged from the model are projected from them. MSKCluster and its six siblings are untouched, so state encoding is unchanged and recorded runs replay. Also corrected: DeleteCluster no longer reports clusterName, which is not a member of DeleteClusterResponse; ListClustersV2 no longer sends an empty nextToken; the v2 handlers' hand-written PascalCase map is gone, so v1 and v2 share one projection and cannot drift; an unset securityGroups/storageInfo/tags is omitted rather than sent as null or volumeSize 0; and substrate's internal AccountID and Region are structurally absent from every wire type, so a field added later cannot reintroduce the leak. The new tests decode into map[string]any and assert literal wire keys and values, since key presence alone does not prove a projection carried a member. Closes #529 for MSK; API Gateway v1 and v2 follow in this milestone.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 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.
Second of four PRs for #529 (v0.91.0). PR A made API Gateway v2 and SSO Admin reachable from an SDK at all; this one fixes MSK's wire shape. API Gateway v1 and v2 follow.
The defect
aws kafka list-clustersreturned HTTP 200 with an empty result and no error. So did every other kafka call. Not "some fields missing" — nothing parsed.botocore's rest-json parser matches a response key against the model's
locationNamecase-sensitively. The kafka model spells all 579 of its response members in lowerCamel, with no exceptions. Substrate marshaled its PascalCase state struct straight onto the wire, so{"ClusterInfoList":[…]}matched nothing and parsed to{}.This corrects #529 as filed, which says MSK's "API is natively PascalCase, so its casing is correct" and flags only the
AccountID/Regionleak. Both are wrong: the casing is broken exactly as API Gateway's is, and the leak is the smaller half. (Posted as a correction on the issue before starting.)Why nothing caught it
Three independent reasons, and they are the reason this defect class is worth a release:
json.Unmarshalmatches keys case-insensitively, so the lowerCamel body a real SDK sends parses into a PascalCase-tagged struct without complaint. Verified live.msk_plugin_test.gowas green while the CLI returned nothing.That last point is why the new tests decode into
map[string]anyand assert on literal wire keys. It is the only assertion that can see the difference.The fix
#528's remedy at
cloudwatchlogs_types.go:59-121, followed exactly:MSKClusterand its six sibling state types are untouched. Their PascalCase tags are a persisted format thatMemoryStateManagersnapshots and recorded runs replay from. State encoding is unchanged. A comment block inmsk_types.gosays why, because the tempting fix for a future casing bug is to retag the state struct — which conflates the two jobs again and silently changes the format of every recorded run.TestMSKWire_StateEncodingUnchangedmakes that a fact rather than a claim.mskClusterInfoOut,mskClusterOut,mskProvisionedOut,mskBrokerNodeGroupInfoOut,mskStorageInfoOut,mskEBSStorageInfoOut,mskBrokerSoftwareInfoOut,mskNodeInfoOut,mskBrokerNodeInfoOut), each tagged from the model, each projected by a…Wire()function.AccountIDorRegionmember at all. The leak is fixed structurally, not by anomitemptythat a field added later could defeat.Judgement calls, from the model rather than the current code
nodeARN, notnodeArn. The one kafka response member that is not the plain lowerCamel of its name. Transcribed from the model; a mechanical lowercasing would have got exactly this wrong.DeleteClusterno longer reportsclusterName. It is not a member ofDeleteClusterResponse.ListClustersV2no longer sends an emptynextToken. Substrate returns every cluster in one page, and an empty token invites a caller to page on nothing.securityGroups: nullandvolumeSize: 0appeared on the wire because the state struct has noomitempty; real MSK omits an unset member, andvolumeSize: 0is a size the API rejects. A caller distinguishing absent from null is reading a real observable, so this is a behaviour change on purpose.ListClustersreturns[], notnull.mskV2ClusterInfois deleted. The v2 handlers built a hand-written PascalCase map — wrong for the same reason the struct path was, not right for being hand-written. v1 and v2 now share one projection and cannot drift.cfn_resources_v34.goTwo changes, neither behavioural. The comment claimed "MSK's API is natively PascalCase, so only the values need attention" — the PascalCase keys there are CloudFormation template property names and are no evidence of the wire shape; corrected with a pointer to #529. And the create-response struct is retagged
clusterArn/clusterNameto document the real wire shape.That retag is provably a no-op:
deployMSKClusterunmarshals withencoding/json, which matches case-insensitively, so both spellings recoverPhysicalID/ARNfrom the lowerCamel body. Confirmed by mutation — reverting the tag leavesTestCFN_MSKClustergreen, verdict EQUIVALENT with that proof. It is the same mechanism that hid #529, benign here because both ends are Go.Tests
emulator/msk_wire_test.go, new — 12 tests asserting the raw wire:bytes.Containson every response, per API Gateway: state structs are marshalled straight to the wire, so responses are PascalCase and carry substrate's internal AccountID/Region #529's criterion — a nestedAccountIDwould hide from a top-level map check.clusterInfo→brokerNodeGroupInfo→storageInfo→ebsStorageInfo, and the v2 equivalent throughprovisioned. A projection that converts only the top level leaves the nested value PascalCase and a caller parses a cluster with no broker configuration.requireValues). Mutation testing found this gap: aWire()that forgets a member still emits its key holding Go's zero value, sonumberOfBrokerNodessilently became 0 and a presence check saw nothing wrong. That is the likeliest real-world slip in a transcription like this, so every member a projection copies is now checked by value.msk_plugin_test.go's nine assertion blocks are converted to the real wire keys. Worth saying plainly: those assertions were wrong today and passed anyway — the case-insensitive match again. Updating them is part of the fix, not weakened testing.Verification
Mutation testing, 17 mutants, 17 CAUGHT (green baseline pre-flight; anchor-count assert before applying;
gofmt+go vetgate;-race): an element tag reverted to PascalCase; the v1 and v2 envelopes reverted; anAccountIDfield added back to a wire type; the nested projection skipped; five separate members dropped from four differentWire()functions;nodeARNlowercased;storageInfoalways emitted;securityGroups'omitemptydropped;clusterNameadded back to delete;nextTokenrestored; and the state struct retagged to the wire spelling. Plus one EQUIVALENT with the proof given above.Gates:
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues,make test(race),make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./...— all clean.Live against
substrate server, every line of which returned empty or a null-type error before:The raw body, from botocore's own debug log:
{"clusterInfoList":[{"clusterArn":…,"clusterName":"c2","state":"ACTIVE","brokerNodeGroupInfo":{"instanceType":…,"clientSubnets":[…]},"currentBrokerSoftwareInfo":{"kafkaVersion":"3.5.1"},"numberOfBrokerNodes":2,"creationTime":…}]}— lowerCamel throughout, no leak, no nulls, sparse members absent.docs/services.mdneeded no change: it documents no MSK member names, only the service-table row.Compatibility
A consumer asserting a PascalCase member, an
AccountID/Regionfield, aclusterNameon a delete response, or an emptynextTokenfrom MSK will go red. That is the fix — those shapes were unparseable by a real SDK — but anyone pinned to the broken shape should know. State encoding is unchanged, so recorded runs replay.#529 stays open until API Gateway v1 and v2 land.
Refs #529