Commit fac4bc9
kafka_actions: harden reset-consumer-offsets action (DataDog#24165)
* kafka_actions: harden reset-consumer-offsets action
- Abort before altering offsets when the consumer group still has active
members (describe_consumer_groups pre-flight check) so the Kafka
NON_EMPTY_GROUP error never surfaces as a cryptic partial failure.
- Inspect per-partition TopicPartition error codes in the
alter_consumer_group_offsets result; previously only group-level
futures were checked, letting silent per-partition failures through.
- Add reset_to: earliest|latest support: resolves the log-start or
high-watermark via list_offsets at runtime, then commits the concrete
offset. alter_consumer_group_offsets does not accept symbolic offsets.
- Validate that partition and offset are non-negative; reject entries
that set both offset and reset_to or neither.
- Clarify in spec.yaml that the cluster field must be the Kafka-internal
UUID (from AdminClient.list_topics().cluster_id), not a human-readable
name; update examples and error messages accordingly.
- Log the full offset list in the pre-execution warning for audit trail.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* kafka_actions: add changelog entry for PR DataDog#24165
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* kafka_actions: fix ruff formatting
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* kafka_actions: fix ruff import sort in remaining test files
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix update_consumer_group_offsets in kafka_actions
The confluent-kafka AdminClient.alter_consumer_group_offsets() API takes a
single list of ConsumerGroupTopicPartitions, not (group, partitions) as two
positional arguments, which raised "takes 2 positional arguments but 3 were
given". ConsumerGroupTopicPartitions is also exported from confluent_kafka,
not confluent_kafka.admin.
Additionally, future.result() returns a single ConsumerGroupTopicPartitions
object rather than a list of partitions, so iterate its topic_partitions to
collect per-partition errors.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* kafka_actions: add timestamp-based offset reset and sentinel offsets
Replace reset_to: earliest/latest with offset: -2/-1 sentinel values
and add a timestamp field that resolves all partitions of a topic to the
first offset at or after the given millisecond timestamp, with automatic
partition discovery when partition is omitted.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* kafka_actions: remove unrelated cluster-UUID doc changes from spec.yaml
Reverts stray documentation claiming the 'cluster' field for
update_consumer_group_offsets must be the Kafka-internal UUID rather
than a human-readable name. That claim is unrelated to this PR's
hardening work and inconsistent with every other action's cluster
docs/examples (prod-kafka-1).
* kafka_actions: sync changelog entry with current update_consumer_group_offsets behavior
* kafka_actions: restore autogenerated file headers and fix formatting
Regenerated config_models were missing their license headers (a stray
regeneration artifact), and kafka_client.py / test_unit.py had two
small ruff formatting/import-order issues.
* kafka_actions: address round-1 review feedback on offset-reset hardening
Adds request timeouts and error handling around list_offsets/describe_consumer_groups
calls, de-dups overlapping offset targets, guards against both offset and timestamp
being set, and splits update_consumer_group_offsets into smaller resolver methods.
Extracts a shared partition-discovery helper and de-dups the config.py partition
validation. Adds unit test coverage for the client-internal sentinel/timestamp/
per-partition-error/active-member logic and parameterizes the offsets validation
tests. Cleans up doc formatting in spec.yaml and splits the changelog entry into
.fixed/.added to reflect the net-new sentinel/timestamp capabilities.
* [kafka_actions] Address round-2 review feedback
Batch the timestamp-fallback offset lookup instead of issuing one
list_offsets RPC per partition, pass the admin client into the resolver
helpers consistently, wrap the describe_consumer_groups result with the
same log-and-reraise pattern as the other admin calls, and tighten a
couple of doc/type-hint/test gaps flagged by the second review pass.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* [kafka_actions] Fix import grouping in test files (ruff I001)
CI's ruff check flagged missing blank-line separation between third-party
and first-party import groups across the test suite.
* [kafka_actions] Address round-3 review nits
Type-hint the admin param on the offset resolver helpers, and key the
fallback test's list_offsets stub on OffsetSpec type instead of request
length so it stays correct if a second fallback partition is added.
* [kafka_actions] Fix import grouping (ruff I001)
Restore the blank line between third-party and first-party import
groups after adding the OffsetSpec import.
* [kafka_actions] Trim redundant offsets doc and merge changelog entries
Remove the duplicated offset/timestamp usage block from the action
description (already covered in the per-field docs), and consolidate
the two changelog fragments into a single added entry.
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent ac244fb commit fac4bc9
9 files changed
Lines changed: 584 additions & 69 deletions
File tree
- kafka_actions
- assets/configuration
- changelog.d
- datadog_checks/kafka_actions
- config_models
- data
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
505 | | - | |
| 505 | + | |
| 506 | + | |
506 | 507 | | |
507 | 508 | | |
508 | 509 | | |
| |||
518 | 519 | | |
519 | 520 | | |
520 | 521 | | |
521 | | - | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
522 | 525 | | |
523 | 526 | | |
524 | 527 | | |
| |||
530 | 533 | | |
531 | 534 | | |
532 | 535 | | |
533 | | - | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
534 | 539 | | |
535 | 540 | | |
536 | 541 | | |
537 | 542 | | |
538 | | - | |
539 | | - | |
540 | 543 | | |
541 | 544 | | |
542 | 545 | | |
543 | 546 | | |
544 | 547 | | |
545 | 548 | | |
546 | | - | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
547 | 552 | | |
548 | 553 | | |
549 | | - | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
550 | 564 | | |
551 | 565 | | |
552 | 566 | | |
553 | 567 | | |
554 | 568 | | |
555 | 569 | | |
556 | | - | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
557 | 573 | | |
558 | 574 | | |
559 | 575 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
743 | 743 | | |
744 | 744 | | |
745 | 745 | | |
746 | | - | |
| 746 | + | |
747 | 747 | | |
748 | 748 | | |
749 | | - | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
750 | 752 | | |
751 | 753 | | |
752 | 754 | | |
| |||
755 | 757 | | |
756 | 758 | | |
757 | 759 | | |
| 760 | + | |
| 761 | + | |
758 | 762 | | |
759 | | - | |
| 763 | + | |
| 764 | + | |
760 | 765 | | |
761 | 766 | | |
| 767 | + | |
762 | 768 | | |
763 | 769 | | |
764 | 770 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
289 | 290 | | |
290 | 291 | | |
291 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
292 | 298 | | |
293 | 299 | | |
294 | 300 | | |
| |||
310 | 316 | | |
311 | 317 | | |
312 | 318 | | |
313 | | - | |
314 | | - | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
315 | 327 | | |
316 | | - | |
317 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
318 | 331 | | |
319 | | - | |
320 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
321 | 346 | | |
322 | | - | |
323 | | - | |
| 347 | + | |
| 348 | + | |
324 | 349 | | |
325 | 350 | | |
326 | 351 | | |
| |||
Lines changed: 15 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
209 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
210 | 220 | | |
211 | 221 | | |
212 | 222 | | |
| |||
219 | 229 | | |
220 | 230 | | |
221 | 231 | | |
222 | | - | |
| 232 | + | |
223 | 233 | | |
224 | 234 | | |
225 | 235 | | |
226 | | - | |
| 236 | + | |
| 237 | + | |
227 | 238 | | |
228 | 239 | | |
229 | 240 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
| 262 | + | |
| 263 | + | |
263 | 264 | | |
264 | 265 | | |
265 | 266 | | |
| |||
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
273 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
274 | 277 | | |
275 | 278 | | |
276 | 279 | | |
| |||
0 commit comments