Skip to content

in_kubernetes_events: bound watch connection lifetime - #12105

Merged
edsiper merged 2 commits into
masterfrom
kubernetes-events-hang-12019
Jul 30, 2026
Merged

in_kubernetes_events: bound watch connection lifetime#12105
edsiper merged 2 commits into
masterfrom
kubernetes-events-hang-12019

Conversation

@edsiper

@edsiper edsiper commented Jul 15, 2026

Copy link
Copy Markdown
Member

Problem

The Kubernetes events watch request can remain silently half-open forever when the API server or an intermediary stops sending data without closing the connection. The plugin accepts the incomplete HTTP response as an active streaming client, while the default network I/O timeout is disabled, so the collector never reconnects.

Fixes #12019.

Changes

  • Add kube_watch_timeout, defaulting to 10m; setting it to 0 disables the timeout.
  • Add the corresponding Kubernetes timeoutSeconds query parameter to watch requests.
  • Apply the same value as the HTTP client's read-idle timeout so Fluent Bit can recover if the server-side timeout is not honored.
  • Add an integration regression test that stalls a watch connection and verifies that the plugin reconnects and relists.

The default bounds recovery time while avoiding frequent API relists. Existing behavior can be retained with kube_watch_timeout 0.

Validation

All checks passed:

ctest --test-dir build -R '^flb-rt-in_kubernetes_events$' --output-on-failure
tests/integration/.venv/bin/python -m pytest tests/integration/scenarios/in_kubernetes_events/tests/test_in_kubernetes_events_001.py -q
VALGRIND=1 VALGRIND_STRICT=1 tests/integration/.venv/bin/python -m pytest tests/integration/scenarios/in_kubernetes_events/tests/test_in_kubernetes_events_001.py -q
GITHUB_EVENT_NAME=pull_request GITHUB_BASE_REF=master tests/integration/.venv/bin/python .github/scripts/commit_prefix_check.py

The strict Valgrind run reported zero leaks and zero errors.

Summary by CodeRabbit

  • New Features

    • Added a configurable Kubernetes Events watch timeout (default: 10 minutes).
    • Applied the timeout to watch requests and inactive streaming connections; set it to 0 to disable.
  • Bug Fixes

    • Improved streamed event tracking by advancing the last processed resourceVersion after handling events.
  • Tests

    • Added an integration test that validates reconnection after a stalled watch and confirms the timeout parameter is included in watch URLs.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 88070376-fe38-4d64-9d49-108dabcdd8a4

📥 Commits

Reviewing files that changed from the base of the PR and between b0c1a32 and 7c8f175.

📒 Files selected for processing (1)
  • tests/integration/scenarios/in_kubernetes_events/tests/test_in_kubernetes_events_001.py

📝 Walkthrough

Walkthrough

The Kubernetes events input adds a configurable watch timeout, applies it to Kubernetes watch requests and streaming HTTP read idle handling, advances the tracked resource version from streamed events, and adds integration coverage for stalled-watch reconnection.

Changes

Kubernetes watch timeout handling

Layer / File(s) Summary
Watch timeout and resource-version runtime
plugins/in_kubernetes_events/kubernetes_events.h, plugins/in_kubernetes_events/kubernetes_events.c
Adds a 10-minute default, stores watch_timeout, appends timeoutSeconds to watch requests, configures streaming read idle timeouts, and advances last_resource_version after successful event processing.
Stalled-watch reconnection coverage
tests/integration/scenarios/in_kubernetes_events/tests/test_in_kubernetes_events_001.py
Adds a threaded mock Kubernetes API and verifies repeated list/watch requests, timeout URL parameters, and single event delivery.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: docs-required

Suggested reviewers: cosmo0920

Sequence Diagram(s)

sequenceDiagram
  participant KubernetesEventsInput
  participant KubernetesAPI
  participant StreamingHTTPClient
  KubernetesEventsInput->>KubernetesAPI: Request watch URL with timeoutSeconds
  KubernetesEventsInput->>StreamingHTTPClient: Set read idle timeout
  KubernetesAPI-->>StreamingHTTPClient: Stream event
  KubernetesEventsInput->>KubernetesEventsInput: Process event and advance resourceVersion
  KubernetesAPI-->>StreamingHTTPClient: Close stalled watch
  KubernetesEventsInput->>KubernetesAPI: Reconnect watch
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR improves stalled-watch recovery, but it does not show the requested crash or 5xx health-check path for detectable failures. Add a failure-detection mechanism such as a failing health check or supervised termination when the watch stalls, while keeping reconnection behavior.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: bounding the Kubernetes events watch connection lifetime.
Out of Scope Changes check ✅ Passed The changes stay focused on Kubernetes events watch timeout handling and recovery testing.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch kubernetes-events-hang-12019

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 602e7948c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


flb_sds_printf(&url, "?watch=1&resourceVersion=%" PRIu64, max_resource_version);
if (ctx->watch_timeout > 0) {
flb_sds_printf(&url, "&timeoutSeconds=%d", ctx->watch_timeout);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Advance resource versions before timing out watches

With the new default positive watch timeout, every watch request asks the API server to close after 600s, which makes the next collector cycle perform a full list again. In DB-less configurations, watched events are not used to advance ctx->last_resource_version (it is only updated from list metadata in check_and_init_stream()), so any events delivered by the watch and still retained by Kubernetes have resource versions greater than the stale filter and are emitted a second time on each forced relist. Please update the tracked resource version from watched events or avoid enabling periodic relists by default.

Useful? React with 👍 / 👎.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@tests/integration/scenarios/in_kubernetes_events/tests/test_in_kubernetes_events_001.py`:
- Around line 52-59: Update the Kubernetes event recovery test around the server
response logic and its existing duplicate/resource-version assertions so the
first watch emits only the initial event, while the second watch or relist (when
watch_requests >= 2) emits a distinct event. Extend the client-side wait and
assertions to require that this post-recovery event is processed, while
preserving the existing duplicate/resource-version checks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 12a2ad88-86ef-42ce-ba30-b70492c7a5cb

📥 Commits

Reviewing files that changed from the base of the PR and between 602e794 and b0c1a32.

📒 Files selected for processing (3)
  • plugins/in_kubernetes_events/kubernetes_events.c
  • plugins/in_kubernetes_events/kubernetes_events.h
  • tests/integration/scenarios/in_kubernetes_events/tests/test_in_kubernetes_events_001.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • plugins/in_kubernetes_events/kubernetes_events.h
  • plugins/in_kubernetes_events/kubernetes_events.c

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@edsiper
edsiper force-pushed the kubernetes-events-hang-12019 branch from b0c1a32 to 7c8f175 Compare July 30, 2026 13:48
@edsiper
edsiper merged commit dad5356 into master Jul 30, 2026
52 of 57 checks passed
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.

indefinite hang on processing kubernetes events

1 participant