refactor(kafka-connect): improve request logging and dry-run handling - #652
Open
disrupted wants to merge 26 commits into
Open
refactor(kafka-connect): improve request logging and dry-run handling#652disrupted wants to merge 26 commits into
disrupted wants to merge 26 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the Kafka Connect REST client to use httpx event hooks for request/response debug logging, and unifies “real” vs “dry-run” behavior through a single request path. It also updates the KafkaConnectHandler and related tests to pass dry_run through to Kafka Connect operations consistently.
Changes:
- Rename/refactor the Kafka Connect REST wrapper to
KafkaConnect, adding a unifiedrequest()method withdry_runsupport. - Add httpx request/response event hooks to centralize debug logging.
- Update handler logic and tests to propagate
dry_runinto create/update/pause/resume/stop/delete/reset flows.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
kpops/component_handlers/kafka_connect/kafka_connect_api.py |
Introduces KafkaConnect, central request() method, and httpx event-hook-based logging with dry_run support. |
kpops/component_handlers/kafka_connect/kafka_connect_handler.py |
Refactors handler flow to use KafkaConnect methods and propagate dry_run across operations. |
tests/component_handlers/kafka_connect/test_kafka_connect_api.py |
Updates API tests to use pytest_httpx request inspection and adds logging/dry-run behavior tests. |
tests/component_handlers/kafka_connect/test_kafka_connect_handler.py |
Updates handler tests to reflect new dry_run plumbing and reset/delete behavior. |
Comments suppressed due to low confidence (4)
kpops/component_handlers/kafka_connect/kafka_connect_api.py:65
_log_response()always callsawait response.aread()and attempts JSON parsing, even when DEBUG logging is disabled. This forces buffering the full response body in memory for every request (including large responses) and can interfere with streaming usage. Guard the body read/logging behindlog.isEnabledFor(logging.DEBUG)so normal INFO-level runs don't pay this cost.
kpops/component_handlers/kafka_connect/kafka_connect_api.py:57_log_request()decodesrequest.contentunconditionally when it exists, even if DEBUG logging is disabled. This adds overhead on every request and can raiseUnicodeDecodeErrorfor non-UTF8 payloads. Consider guarding onlog.isEnabledFor(logging.DEBUG)and decoding witherrors="replace"(or falling back torepr(...)).
tests/component_handlers/kafka_connect/test_kafka_connect_api.py:721- Same as above: this test collects all DEBUG records in
caplog, which can break if unrelated DEBUG logs are emitted. Filter byrecord.name == "KafkaConnectAPI"to make the assertions deterministic.
tests/component_handlers/kafka_connect/test_kafka_connect_api.py:632 - The DEBUG log assertions collect all DEBUG records in
caplog, which can make the test flaky if any other library emits DEBUG logs. Filter by the expected logger name (e.g.KafkaConnectAPI) so the test only asserts on KafkaConnect's hook output.
This issue also appears on line 719 of the same file.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
use httpx event hooks to clean up logging
unified
KafkaConnect._request()method to handle both real execution and dry-run preview