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

feat: old reset strategy #72

Merged
merged 14 commits into from
Sep 20, 2023
Merged

feat: old reset strategy #72

merged 14 commits into from
Sep 20, 2023

Conversation

ishanarya0
Copy link
Member

@ishanarya0 ishanarya0 commented Sep 18, 2023

Use new group creation for reset strategy.

Comment on lines 207 to 227
func getNewConsumerGroupID(currentConsumerGroupID, deploymentID string) (string, error) {
const groupNumberSuffixLength = 4
suffix := "0000"

currentConsumerGroupSuffix := currentConsumerGroupID[len(currentConsumerGroupID)-groupNumberSuffixLength:]
currentConsumerGroupNumber, err := strconv.Atoi(currentConsumerGroupSuffix)
if err != nil {
return "", err
}

currentConsumerGroupNumber++
newConsumerGroupSuffix := strconv.Itoa(currentConsumerGroupNumber)

if len(newConsumerGroupSuffix) > groupNumberSuffixLength {
return "", errGroupNumberLimitCrossed
}

newConsumerGroupSuffix = suffix[:groupNumberSuffixLength-len(newConsumerGroupSuffix)] + newConsumerGroupSuffix

return fmt.Sprintf("%s-%s", deploymentID, newConsumerGroupSuffix), nil
}
Copy link

@spy16 spy16 Sep 18, 2023

Choose a reason for hiding this comment

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

why do we care about the suffix length and the range being 0-9999?

why not do this:

var suffixRegex = regexp.MustCompile(`(?P<prefix>^[A-Za-z0-9-]+)(?P<seq>-[0-9]+)?$`)

func getNewConsumerGroupID(curGroup string) string {
    matches := suffixRegex.FindStringSubmatch(curGroup)
    prefix, sequence := matches[1], matches[2]
    
    seq, err := strconv.Atoi(sequence)
    if err != nil {
        // ignore the error. but put whatever was here back.
        prefix += sequence
    } else {
        seq++
    }
    
    return fmt.Sprintf("%s-%d", prefix, seq)
}

🚨 I have not tested this properly. so the regex and index handling for the matches might need some testing & tweaking. but the idea remains the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah this looks good 💯
but let's not ignore the error and propagate it back to the user? just in case someone updated it via API?
OR, we can add a suffix "-1", but there is a chance of group name confict. wdys?

Copy link

Choose a reason for hiding this comment

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

The reason for ignoring is the initial case for example where a sequence is not added as a suffix yet.

During creation, you could simply pass the deployment ID in place of curGroup arg, and get back a valid starting point.

The same goes with update. If someone doesn't put a sequence suffix in the end, this will add one automatically

But yea, the update behaviour is something you need to take a call on.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm I get it, but just to avoid any conflicts, I think we should start with a sequence and keep increasing it.

pkg/kafka/consumer_reset.go Outdated Show resolved Hide resolved
@ishanarya0 ishanarya0 requested review from mabdh and spy16 and removed request for spy16 September 18, 2023 10:11
@ishanarya0 ishanarya0 merged commit 2c4ef1f into main Sep 20, 2023
4 checks passed
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.

4 participants