Skip to content

feat(kafka): add rackId for kafka consumers - #4872

Merged
mark-vass-konghq merged 1 commit into
mainfrom
feat/add-rackId-for-kafka-consumers
Aug 7, 2026
Merged

mark-vass-konghq merged 1 commit into
mainfrom
feat/add-rackId-for-kafka-consumers

Conversation

@mark-vass-konghq

@mark-vass-konghq mark-vass-konghq commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds clientRack config option, mapped to librdkafka's client.rack setting.

Why

Enables rack-aware consumer group assignment and lets consumers fetch from replicas in the same rack/AZ, reducing cross-AZ network traffic and cost.

Changes

  • pkg/kafka/config.go: new ClientRack field on CommonConfigParams; sets client.rack in the config map when non-empty.
  • app/config/kafka.go: registers kafka.clientRack viper default (empty string, opt-in).
  • config.example.yaml: documents the new option.
  • Test coverage updated across pkg/kafka/config_test.go, app/config/config_test.go, and app/config/testdata/complete.yaml.

Compatibility

Backward compatible. Field defaults to empty, so client.rack is only set when explicitly configured.

Summary by CodeRabbit

  • New Features

    • Added optional Kafka client rack configuration for rack-aware behavior.
    • Kafka clients now include the configured rack identifier when provided.
    • Added example configuration and documentation for setting the client rack.
  • Bug Fixes

    • Improved handling and reporting of Kafka configuration errors.
    • Configurations without a rack identifier continue to work without adding an empty setting.

Greptile Summary

The PR adds an optional Kafka client rack setting and maps it to librdkafka’s client.rack property.

  • Registers the kafka.clientRack configuration default.
  • Propagates non-empty rack identifiers into the shared Kafka configuration map.
  • Updates example configuration, fixtures, and tests for configured and empty values.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
pkg/kafka/config.go Adds the optional ClientRack field and conditionally maps it to librdkafka’s client.rack property.
app/config/kafka.go Registers an empty, opt-in default for the new Kafka client rack setting.
pkg/kafka/config_test.go Covers both configured rack propagation and omission of the property when the value is empty.
app/config/config_test.go Extends complete configuration decoding coverage to include ClientRack.
config.example.yaml Documents the optional rack identifier and its rack-aware consumer behavior.

Reviews (2): Last reviewed commit: "feat(kafka): add rackId for kafka consum..." | Re-trigger Greptile

@mark-vass-konghq mark-vass-konghq self-assigned this Aug 7, 2026
@mark-vass-konghq
mark-vass-konghq requested a review from a team as a code owner August 7, 2026 07:27
@mark-vass-konghq mark-vass-konghq added the release-note/feature Release note: Exciting New Features label Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Kafka configuration now supports an optional client rack. The setting maps to client.rack, has an empty default, and appears in configuration fixtures, examples, and tests.

Changes

Kafka client rack configuration

Layer / File(s) Summary
Client rack configuration mapping
pkg/kafka/config.go, pkg/kafka/config_test.go
CommonConfigParams adds ClientRack. AsConfigMap emits client.rack for non-empty values. Tests verify configured and omitted values.
Defaults and configuration fixtures
app/config/kafka.go, app/config/testdata/complete.yaml, app/config/config_test.go, config.example.yaml
Kafka configuration defines an empty kafka.clientRack default. Fixtures, expected values, and the example configuration use use1-az1.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: borbelyr-kong

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the Kafka consumer rack configuration added by the pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-rackId-for-kafka-consumers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
config.example.yaml (1)

213-215: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Document the broker-side prerequisites.

clientRack must match the broker broker.rack. Follower selection depends on the broker replica.selector.class, and rack-aware assignment is best effort with compatible Kafka versions. Setting clientRack: use1-az1 alone does not guarantee same-rack fetching. Add a short prerequisite note here. (cwiki.apache.org)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@config.example.yaml` around lines 213 - 215, Update the clientRack
configuration comments to add a concise prerequisite note: clientRack must match
broker.rack, follower selection requires the broker replica.selector.class
configuration, and rack-aware assignment is best effort with compatible Kafka
versions.

Source: MCP tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/kafka/config_test.go`:
- Around line 41-42: Add a test case in the existing Kafka config test covering
ClientRack set to an empty string, and explicitly assert that the resulting
configuration does not contain the client.rack key. Retain the current
configured-rack assertions and ensure the new case verifies unexpected keys are
absent.

---

Nitpick comments:
In `@config.example.yaml`:
- Around line 213-215: Update the clientRack configuration comments to add a
concise prerequisite note: clientRack must match broker.rack, follower selection
requires the broker replica.selector.class configuration, and rack-aware
assignment is best effort with compatible Kafka versions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7125471c-877b-4d14-b181-d09cc9ecec61

📥 Commits

Reviewing files that changed from the base of the PR and between ef9f6e9 and 8dfd6ce.

📒 Files selected for processing (6)
  • app/config/config_test.go
  • app/config/kafka.go
  • app/config/testdata/complete.yaml
  • config.example.yaml
  • pkg/kafka/config.go
  • pkg/kafka/config_test.go

Comment thread pkg/kafka/config_test.go Resolved
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/add-rackId-for-kafka-consumers branch from 8dfd6ce to a83d5e4 Compare August 7, 2026 07:43
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@chrisgacsal chrisgacsal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! :shipit:

@mark-vass-konghq
mark-vass-konghq merged commit 49f490d into main Aug 7, 2026
27 checks passed
@mark-vass-konghq
mark-vass-konghq deleted the feat/add-rackId-for-kafka-consumers branch August 7, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants