aliehsaeedii commented on code in PR #20946: URL: https://github.com/apache/kafka/pull/20946#discussion_r2560383889
########## docs/streams/developer-guide/kafka-streams-group-sh.html: ########## @@ -0,0 +1,278 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<script><!--#include virtual="../../js/templateData.js" --></script> + +<script id="content-template" type="text/x-handlebars-template"> + <!-- h1>Developer Guide for Kafka Streams</h1 --> + <div class="sub-nav-sticky"> + <div class="sticky-top"> + <!-- div style="height:35px"> + <a href="/{{version}}/documentation/streams/">Introduction</a> + <a class="active-menu-item" href="/{{version}}/documentation/streams/developer-guide">Developer Guide</a> + <a href="/{{version}}/documentation/streams/core-concepts">Concepts</a> + <a href="/{{version}}/documentation/streams/quickstart">Run Demo App</a> + <a href="/{{version}}/documentation/streams/tutorial">Tutorial: Write App</a> + </div --> + </div> + </div> +<div class="everything"> + + <div class="container"> + <div class="toc" id="toc"> + <h2>Table of contents</h2> + <ul> + <li><a href="#overview">Overview</a></li> + <li><a href="#what-it-does">What the Streams Groups tool does</a></li> + <li><a href="#usage">Usage</a></li> + <li><a href="#commands">Commands</a></li> + <li><a href="#options">All options and flags</a></li> + <li><a href="#best-practices">Best practices and safety</a></li> + </ul> + </div> + + <div id="header"> + <div class="container"> + <h1>Kafka Streams Groups Tool (kafka-streams-groups.sh)</h1> + <p>Use <code>kafka-streams-groups.sh</code> to manage <strong>Streams groups</strong> for the Streams Rebalance Protocol (KIP‑1071): list and describe groups, inspect members and offsets/lag, reset or delete offsets for input topics, and delete groups (optionally including internal topics).</p> + </div> + </div> + + <div id="overview"> + <span class="anchor" aria-hidden="true"></span> + <h2>Overview</h2> + <p>A <strong>Streams group</strong> is a broker‑coordinated group type for Kafka Streams that uses Streams‑specific RPCs and metadata, distinct from classic consumer groups. The CLI surfaces Streams‑specific states, assignments, and input‑topic offsets to simplify visibility and administration.</p> + + <div class="admonition warning"> + <strong>Use with care:</strong> Mutating operations (offset resets/deletes, group deletion) affect how applications will reprocess data when restarted. Always preview with <span class="kbd">--dry-run</span> before executing and ensure application instances are stopped/inactive. + </div> + </div> + + <div id="what-it-does"> + <span class="anchor" aria-hidden="true"></span> + <h2>What the Streams Groups tool does</h2> + <ul> + <li><strong>List Streams groups</strong> across a cluster and display or filter by group state (Empty, Not Ready, Assigning, Reconciling, Stable, Dead).</li> + + <li><strong>Describe a Streams group</strong> and show: + <ul> + <li>Group state, group epoch, target assignment epoch (with <code>--state</code>, <code>--verbose</code> for additional details).</li> + <li>Per‑member info such as epochs, current vs target assignments, and whether a member still uses the classic protocol (with <code>--members</code> and <code>--verbose</code>).</li> + <li>Input‑topic offsets and lag (with <code>--offsets</code>), to understand how far behind processing is.</li> + </ul> + </li> + + <li><strong>Reset input‑topic offsets</strong> for a Streams group to control reprocessing boundaries using precise specifiers (earliest, latest, to‑offset, to‑datetime, by‑duration, shift‑by, from‑file). Requires <code>--dry-run</code> or <code>--execute</code> and inactive instances.</li> + + <li><strong>Delete offsets</strong> for input topics to force re‑consumption on next start.</li> + + <li><strong>Delete a Streams group</strong> to clean up broker‑side Streams metadata (offsets, topology, assignments). Optionally delete a subset of <strong>internal topics</strong> at the same time using <code>--internal-topics</code>.</li> + </ul> + </div> + + <div id="usage"> + <span class="anchor" aria-hidden="true"></span> + <h2>Usage</h2> + <p>The script is typically located in <code>bin/kafka-streams-groups.sh</code> and connects to your cluster via <code>--bootstrap-server</code>. For secured clusters, pass AdminClient properties using <code>--command-config</code>.</p> + + <pre><code>$ kafka-streams-groups.sh --bootstrap-server <host:port> [COMMAND] [OPTIONS]</code></pre> + + <div class="admonition note"> + <strong>Note:</strong> <code>kafka-streams-groups.sh</code> complements the Streams Admin API for Streams groups. The CLI exposes list/describe/delete operations and offset management similar in spirit to consumer-group tools, but tailored to Streams groups defined in KIP‑1071. + </div> + </div> + + <div id="commands"> + <span class="anchor" aria-hidden="true"></span> + <h2>Commands</h2> + + <div id="list"> + <h3>List Streams groups</h3> + <p>Discovering groups</p> + <pre><code># List all Streams groups +kafka-streams-groups.sh --bootstrap-server localhost:9092 --list +</code></pre> + </div> + + <div id="describe"> + <h3>Describe Streams groups</h3> + <p>Inspecting group's state, members, and lag</p> + <pre><code> +# Describe a group: state + epochs +kafka-streams-groups.sh --bootstrap-server localhost:9092 \ + --describe --group my-streams-app --state --verbose + +# Describe a group: members (assignments vs target, classic/streams) +kafka-streams-groups.sh --bootstrap-server localhost:9092 \ + --describe --group my-streams-app --members --verbose + +# Describe a group: input-topic offsets and lag +kafka-streams-groups.sh --bootstrap-server localhost:9092 \ + --describe --group my-streams-app --offsets +</code></pre> + </div> + + <div id="reset-offsets"> + <h3>Reset input-topic offsets (preview, then apply)</h3> + <p>Ensure all application instances are stopped/inactive. Always preview changes with <code>--dry-run</code> before using <code>--execute</code>.</p> + <pre><code># Preview resetting all input topics to a specific timestamp +kafka-streams-groups.sh --bootstrap-server localhost:9092 \ + --group my-streams-app \ + --reset-offsets --all-input-topics --to-datetime 2025-01-31T23:57:00.000 \ + --dry-run + +# Apply the reset +kafka-streams-groups.sh --bootstrap-server localhost:9092 \ + --group my-streams-app \ + --reset-offsets --all-input-topics --to-datetime 2025-01-31T23:57:00.000 \ + --execute +</code></pre> + </div> + + <div id="delete-offsets"> + <h3>Delete offsets to force re-consumption</h3> + <p>Delete offsets for all or specific input topics to have the group re-read data on restart.</p> + <pre><code># Delete offsets for all input topics (execute) +kafka-streams-groups.sh --bootstrap-server localhost:9092 \ + --group my-streams-app \ + --delete-offsets --all-input-topics --execute + +# Delete offsets for specific topics +kafka-streams-groups.sh --bootstrap-server localhost:9092 \ + --group my-streams-app \ + --delete-offsets --topic input-a --topic input-b --execute +</code></pre> + </div> + + <div id="delete-group"> + <h3>Delete a Streams group (cleanup)</h3> + <p>Delete broker-side Streams metadata for a group and optionally remove a subset of internal topics.</p> + <pre><code># Delete Streams group metadata +kafka-streams-groups.sh --bootstrap-server localhost:9092 \ + --delete --group my-streams-app + +# Delete a subset of internal topics alongside the group (use with care) +kafka-streams-groups.sh --bootstrap-server localhost:9092 \ + --delete --group my-streams-app \ + --internal-topics my-app-repartition-0,my-app-changelog +</code></pre> + </div> + </div> + + <div id="options"> + <span class="anchor" aria-hidden="true"></span> + <h2>All options and flags</h2> + + <div class="options-core"> + <h3>Core actions</h3> + <ul> + <li><code>--list</code>: List Streams groups. Use <code>--state</code> to display/filter by state.</li> + <li><code>--describe</code>: Describe a group selected by <code>--group</code>. Combine with: + <ul> + <li><code>--state</code> (group state and epochs), <code>--members</code> (members and assignments), <code>--offsets</code> (input-topic offsets/lag).</li> + <li><code>--verbose</code> for additional details (e.g., leader epochs where applicable).</li> + </ul> + </li> + <li><code>--reset-offsets</code>: Reset input-topic offsets (one group at a time; instances should be inactive). Choose exactly one specifier: + <ul> + <li><code>--to-earliest</code>, <code>--to-latest</code>, <code>--to-current</code>, <code>--to-offset <n></code></li> + <li><code>--by-duration <PnDTnHnMnS></code>, <code>--to-datetime <YYYY-MM-DDTHH:mm:SS.sss></code></li> + <li><code>--shift-by <n></code> (±), <code>--from-file</code> (CSV)</li> + </ul> + Scope: + <ul> + <li><code>--all-input-topics</code> or one/more <code>--topic <name></code>; some builds also support <code>--all-topics</code> (all input topics per broker topology metadata).</li> + </ul> + Safety: + <ul> + <li>Requires <code>--dry-run</code> or <code>--execute</code>.</li> + </ul> + </li> + <li><code>--delete-offsets</code>: Delete offsets for <code>--all-input-topics</code>, specific <code>--topic</code> names, or <code>--from-file</code>.</li> + <li><code>--delete</code>: Delete Streams group metadata; optionally pass <code>--internal-topics <list></code> to delete a subset of internal topics.</li> + </ul> + </div> + + <div class="options-common"> + <h3>Common flags</h3> + <ul> + <li><code>--group <id></code>: Target Streams group (application.id).</li> + <li><code>--all-groups</code>: Operate on all groups (allowed with <code>--delete</code>).</li> + <li><code>--bootstrap-server <host:port></code>: Broker(s) to connect to (required).</li> + <li><code>--command-config <file></code>: Properties for AdminClient (security, timeouts, etc.).</li> + <li><code>--timeout <ms></code>: Wait time for group stabilization in some operations (default: 5000ms).</li> + <li><code>--dry-run</code>, <code>--execute</code>: Preview vs apply for mutating operations.</li> + <li><code>--help</code>, <code>--version</code>, <code>--verbose</code>: Usage, version, verbosity.</li> + </ul> + </div> + </div> + + <div id="best-practices"> + <span class="anchor" aria-hidden="true"></span> + <h2>Best practices and safety</h2> + <ul> + <li>Stop all application instances before resetting or deleting offsets to prevent immediate re‑joins with stale positions.</li> Review Comment: >Do we allow to change offsets even if the group is not-empty? No, you are right. This is not the best practice! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
