Skip to content

eventrecorder: add optional webhook batching - #5392

Merged
siavashs merged 1 commit into
prometheus:mainfrom
siavashs:feat/cf-pipelines
Jul 18, 2026
Merged

siavashs merged 1 commit into
prometheus:mainfrom
siavashs:feat/cf-pipelines

Conversation

@siavashs

@siavashs siavashs commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

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?

[ENHANCEMENT] eventrecorder: Add optional webhook batching.

@siavashs
siavashs requested a review from a team as a code owner July 17, 2026 11:24
@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 92aed7c4-3d82-41c2-b60b-874081b7069d

📥 Commits

Reviewing files that changed from the base of the PR and between 53cc6e8 and ac4bfcc.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • config/config_test.go
  • docs/configuration.md
  • eventrecorder/recorder.go
  • eventrecorder/webhook.go
  • eventrecorder/webhook_test.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • config/config_test.go
  • CHANGELOG.md
  • eventrecorder/recorder.go
  • docs/configuration.md
  • eventrecorder/webhook_test.go
  • eventrecorder/webhook.go

📝 Walkthrough

Walkthrough

Webhook 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.

Changes

Event Recorder Batching

Layer / File(s) Summary
Batching configuration contract
eventrecorder/webhook.go, config/config_test.go, docs/configuration.md, CHANGELOG.md
Adds batching fields, defaults, validation, equality handling, configuration coverage, delivery documentation, and a changelog entry.
Batched webhook delivery
eventrecorder/webhook.go, eventrecorder/recorder.go
Adds batch aggregation and delivery workers, threshold- and timer-based flushing, whole-batch retries, response draining, output-kind logging, and sanitized URL errors.
Batching behavior validation
eventrecorder/webhook_test.go
Tests batching by count and size, interval and close flushing, retrying complete batches, YAML validation, payload decoding, and configuration equality.

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
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.81% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: optional webhook batching in eventrecorder.
Description check ✅ Passed The description clearly explains the feature, behavior, documentation impact, and includes the required release-notes entry.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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: 2

🧹 Nitpick comments (2)
eventrecorder/cloudflare_pipelines.go (1)

49-51: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Tighten the URL scheme validation.

The error message explicitly requires an http(s) URL, but the validation only checks that a scheme exists. A URL like ftp://example.com would 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 value

Avoid using require inside separate goroutines.

While the coding guidelines enforce using require over assert, require utilizes t.FailNow(). When invoked inside a separate goroutine (such as an httptest.Server handler), 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 the requests channel, eventually hitting the 10-minute global timeout rather than failing fast.

  • eventrecorder/cloudflare_pipelines_test.go#L35-L38: Replace require with t.Errorf checks inside the TestCloudflarePipelinesOutput_SendEvent HTTP handler.
  • eventrecorder/cloudflare_pipelines_test.go#L75-L76: Replace require.NoError(t, err) inside the TestCloudflarePipelinesOutput_BatchesByEventCount HTTP handler.
  • eventrecorder/cloudflare_pipelines_test.go#L105-L106: Replace require.NoError(t, err) inside the TestCloudflarePipelinesOutput_FlushesOnInterval HTTP handler.
  • eventrecorder/cloudflare_pipelines_test.go#L139-L140: Replace require.NoError(t, err) inside the TestCloudflarePipelinesOutput_BatchesByEncodedSize HTTP handler.
  • eventrecorder/cloudflare_pipelines_test.go#L174-L175: Replace require.NoError(t, err) inside the TestCloudflarePipelinesOutput_CloseFlushesPartialBatch HTTP handler.
  • eventrecorder/cloudflare_pipelines_test.go#L204-L205: Replace require.NoError(t, err) inside the TestCloudflarePipelinesOutput_RetriesWholeBatch HTTP 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9e50fad and 45d6b0e.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • config/config.go
  • config/config_test.go
  • docs/configuration.md
  • eventrecorder/cloudflare_pipelines.go
  • eventrecorder/cloudflare_pipelines_test.go
  • eventrecorder/config.go
  • eventrecorder/recorder.go
  • eventrecorder/webhook.go
  • eventrecorder/webhook_test.go

Comment thread eventrecorder/recorder.go Resolved
Comment thread eventrecorder/webhook_test.go Resolved
@siavashs
siavashs force-pushed the feat/cf-pipelines branch from 45d6b0e to 43f70af Compare July 17, 2026 11:55
@siavashs
siavashs marked this pull request as draft July 17, 2026 12:14
@siavashs
siavashs force-pushed the feat/cf-pipelines branch from 43f70af to 53cc6e8 Compare July 17, 2026 12:23
@siavashs siavashs changed the title feat(eventrecorder): add Cloudflare Pipelines eventrecorder: add optional webhook batching Jul 17, 2026
@siavashs
siavashs marked this pull request as ready for review July 17, 2026 12:24

@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 `@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

📥 Commits

Reviewing files that changed from the base of the PR and between 43f70af and 53cc6e8.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • config/config_test.go
  • docs/configuration.md
  • eventrecorder/recorder.go
  • eventrecorder/webhook.go
  • eventrecorder/webhook_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • eventrecorder/webhook.go

Comment thread eventrecorder/webhook_test.go Resolved
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]>
@siavashs
siavashs force-pushed the feat/cf-pipelines branch from 53cc6e8 to ac4bfcc Compare July 17, 2026 13:24
@siavashs
siavashs merged commit 75a001b into prometheus:main Jul 18, 2026
7 checks passed
@siavashs
siavashs deleted the feat/cf-pipelines branch July 18, 2026 10:16
@SoloJacobs SoloJacobs mentioned this pull request Aug 14, 2026
Exikle pushed a commit to Exikle/home-infra that referenced this pull request Nov 16, 2026
….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. [#&#8203;5332](prometheus/alertmanager#5332)
- \[FEATURE] Add optional templatable labels to alert routes. [#&#8203;5328](prometheus/alertmanager#5328)
- \[FEATURE] eventrecorder: Add inhibit rule names to `inhibition_muted_alert` events. [#&#8203;5315](prometheus/alertmanager#5315)
- \[FEATURE] eventrecorder: Add stdout output type. [#&#8203;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. [#&#8203;5406](prometheus/alertmanager#5406)
- \[FEATURE] sns: Add aws `external_id` support in sigv4 configuration. [#&#8203;5157](prometheus/alertmanager#5157)
- \[FEATURE] template: Add `toDate` and `mustToDate` functions. [#&#8203;5327](prometheus/alertmanager#5327)
- \[ENHANCEMENT] doc: Add AlertmanagerClusterFailedPeers alertmanager-mixin. [#&#8203;5301](prometheus/alertmanager#5301)
- \[ENHANCEMENT] doc: Add description for Rocketchat parameters in global config. [#&#8203;5181](prometheus/alertmanager#5181)
- \[ENHANCEMENT] doc: Add top level tracing configuration key. [#&#8203;5314](prometheus/alertmanager#5314)
- \[ENHANCEMENT] doc: Fix Alertmanager port in amtool config routes example. [#&#8203;5312](prometheus/alertmanager#5312)
- \[ENHANCEMENT] eventrecorder: Add optional webhook batching. [#&#8203;5392](prometheus/alertmanager#5392)
- \[ENHANCEMENT] notify: The discord and webex integrations now report a failure `reason` on `alertmanager_notifications_failed_total`. [#&#8203;5332](prometheus/alertmanager#5332)
- \[ENHANCEMENT] ui: Improve responsiveness of UI when loading thousands of alerts. [#&#8203;5357](prometheus/alertmanager#5357)
- \[BUGFIX] eventrecorder: Fixed a minor performance regression when the event recorder is enabled. [#&#8203;5307](prometheus/alertmanager#5307)
- \[BUGFIX] msteamsv2: Inherit global `proxy_url` into partial `http_config`. [#&#8203;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). [#&#8203;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
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.

3 participants