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

@locker95 locker95 commented Jul 22, 2026

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

Notes from review discussion

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

📝 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
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.
Title check ✅ Passed The title is concise, follows the required area: description format, and clearly reflects the exported GroupKey change.
Description check ✅ Passed The description matches the template well, includes the checklist, a clear summary, and release notes for the user-facing change.
✨ 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.

@locker95

Copy link
Copy Markdown
Author

@TheMeier Thanks for the notes — agreed on both points:

  1. Custom webhook payload templates still won't see GroupKey until something like notify.DeepCopyWithTemplate edge cases #5012 / renderPayload wiring lands; this PR only exposes it on template.Data for the existing Go template path (email, etc.).
  2. Non-uniqueness of groupKey (How to fix non unique GroupKeys? #3817) is pre-existing; this change just surfaces the value the dispatcher already uses, it doesn't claim global uniqueness.

I'll leave both caveats in mind if we extend this further (e.g. webhook payload). Happy to mention them in the PR description if useful.

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