Skip to content

webhook: custom payloads allow any type#5130

Merged
siavashs merged 1 commit intoprometheus:mainfrom
TheMeier:webhook_template
Mar 30, 2026
Merged

webhook: custom payloads allow any type#5130
siavashs merged 1 commit intoprometheus:mainfrom
TheMeier:webhook_template

Conversation

@TheMeier
Copy link
Copy Markdown
Contributor

@TheMeier TheMeier commented Mar 29, 2026

do not require payload top level to be a map
deepCopyWithTemplate can handle any type, so we
can allow users to specify any type of payload.
This allows for more flexibility in the payload
structure.

I have set CHANGELOG to NONE which is true if this goes in before the next release as this updates #5011 which is not released yet.

Pull Request Checklist

Please check all the applicable boxes.

Which user-facing changes does this PR introduce?

NONE

Summary by CodeRabbit

  • New Features

    • Webhook payloads now accept more flexible configuration types (any value), allowing lists, strings, and structured data to be templated and serialized consistently.
  • Tests

    • Expanded webhook payload tests to validate list, string, and map payload forms and ensure exact JSON serialization and inclusion of common metadata across formats.

@TheMeier TheMeier requested a review from a team as a code owner March 29, 2026 19:36
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e581135f-8958-4065-928a-0f2053107084

📥 Commits

Reviewing files that changed from the base of the PR and between 1407602 and 8375938.

📒 Files selected for processing (3)
  • config/notifiers.go
  • notify/webhook/webhook.go
  • notify/webhook/webhook_test.go
✅ Files skipped from review due to trivial changes (1)
  • notify/webhook/webhook_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • notify/webhook/webhook.go

📝 Walkthrough

Walkthrough

The PR changes webhook payload handling by making WebhookConfig.Payload an any (formerly map[string]any) and refactoring renderPayload to deep-copy-and-template the entire payload object. Tests were expanded to cover map, list, and string payload forms.

Changes

Cohort / File(s) Summary
Config Payload Flexibility
config/notifiers.go
Changed WebhookConfig.Payload field type from map[string]any to any while keeping yaml:"payload,omitempty" json:"payload,omitempty" tags.
Webhook Rendering Logic
notify/webhook/webhook.go
Reworked renderPayload to call template.DeepCopyWithTemplate on the whole n.conf.Payload instead of iterating and copying keys into a new map.
Webhook Test Coverage
notify/webhook/webhook_test.go
Replaced original payload test with TestWebhookCustomPayloadMap (map payload) and added TestWebhookCustomPayloadList, TestWebhookCustomPayloadStringList, and TestWebhookCustomPayloadString to validate list/string payloads and templating outcomes.

Sequence Diagram

sequenceDiagram
    participant Webhook as Webhook Notifier
    participant Config as Payload Config
    participant Template as Template Engine
    participant HTTP as HTTP Client

    Webhook->>Config: Read Payload (any)
    activate Config
    Config-->>Webhook: Return payload object
    deactivate Config

    Webhook->>Template: DeepCopyWithTemplate(payload)
    activate Template
    Template->>Template: Recursively render & template values
    Template-->>Webhook: Return rendered payload
    deactivate Template

    Webhook->>Webhook: Marshal rendered payload to JSON
    Webhook->>HTTP: POST JSON payload
    activate HTTP
    HTTP-->>Webhook: Response
    deactivate HTTP
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: allowing custom webhook payloads to use any type rather than requiring a map structure.
Description check ✅ Passed The description explains the feature, its rationale, testing status, and commit sign-offs. It mostly covers required checklist items for a new feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@notify/webhook/webhook_test.go`:
- Around line 375-380: The YAML unmarshal in the test currently ignores the
error; change the call to capture the returned error and assert it with
require.NoError(t, err) so test fixtures failing to parse fail the test. Locate
the yaml.Unmarshal call that fills the payload variable
(yaml.Unmarshal([]byte(...), &payload)), store its error (err :=
yaml.Unmarshal(...)) and replace the ignored result with require.NoError(t, err)
using the existing testing variable t.
🪄 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

Run ID: 34bb2cfb-be7e-469f-87cb-010860cfcb80

📥 Commits

Reviewing files that changed from the base of the PR and between 4aac704 and 1407602.

📒 Files selected for processing (3)
  • config/notifiers.go
  • notify/webhook/webhook.go
  • notify/webhook/webhook_test.go

do not require payload top level to be a map
deepCopyWithTemplate can handle any type, so we
can allow users to specify any type of payload.
This allows for more flexibility in the payload
structure.

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
@siavashs siavashs merged commit 4b3628f into prometheus:main Mar 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants