Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support existing deprecated Rebalance.Strategy field usage #2352

Merged
merged 2 commits into from Oct 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions config.go
Expand Up @@ -794,6 +794,12 @@ func (c *Config) Validate() error {
return ConfigurationError("ReadCommitted requires Version >= V0_11_0_0")
}

// backward compatibility on Rebalance Strategy
Copy link
Contributor

Choose a reason for hiding this comment

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

The code works, but I'm not sure if it's good to modify the config in Validation method.

And btw there is no need to clear c.Consumer.Group.Rebalance.GroupStrategies here.
Because c.Consumer.Group.Rebalance.Strategy takes precedence of c.Consumer.Group.Rebalance.GroupStrategies in sarama (
https://github.com/Shopify/sarama/blob/v1.37.0/consumer_group.go#L443-L453 & https://github.com/Shopify/sarama/blob/v1.37.0/consumer_group.go#L333-L340)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you. So just delete the case segment woud be enough. Keep no editing in Validation method.

if c.Consumer.Group.Rebalance.Strategy != nil {
// avoid Consumer.Group.Rebalance.GroupStrategies and Consumer.Group.Rebalance.Strategy being set at the same time
c.Consumer.Group.Rebalance.GroupStrategies = []BalanceStrategy{}
}

// validate the Consumer Group values
switch {
case c.Consumer.Group.Session.Timeout <= 2*time.Millisecond:
Expand All @@ -804,8 +810,6 @@ func (c *Config) Validate() error {
return ConfigurationError("Consumer.Group.Heartbeat.Interval must be < Consumer.Group.Session.Timeout")
case c.Consumer.Group.Rebalance.Strategy == nil && len(c.Consumer.Group.Rebalance.GroupStrategies) == 0:
return ConfigurationError("Consumer.Group.Rebalance.GroupStrategies or Consumer.Group.Rebalance.Strategy must not be empty")
case c.Consumer.Group.Rebalance.Strategy != nil && len(c.Consumer.Group.Rebalance.GroupStrategies) != 0:
return ConfigurationError("Consumer.Group.Rebalance.GroupStrategies and Consumer.Group.Rebalance.Strategy cannot be set at the same time")
case c.Consumer.Group.Rebalance.Timeout <= time.Millisecond:
return ConfigurationError("Consumer.Group.Rebalance.Timeout must be >= 1ms")
case c.Consumer.Group.Rebalance.Retry.Max < 0:
Expand Down