Repository navigation
eventrecorder: add optional webhook batching - #5392
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughWebhook outputs now support optional JSON-array batching controlled by event count, byte size, and flush interval. Configuration validation, retry behavior, response handling, URL sanitization, tests, documentation, and filepath resolution coverage were updated. ChangesEvent Recorder Batching
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant EventRecorder
participant WebhookOutput
participant BatchLoop
participant WebhookEndpoint
EventRecorder->>WebhookOutput: SendEvent(event)
WebhookOutput->>BatchLoop: Queue serialized event
BatchLoop->>WebhookOutput: Flush JSON array batch
WebhookOutput->>WebhookEndpoint: POST batch with retries
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
eventrecorder/cloudflare_pipelines.go (1)
49-51: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueTighten the URL scheme validation.
The error message explicitly requires an
http(s)URL, but the validation only checks that a scheme exists. A URL likeftp://example.comwould pass this check but fail to fulfill the intent. Consider enforcing the scheme strictly.💡 Proposed fix
- if c.URL.Scheme == "" || c.URL.Host == "" { + if (c.URL.Scheme != "http" && c.URL.Scheme != "https") || c.URL.Host == "" { return errors.New("event_recorder Cloudflare Pipelines output requires an absolute http(s) url") }🤖 Prompt for 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. In `@eventrecorder/cloudflare_pipelines.go` around lines 49 - 51, Update the URL validation in the Cloudflare Pipelines output configuration to accept only http and https schemes, while continuing to require a non-empty host. Preserve the existing error and rejection behavior for invalid URLs, including unsupported schemes such as ftp.eventrecorder/cloudflare_pipelines_test.go (1)
35-38: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueAvoid using
requireinside separate goroutines.While the coding guidelines enforce using
requireoverassert,requireutilizest.FailNow(). When invoked inside a separate goroutine (such as anhttptest.Serverhandler), it instantly terminates that specific goroutine but does not stop the main test execution. This results in the main test deadlocking while waiting to read from therequestschannel, eventually hitting the 10-minute global timeout rather than failing fast.
eventrecorder/cloudflare_pipelines_test.go#L35-L38: Replacerequirewitht.Errorfchecks inside theTestCloudflarePipelinesOutput_SendEventHTTP handler.eventrecorder/cloudflare_pipelines_test.go#L75-L76: Replacerequire.NoError(t, err)inside theTestCloudflarePipelinesOutput_BatchesByEventCountHTTP handler.eventrecorder/cloudflare_pipelines_test.go#L105-L106: Replacerequire.NoError(t, err)inside theTestCloudflarePipelinesOutput_FlushesOnIntervalHTTP handler.eventrecorder/cloudflare_pipelines_test.go#L139-L140: Replacerequire.NoError(t, err)inside theTestCloudflarePipelinesOutput_BatchesByEncodedSizeHTTP handler.eventrecorder/cloudflare_pipelines_test.go#L174-L175: Replacerequire.NoError(t, err)inside theTestCloudflarePipelinesOutput_CloseFlushesPartialBatchHTTP handler.eventrecorder/cloudflare_pipelines_test.go#L204-L205: Replacerequire.NoError(t, err)inside theTestCloudflarePipelinesOutput_RetriesWholeBatchHTTP handler.💡 Example refactor for one of the HTTP handlers
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - require.Equal(t, "application/json", r.Header.Get("Content-Type")) - require.Equal(t, "Bearer pipeline-token", r.Header.Get("Authorization")) + if got := r.Header.Get("Content-Type"); got != "application/json" { + t.Errorf("expected Content-Type application/json, got %s", got) + } + if got := r.Header.Get("Authorization"); got != "Bearer pipeline-token" { + t.Errorf("expected Authorization Bearer pipeline-token, got %s", got) + } body, err := io.ReadAll(r.Body) - require.NoError(t, err) + if err != nil { + t.Errorf("failed to read body: %v", err) + } requests <- body w.WriteHeader(http.StatusNoContent) }))🤖 Prompt for 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. In `@eventrecorder/cloudflare_pipelines_test.go` around lines 35 - 38, Replace all require calls inside the HTTP handlers for TestCloudflarePipelinesOutput_SendEvent (eventrecorder/cloudflare_pipelines_test.go:35-38), TestCloudflarePipelinesOutput_BatchesByEventCount (:75-76), TestCloudflarePipelinesOutput_FlushesOnInterval (:105-106), TestCloudflarePipelinesOutput_BatchesByEncodedSize (:139-140), TestCloudflarePipelinesOutput_CloseFlushesPartialBatch (:174-175), and TestCloudflarePipelinesOutput_RetriesWholeBatch (:204-205) with non-terminating t.Errorf checks, including equivalent error details and preserving each handler’s existing flow.
🤖 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 `@eventrecorder/recorder.go`:
- Around line 194-196: Guard both wc.URL in the Webhook initialization error log
and pc.URL in the Cloudflare Pipelines initialization error log before calling
String(), using a safe nil representation when absent. Update the corresponding
logging paths in eventrecorder/recorder.go at lines 186-188 and 194-196; both
sites require the same change.
In `@eventrecorder/webhook_test.go`:
- Around line 117-144: The webhook test’s capacity-one requests channel can
block the HTTP handler when batching sends an unexpected second request, causing
out.Close to deadlock. Update the test around NewWebhookOutput and the httptest
handler to allow unexpected requests to be recorded without blocking, while
preserving the assertions that the first payload contains three events and no
extra requests were sent.
---
Nitpick comments:
In `@eventrecorder/cloudflare_pipelines_test.go`:
- Around line 35-38: Replace all require calls inside the HTTP handlers for
TestCloudflarePipelinesOutput_SendEvent
(eventrecorder/cloudflare_pipelines_test.go:35-38),
TestCloudflarePipelinesOutput_BatchesByEventCount (:75-76),
TestCloudflarePipelinesOutput_FlushesOnInterval (:105-106),
TestCloudflarePipelinesOutput_BatchesByEncodedSize (:139-140),
TestCloudflarePipelinesOutput_CloseFlushesPartialBatch (:174-175), and
TestCloudflarePipelinesOutput_RetriesWholeBatch (:204-205) with non-terminating
t.Errorf checks, including equivalent error details and preserving each
handler’s existing flow.
In `@eventrecorder/cloudflare_pipelines.go`:
- Around line 49-51: Update the URL validation in the Cloudflare Pipelines
output configuration to accept only http and https schemes, while continuing to
require a non-empty host. Preserve the existing error and rejection behavior for
invalid URLs, including unsupported schemes such as ftp.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: b1140697-7cdf-4f37-b901-1b36872fd3ec
📒 Files selected for processing (10)
CHANGELOG.mdconfig/config.goconfig/config_test.godocs/configuration.mdeventrecorder/cloudflare_pipelines.goeventrecorder/cloudflare_pipelines_test.goeventrecorder/config.goeventrecorder/recorder.goeventrecorder/webhook.goeventrecorder/webhook_test.go
45d6b0e to
43f70af
Compare
43f70af to
53cc6e8
Compare
There was a problem hiding this comment.
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 `@eventrecorder/webhook_test.go`:
- Around line 188-220: Update TestWebhookOutput_BatchingByEncodedSize in
eventrecorder/webhook_test.go lines 188-220 to give the requests channel
capacity beyond two and assert it is empty after validating both batches. Apply
the same channel-capacity increase and post-validation empty-channel assertion
in eventrecorder/webhook_test.go lines 250-287 for the retry test.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: eebabed0-0c2d-4d90-bbe7-7c28547fbfe1
📒 Files selected for processing (6)
CHANGELOG.mdconfig/config_test.godocs/configuration.mdeventrecorder/recorder.goeventrecorder/webhook.goeventrecorder/webhook_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- eventrecorder/webhook.go
Allow webhook outputs to send events as JSON arrays, reducing HTTP request overhead for endpoints that support batched ingestion. Add a single batching coordinator per output that flushes events when the configured count, encoded size, or interval limit is reached. Completed batches are dispatched across the existing HTTP worker pool, while partial batches are flushed during shutdown and retries resend the complete payload. Preserve the existing single-object webhook contract by requiring batching to be explicitly enabled with `batch: true`. Document batching controls, duplicate and ordering semantics, and using a batched webhook output with Cloudflare Pipelines: https://developers.cloudflare.com/pipelines/streams/writing-to-streams/ Cover count-, size-, interval-, retry-, and shutdown-triggered delivery. Signed-off-by: Siavash Safi <[email protected]>
53cc6e8 to
ac4bfcc
Compare
….1 ➔ v0.34.0) (#224) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [quay.io/prometheus/alertmanager](https://github.com/prometheus/alertmanager) | minor | `v0.33.1` → `v0.34.0` | --- >⚠️ **Warning** > > Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/13) for more information. --- ### Release Notes <details> <summary>prometheus/alertmanager (quay.io/prometheus/alertmanager)</summary> ### [`v0.34.0`](https://github.com/prometheus/alertmanager/releases/tag/v0.34.0): 0.34.0 / 2026-08-16 [Compare Source](prometheus/alertmanager@v0.33.1...v0.34.0) - \[CHANGE] notify: The `reason` label on `alertmanager_notifications_failed_total` now distinguishes `authError` (HTTP 401/403) and `rateLimited` (HTTP 429) from the generic `clientError`. Dashboards/alerts matching `reason="clientError"` for these codes must be updated. [#​5332](prometheus/alertmanager#5332) - \[FEATURE] Add optional templatable labels to alert routes. [#​5328](prometheus/alertmanager#5328) - \[FEATURE] eventrecorder: Add inhibit rule names to `inhibition_muted_alert` events. [#​5315](prometheus/alertmanager#5315) - \[FEATURE] eventrecorder: Add stdout output type. [#​5311](prometheus/alertmanager#5311) - \[FEATURE] silences: Add active, expired, and pending boolean filter parameters to GET /api/v2/silences to allow filtering silences by state server-side. [#​5406](prometheus/alertmanager#5406) - \[FEATURE] sns: Add aws `external_id` support in sigv4 configuration. [#​5157](prometheus/alertmanager#5157) - \[FEATURE] template: Add `toDate` and `mustToDate` functions. [#​5327](prometheus/alertmanager#5327) - \[ENHANCEMENT] doc: Add AlertmanagerClusterFailedPeers alertmanager-mixin. [#​5301](prometheus/alertmanager#5301) - \[ENHANCEMENT] doc: Add description for Rocketchat parameters in global config. [#​5181](prometheus/alertmanager#5181) - \[ENHANCEMENT] doc: Add top level tracing configuration key. [#​5314](prometheus/alertmanager#5314) - \[ENHANCEMENT] doc: Fix Alertmanager port in amtool config routes example. [#​5312](prometheus/alertmanager#5312) - \[ENHANCEMENT] eventrecorder: Add optional webhook batching. [#​5392](prometheus/alertmanager#5392) - \[ENHANCEMENT] notify: The discord and webex integrations now report a failure `reason` on `alertmanager_notifications_failed_total`. [#​5332](prometheus/alertmanager#5332) - \[ENHANCEMENT] ui: Improve responsiveness of UI when loading thousands of alerts. [#​5357](prometheus/alertmanager#5357) - \[BUGFIX] eventrecorder: Fixed a minor performance regression when the event recorder is enabled. [#​5307](prometheus/alertmanager#5307) - \[BUGFIX] msteamsv2: Inherit global `proxy_url` into partial `http_config`. [#​5379](prometheus/alertmanager#5379) - \[BUGFIX] webhook: Keep custom `payload` string values verbatim instead of reinterpreting JSON leaves that look like YAML (e.g. values ending with a colon). [#​5304](prometheus/alertmanager#5304) </details> --- ### Configuration 📅 **Schedule**: (in timezone America/Toronto) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4zMC40IiwidXBkYXRlZEluVmVyIjoiNDQuMzIuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsicHJpb3JpdHkvbWVkaXVtIiwicmVub3ZhdGUvY29udGFpbmVyIiwidHlwZS9taW5vciJdfQ==--> Reviewed-on: https://git.dcunha.io/Exikle/frostlink/pulls/224
Allow webhook outputs to send events as JSON arrays, reducing HTTP request
overhead for endpoints that support batched ingestion.
Add a single batching coordinator per output that flushes events when the
configured count, encoded size, or interval limit is reached. Completed
batches are dispatched across the existing HTTP worker pool, while partial
batches are flushed during shutdown and retries resend the complete payload.
Preserve the existing single-object webhook contract by requiring batching
to be explicitly enabled with
batch: true.Document batching controls, duplicate and ordering semantics, and using a
batched webhook output with Cloudflare Pipelines:
https://developers.cloudflare.com/pipelines/streams/writing-to-streams/
Cover count-, size-, interval-, retry-, and shutdown-triggered delivery.
Which user-facing changes does this PR introduce?