Skip to content

template: export GroupKey on template.Data#5400

Open
locker95 wants to merge 1 commit into
prometheus:mainfrom
locker95:template-export-groupkey
Open

template: export GroupKey on template.Data#5400
locker95 wants to merge 1 commit into
prometheus:mainfrom
locker95:template-export-groupkey

Conversation

@locker95

Copy link
Copy Markdown

Pull Request Checklist

  • Please list all open issue(s) discussed with maintainers related to this change
  • Is this a new Receiver integration?
    • N/A
  • Is this a bug fix?
    • I have added tests that can reproduce the bug which pass with this bug fix applied
  • Is this a new feature?
    • N/A (small API completeness fix)
  • Does this change affect performance?
    • N/A
  • 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

Summary

template.Data did not export GroupKey, even though the webhook JSON payload has always included groupKey. Webhook receivers that reuse template.Data (or custom templates that need the grouping key) had no way to access it without defining their own struct.

This change:

  1. Adds GroupKey to template.Data with JSON tag groupKey (matching the documented webhook field).
  2. Populates it from the notify context in GetTemplateData when a group key is present.
  3. Adds unit tests for population and template access via {{ .GroupKey }}.

The webhook Message type still sets its own GroupKey field for the wire format; Go's encoding/json prefers the outer field, so the payload is unchanged.

Which user-facing changes does this PR introduce?

[ENHANCEMENT] template: Export GroupKey on template.Data for templates and webhook-style consumers. #2526

The webhook payload has always included groupKey, but template.Data did
not, so templates and receivers reusing Data could not access it.

Add GroupKey to template.Data and populate it from the notify context in
GetTemplateData.

Fixes prometheus#2526

Signed-off-by: Dean Chen <862469039@qq.com>
@locker95
locker95 requested a review from a team as a code owner July 22, 2026 07:57
@coderabbitai

coderabbitai Bot commented Jul 22, 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: 29dc9ed3-d31b-4a5a-beaf-79b75e3a23e6

📥 Commits

Reviewing files that changed from the base of the PR and between 949777a and 4979805.

📒 Files selected for processing (3)
  • notify/util.go
  • notify/util_test.go
  • template/template.go

📝 Walkthrough

Walkthrough

Adds GroupKey to template data, populates it from notification context, and tests propagation, template access, JSON naming, and empty behavior when absent.

Changes

GroupKey propagation

Layer / File(s) Summary
Template data contract
template/template.go
Adds the exported Data.GroupKey field with json:"groupKey" serialization.
Context propagation and validation
notify/util.go, notify/util_test.go
Copies an available context group key into template data and tests propagation, template access, and missing-key behavior.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes exporting GroupKey on template.Data.
Description check ✅ Passed The PR description includes the checklist, summary, issue reference, and release notes, and is mostly complete.
Linked Issues check ✅ Passed The change exports GroupKey and populates it in template.Data, matching issue #2526's request.
Out of Scope Changes check ✅ Passed The diff stays focused on template.Data, notify propagation, and tests, with no unrelated changes evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@TheMeier

Copy link
Copy Markdown
Contributor

Just for the record:
one will not be able to use it in custom webhook payload templates see #5012. This could be mitigated by custom handling in renderPayload

Also the groupKey is not unique #3817.

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.

template.Data does not export GroupKey

2 participants