template: export GroupKey on template.Data - #5400
Conversation
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>
📝 WalkthroughWalkthroughAdds ChangesGroupKey propagation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Just for the record: Also the groupKey is not unique #3817. |
|
@TheMeier Thanks for the notes — agreed on both points:
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. |
Pull Request Checklist
Summary
template.Datadid not exportGroupKey, even though the webhook JSON payload has always includedgroupKey. Webhook receivers that reusetemplate.Data(or custom templates that need the grouping key) had no way to access it without defining their own struct.This change:
GroupKeytotemplate.Datawith JSON taggroupKey(matching the documented webhook field).GetTemplateDatawhen a group key is present.{{ .GroupKey }}.The webhook
Messagetype still sets its ownGroupKeyfield 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?
Notes from review discussion
GroupKeyuntil something like notify.DeepCopyWithTemplate edge cases #5012 (orrenderPayloadwiring) lands; this PR only exposes it ontemplate.Datafor the existing Go template path.groupKeyis not globally unique (How to fix non unique GroupKeys? #3817); this change surfaces the dispatcher value as-is and does not claim uniqueness.