Skip to content

incident.io notifier: add metadata field with templating support - #5022

Open
leonore wants to merge 3 commits into
prometheus:mainfrom
incident-io:leo/incidentio-notifier-templating
Open

incident.io notifier: add metadata field with templating support#5022
leonore wants to merge 3 commits into
prometheus:mainfrom
incident-io:leo/incidentio-notifier-templating

Conversation

@leonore

@leonore leonore commented Feb 20, 2026

Copy link
Copy Markdown

Allow users to send custom key-value metadata with alerts, with full Go template rendering support (e.g. {{ .CommonLabels.severity }}). This mirrors the approach to the Opsgenie Details attribute.

Pull Request Checklist

Please check all the applicable boxes.

  • Please list all open issue(s) discussed with maintainers related to this change
    • There is no issue where this is formally requested, but it was mentioned here, and through other threads.
  • Is this a new Receiver integration?
  • Is this a bugfix?
    • I have added tests that can reproduce the bug which pass with this bugfix applied
  • Is this a new feature?
    • I have added tests that test the new feature's functionality
  • Does this change affect performance?
    • I have provided benchmarks comparison that shows performance is improved or is not degraded
      • You can use benchstat to compare benchmarks
    • I have added new benchmarks if required or requested by maintainers
  • Is this a breaking change?
    • My changes do not break the existing cluster messages
    • My changes do not break the existing api
  • I have added/updated the required documentation
  • I have signed-off my commits
  • I will follow best practices for contributing to this project

Which user-facing changes does this PR introduce?

[ENHANCEMENT] The incident.io notifier now supports metadata with templating. 

@leonore
leonore force-pushed the leo/incidentio-notifier-templating branch from 202f665 to 642f435 Compare February 20, 2026 17:11
@coderabbitai

coderabbitai Bot commented Apr 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: Pro Plus

Run ID: 00c4c918-5636-4c67-a142-09cab515e679

📥 Commits

Reviewing files that changed from the base of the PR and between 99fdc28 and 42a8780.

📒 Files selected for processing (1)
  • notify/incidentio/incidentio.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • notify/incidentio/incidentio.go

📝 Walkthrough

Walkthrough

This PR adds optional incident.io metadata configuration. Values are rendered with alert data and included in outgoing messages, with omission when unset and non-retryable errors for invalid templates.

Changes

Incident.io metadata field

Layer / File(s) Summary
Metadata configuration and payload contract
notify/incidentio/config.go, docs/configuration.md, notify/incidentio/incidentio.go
Adds the Metadata configuration field, documents the option, and adds an optional metadata field to outgoing messages.
Metadata rendering in Notify
notify/incidentio/incidentio.go
Renders configured metadata templates using alert data, includes the rendered map in the message, and returns a non-retryable error when rendering fails.
Metadata behavior validation
notify/incidentio/incidentio_test.go
Tests omitted, static, templated, and invalid metadata values.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Notifier
  participant TemplateEngine
  participant IncidentioAPI

  Caller->>Notifier: Notify(alert data)
  Notifier->>TemplateEngine: Render metadata templates
  TemplateEngine-->>Notifier: Rendered metadata or error
  Notifier->>IncidentioAPI: Send message with metadata
  Notifier-->>Caller: Return notification result
Loading

Estimated code review effort: 2 (Simple) | ~12 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately summarizes the main change: adding templated metadata to the incident.io notifier.
Description check ✅ Passed The description follows the template well, includes the checklist, notes tests and docs, and provides a release note 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.

@edds
edds force-pushed the leo/incidentio-notifier-templating branch from e3ef305 to c957a79 Compare April 17, 2026 14:26
@leonore
leonore marked this pull request as ready for review April 17, 2026 14:37
@leonore
leonore requested a review from a team as a code owner April 17, 2026 14:37

@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

🧹 Nitpick comments (1)
notify/incidentio/incidentio.go (1)

168-182: Optional: early-exit on template error.

Because notify.TmplText short-circuits after the first error, all subsequent tmpl(v) calls return empty strings that still get written into the metadata map. Since the function returns an error anyway the map is discarded, so this is purely cosmetic — but you can make intent clearer and skip wasted work by checking tmplErr inside the loop or returning immediately after the error check. Current behavior is safe.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@notify/incidentio/incidentio.go` around lines 168 - 182, The
metadata-templating code uses notify.TmplText which sets tmplErr on first error
but still calls tmpl(v) for every entry; change the logic in the metadata block
(variables tmplErr, tmpl, metadata, n.conf.Metadata, notify.TmplText) to check
tmplErr immediately before iterating (or check inside the loop and return on
error) so you stop calling tmpl(v) after an error — i.e., if tmplErr != nil
return the error (or skip/map only after confirming tmplErr==nil) to avoid
populating metadata with empty values after a template failure.
🤖 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/incidentio/incidentio_test.go`:
- Line 498: The tests are failing to compile because they construct URL values
with the nonexistent type config.URL; replace each occurrence (e.g., the
instances constructing URL for IncidentioConfig.URL) with the defined type
&amcommoncfg.URL{URL: u} so IncidentioConfig.URL receives a *amcommoncfg.URL;
update the four places that use &config.URL{URL: u} to &amcommoncfg.URL{URL: u}
and ensure the amcommoncfg import alias is present where the test references
IncidentioConfig and its URL field.

---

Nitpick comments:
In `@notify/incidentio/incidentio.go`:
- Around line 168-182: The metadata-templating code uses notify.TmplText which
sets tmplErr on first error but still calls tmpl(v) for every entry; change the
logic in the metadata block (variables tmplErr, tmpl, metadata, n.conf.Metadata,
notify.TmplText) to check tmplErr immediately before iterating (or check inside
the loop and return on error) so you stop calling tmpl(v) after an error — i.e.,
if tmplErr != nil return the error (or skip/map only after confirming
tmplErr==nil) to avoid populating metadata with empty values after a template
failure.
🪄 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: Pro Plus

Run ID: b2f4a9aa-7cc4-43d8-b445-3e284781603d

📥 Commits

Reviewing files that changed from the base of the PR and between dcbdc8c and c957a79.

📒 Files selected for processing (4)
  • config/notifiers.go
  • docs/configuration.md
  • notify/incidentio/incidentio.go
  • notify/incidentio/incidentio_test.go

Comment thread notify/incidentio/incidentio_test.go Outdated
@github-actions github-actions Bot added the stale label Jun 16, 2026
leonore and others added 2 commits July 9, 2026 14:48
Allow users to send custom key-value metadata with alerts, with full
Go template rendering support (e.g. {{ .CommonLabels.severity }}).

Signed-off-by: leo <leo@incident.io>
Signed-off-by: Edd Sowden <edd.sowden@incident.io>
@isaacseymour
isaacseymour force-pushed the leo/incidentio-notifier-templating branch from d117913 to 99fdc28 Compare July 9, 2026 13:50
@isaacseymour

Copy link
Copy Markdown
Contributor

👋 Hey, we'd love to get this improvement merged, and a bunch of our customers would appreciate it too. @siavashs / @Spaceman1701 any chance either of you have time to take a look at this? 🙏

Comment thread notify/incidentio/incidentio.go Outdated
Check the template error inside the render loop so we return as soon as
a metadata value fails to render, rather than continuing to call the
template function for the remaining entries after it has already errored.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Isaac Seymour <i.seymour@oxon.org>
@siavashs siavashs mentioned this pull request Jul 24, 2026
@github-actions github-actions Bot removed the stale label Aug 4, 2026
@SoloJacobs

Copy link
Copy Markdown
Contributor

Hi @isaacseymour ,

LGTM overall. Needs a rebase

could you say a word on what your use case is? How do your customers benefit? Phrase it from the user perspective, don't let the AI dictate (it's very bad knowing these kinds of things).

Kind regards

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.

5 participants