Skip to content

KAFKA-19244: Add support for kafka-streams-groups.sh options (reset-offsets) [1/N] #19646

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

Merged
merged 29 commits into from
Jun 20, 2025

Conversation

aliehsaeedii
Copy link
Contributor

@aliehsaeedii aliehsaeedii commented May 5, 2025

This PR implements all the options for --reset-offset, (supports
--execute, --dry-run, --export). Includes unit and integration
tests.

  • --reset-offsets --input-topic String: topics --shift-by Long
  • --reset-offsets --input-topic String: topics --to-offset Long
  • --reset-offsets --input-topic String: topics -to-latest
  • --reset-offsets --input-topic String: topics -to-earliest
  • --reset-offsets --all-input-topics --shift-by Long
  • --reset-offsets --all-input-topics --to-offset Long
  • --reset-offsets --all-input-topics -to-latest
  • --reset-offsets --all-input-topics -to-earliest
  • --reset-offsets --all-input-topics -to-earliest
  • --reset-offsets --from-file String:fileName
  • --reset-offsets --input-topic String: topics --by-duration String:
    duration
  • --reset-offsets --all-input-topics --by-duration String: duration
  • --reset-offsets --input-topics <String: topics> --to-datetime String:
    datetime
  • --reset-offsets --all-input-topics --to-datetime String: datetime
  • --reset-offsets --input-topics <String: topics> -to-current
  • --reset-offsets --all-input-topics -to-current

Reviewers: Lucas Brutschy [email protected], Bill Bejeck
[email protected]

@github-actions github-actions bot added triage PRs from the community tools clients labels May 5, 2025
@mjsax mjsax added streams KIP-1071 PRs related to KIP-1071 ci-approved and removed triage PRs from the community labels May 5, 2025
Copy link
Member

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @aliehsaeedii I made a pass over the non-testing code, I'll do more in a follow up review

throw new IllegalArgumentException("Cannot shift offset for partition " + topicPartition + " since there is no current committed offset");
}

return currentOffset.offset() + shiftBy;
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to do any validation on what the acceptable values for shiftBy?

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 assume any long value should be accepted. Good point. I'll add some tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems shiftby 150 and -150 are already existing.

@aliehsaeedii aliehsaeedii changed the title KAFKA-19244: Add support for kafka-streams-groups.sh options (delete group, offset-related APIs) [1/2] KAFKA-19244: Add support for kafka-streams-groups.sh options (delete group, offset-related APIs) [1/N] May 19, 2025
@lucasbru lucasbru changed the title KAFKA-19244: Add support for kafka-streams-groups.sh options (delete group, offset-related APIs) [1/N] KAFKA-19244: Add support for kafka-streams-groups.sh options (offset-related APIs) [1/N] May 27, 2025
Copy link
Member

@lucasbru lucasbru left a comment

Choose a reason for hiding this comment

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

Hey @aliehsaeedii ! Thanks for the PR. Mostly looking good to me, left a few comments

Copy link
Member

@lucasbru lucasbru left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I left some comments. These are still relatively high-level things.

List<String> internalTopics = retrieveInternalTopics(List.of(groupId)).get(groupId);
if (internalTopics != null && !internalTopics.isEmpty()) {
try {
adminClient.deleteTopics(internalTopics).all().get();
Copy link
Member

Choose a reason for hiding this comment

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

Why do we delete internal topics here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aliehsaeedii aliehsaeedii changed the title KAFKA-19244: Add support for kafka-streams-groups.sh options (offset-related APIs) [1/N] KAFKA-19244: Add support for kafka-streams-groups.sh options (reset-offsets) [1/N] Jun 4, 2025
Copy link
Member

@lucasbru lucasbru left a comment

Choose a reason for hiding this comment

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

One more comment @aliehsaeedii

Copy link
Member

@lucasbru lucasbru left a comment

Choose a reason for hiding this comment

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

Hi, I left some commments on the documentation. Please make sure that --all-topics and --topics are not present in more places.

private static final String INPUT_TOPIC_DOC = "The input topic whose streams group information should be deleted or topic that should be included in the reset offset process. " +
"In `reset-offsets` case, partitions can be specified using this format: `topic1:0,1,2`, where 0,1,2 are the partition to be included in the process. " +
"Reset-offsets also supports multiple topic inputs.";
private static final String ALL_INPUT_TOPICS_DOC = "Consider all topics assigned to a group in the `reset-offsets` process.";
Copy link
Member

Choose a reason for hiding this comment

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

delete-offsets as well? Maybe use the format Supported operations: delete-offsets, reset-offsets. as in the other options. Also, topics aren't really assigned to a group. How about:

Consider all source topics used in the topology of the group.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, topics aren't really assigned to a group.

I meant associated:|

@lucasbru lucasbru requested a review from Copilot June 12, 2025 14:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces full support for the --reset-offsets command in kafka-streams-groups.sh, refactors offset handling into OffsetsUtils, and updates related tests and utility classes.

  • Add new reset-offsets options (e.g., --to-offset, --by-duration, --export, etc.) in StreamsGroupCommandOptions.
  • Refactor ConsumerGroupCommand to delegate offset logic to OffsetsUtils.
  • Update tests in StreamsGroupCommandTest and DescribeStreamsGroupTest to cover new behavior and require explicit --group for describe; make CSV and spec methods public.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tools/src/main/java/.../StreamsGroupCommandOptions.java Add reset-offsets CLI options, docs, and validation logic.
tools/src/main/java/.../ConsumerGroupCommand.java Replace inline offset logic with OffsetsUtils delegation.
tools/src/test/java/.../StreamsGroupCommandTest.java Update tests to use shared ADMIN_CLIENT mock and new helpers.
tools/src/test/java/.../DescribeStreamsGroupTest.java Require --group for all describe invocations in tests.
tools/src/main/java/.../consumer/group/CsvUtils.java Make readerFor/writerFor methods public.
tools/src/main/java/.../consumer/group/ConsumerGroupCommand.java (Reviewed above)
clients/src/main/java/.../ListStreamsGroupOffsetsSpec.java Make topicPartitions methods public.
Comments suppressed due to low confidence (2)

tools/src/main/java/org/apache/kafka/tools/streams/StreamsGroupCommandOptions.java:227

  • Add a similar check to ensure exportOpt is only allowed when resetOffsetsOpt is present (e.g., only --reset-offsets may be used with --export).
if ((options.has(dryRunOpt) || options.has(executeOpt)) && !options.has(resetOffsetsOpt))

tools/src/main/java/org/apache/kafka/tools/streams/StreamsGroupCommandOptions.java:233

  • Include deleteOffsetsOpt in the allowed set for inputTopicOpt, since deleting offsets also uses --input-topic. E.g., minus(allStreamsGroupLevelOpts, resetOffsetsOpt, deleteOffsetsOpt).
CommandLineUtils.checkInvalidArgs(parser, options, inputTopicOpt, minus(allStreamsGroupLevelOpts, resetOffsetsOpt));

Copy link
Member

@lucasbru lucasbru left a comment

Choose a reason for hiding this comment

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

Hi @aliehsaeedii ! I left some comments

Copy link
Member

@lucasbru lucasbru left a comment

Choose a reason for hiding this comment

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

Hi @aliehsaeedii ! I left some comments

@lucasbru lucasbru merged commit a797d64 into apache:trunk Jun 20, 2025
22 checks passed

public static class Unknown implements LogOffsetResult { }

public static class Ignore implements LogOffsetResult { }
Copy link
Member

Choose a reason for hiding this comment

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

Excuse me, what is the purpose of Ignore? will it be used in next PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants