Skip to content

fix(msk): return the response shape a Kafka SDK parses (#529) - #564

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/529-msk-wire-shape
Aug 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/529-msk-wire-shape

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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-clusters returned 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 locationName case-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/Region leak. 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:

  • The request side works. Go's json.Unmarshal matches keys case-insensitively, so the lowerCamel body a real SDK sends parses into a PascalCase-tagged struct without complaint. Verified live.
  • The state was written correctly. Nothing was corrupted; only the response was unreadable.
  • The Go tests passed. A struct marshaled and unmarshaled by its own definition agrees with itself whatever its tags say — and on top of that, the case-insensitive match means even a hand-written assertion struct with the wrong tags stays green. msk_plugin_test.go was green while the CLI returned nothing.

That last point is why the new tests decode into map[string]any and 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:

  • MSKCluster and its six sibling state types are untouched. Their PascalCase tags are a persisted format that MemoryStateManager snapshots and recorded runs replay from. State encoding is unchanged. A comment block in msk_types.go says 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_StateEncodingUnchanged makes that a fact rather than a claim.
  • Response-only element types (mskClusterInfoOut, mskClusterOut, mskProvisionedOut, mskBrokerNodeGroupInfoOut, mskStorageInfoOut, mskEBSStorageInfoOut, mskBrokerSoftwareInfoOut, mskNodeInfoOut, mskBrokerNodeInfoOut), each tagged from the model, each projected by a …Wire() function.
  • No wire type has an AccountID or Region member at all. The leak is fixed structurally, not by an omitempty that a field added later could defeat.

Judgement calls, from the model rather than the current code

  • nodeARN, not nodeArn. 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.
  • DeleteCluster no longer reports clusterName. It is not a member of DeleteClusterResponse.
  • ListClustersV2 no longer sends an empty nextToken. Substrate returns every cluster in one page, and an empty token invites a caller to page on nothing.
  • Unset optionals are omitted, not nulled. securityGroups: null and volumeSize: 0 appeared on the wire because the state struct has no omitempty; real MSK omits an unset member, and volumeSize: 0 is a size the API rejects. A caller distinguishing absent from null is reading a real observable, so this is a behaviour change on purpose.
  • An empty ListClusters returns [], not null.
  • mskV2ClusterInfo is 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.go

Two 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/clusterName to document the real wire shape.

That retag is provably a no-op: deployMSKCluster unmarshals with encoding/json, which matches case-insensitively, so both spellings recover PhysicalID/ARN from the lowerCamel body. Confirmed by mutation — reverting the tag leaves TestCFN_MSKCluster green, 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:

  • One envelope-and-element test per operation (create, describe, list, delete, bootstrap-brokers, list-nodes, describe-v2, list-v2), each on literal keys. One test covering all eight would pass while seven were wrong.
  • Byte-level leak assertions via bytes.Contains on 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 nested AccountID would hide from a top-level map check.
  • A nested-projection test walking clusterInfo → brokerNodeGroupInfo → storageInfo → ebsStorageInfo, and the v2 equivalent through provisioned. A projection that converts only the top level leaves the nested value PascalCase and a caller parses a cluster with no broker configuration.
  • Absent-versus-null, and empty-list-versus-null.
  • The state-encoding invariance test described above.
  • Value assertions, not just key presence (requireValues). Mutation testing found this gap: a Wire() that forgets a member still emits its key holding Go's zero value, so numberOfBrokerNodes silently 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 vet gate; -race): an element tag reverted to PascalCase; the v1 and v2 envelopes reverted; an AccountID field added back to a wire type; the nested projection skipped; five separate members dropped from four different Wire() functions; nodeARN lowercased; storageInfo always emitted; securityGroups' omitempty dropped; clusterName added back to delete; nextToken restored; 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:

create-cluster                              → ClusterArn/ClusterName/State all parse
list-clusters --query 'length(…)'           → 1
describe-cluster … ClusterInfo.ClusterName  → c1
… BrokerNodeGroupInfo.StorageInfo.EbsStorageInfo.VolumeSize → 100   (nested)
… CurrentBrokerSoftwareInfo.KafkaVersion    → 3.5.1
list-clusters-v2 … ClusterType              → PROVISIONED
describe-cluster-v2 … Provisioned.NumberOfBrokerNodes → 2
get-bootstrap-brokers                       → broker1.c1.us-east-1…:9092,…
list-nodes → 2 nodes, NodeARN and BrokerNodeInfo.BrokerId both parse
delete-cluster --query State                → DELETING
AccountID/Region in any response body       → 0

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.md needed no change: it documents no MSK member names, only the service-table row.

Compatibility

A consumer asserting a PascalCase member, an AccountID/Region field, a clusterName on a delete response, or an empty nextToken from 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

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

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 798b7db into main Aug 4, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the fix/529-msk-wire-shape branch August 9, 2026 17:48
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.

1 participant