feat(client): expose ClusterID via Client interface - #3694
Open
shashank-reddy-nr wants to merge 1 commit into
Open
feat(client): expose ClusterID via Client interface#3694shashank-reddy-nr wants to merge 1 commit into
shashank-reddy-nr wants to merge 1 commit into
Conversation
Add ClusterID() string to the Client interface, backed by the ClusterID field already present in MetadataResponse (protocol version >= 2, Kafka >= 0.10.1). The value is stored on each successful metadata refresh under the existing client.lock RWMutex, consistent with how controllerID is handled. Returns an empty string for brokers that predate Kafka 0.10.1 or before the first metadata response is received. Also add SetClusterID to MockMetadataResponse so tests can configure the mock to return a cluster ID, and add stubLeaderClient.ClusterID() to satisfy the updated interface in async_producer_test.go. Assisted-by: Claude Sonnet 4.6
puellanivis
reviewed
Jul 28, 2026
Comment on lines
+38
to
+41
| // ClusterID returns the cluster ID reported by the broker in the most recent | ||
| // metadata response. It returns an empty string if the broker has not yet | ||
| // responded or if the Kafka version predates 0.10.1 (MetadataResponse v2). | ||
| ClusterID() string |
Collaborator
There was a problem hiding this comment.
This is expanding an exported interface, and thus a breaking change.
Comment on lines
+1116
to
+1118
| if data.ClusterID != nil && *data.ClusterID != "" { | ||
| client.clusterID = *data.ClusterID | ||
| } |
Collaborator
There was a problem hiding this comment.
The test against *data.ClusterID != "" is unnecessary. We can simply assign a zero value as a no-op.
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.
Summary
Adds
ClusterID() stringto theClientinterface, surfacing the cluster ID that brokers already return inMetadataResponse(protocol version ≥ 2, Kafka ≥ 0.10.1.0) but that was never stored or accessible to callers.Changes
client.go— addsclusterID stringfield to theclientstruct; stores the value inupdateMetadata()under the existingclient.lockRWMutex (same pattern ascontrollerID); addsClusterID() stringto theClientinterface; implements(*client).ClusterID()withRLock.mockresponses.go— addsclusterIDfield andSetClusterID()builder toMockMetadataResponseso tests can configure the mock; populatesMetadataResponse.ClusterIDinFor().client_test.go— addsTestClientClusterIDwith two subtests: one atV0_10_1_0that asserts the value round-trips correctly, and one atV0_10_0_0that asserts an empty string is returned when the broker does not include a cluster ID.async_producer_test.go— adds theClusterID() stringstub tostubLeaderClientto satisfy the updated interface.Design notes
string(not(string, error)): the cluster ID is either present or not; returning empty string for pre-0.10.1 brokers is consistent with howcontrollerIDbehaves before any metadata has been received.nopCloserClientrequires no changes — it embeds theClientinterface by value and inherits the new method automatically.MetadataResponse.ClusterIDis*string; the store path checks!= nil && != ""before overwriting, so a nil pointer from an old-version response never clears a previously cached value.