feat(template): Add addDuration template helper for time offsets - #5550
holger-waschke wants to merge 2 commits into
Conversation
a729d96 to
c1fbbad
Compare
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: prometheus/alertmanager/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe template package adds an ChangesTemplate behavior updates
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The helper adds duration offsets for template-generated links and reports invalid durations safely. Current evidence supports merging. 🚥 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 |
|
So if you flip the args If I read the coderabbit comment correctly |
fluktuid
left a comment
There was a problem hiding this comment.
@TheMeier If I understand your comment correctly, this is how it should look for best compatibility.
@holger-waschke hope this helps
Signed-off-by: Holger Waschke <holger.waschke@dvag.com>
c760ea4 to
b28b549
Compare
Summary
Adds an addDuration helper function to Alertmanager templates. This allows templates to shift timestamps using Go duration strings (e.g., "-30m", "1h") and returns the resulting value as Unix milliseconds for direct use in links.
Why?
Before this change, achieving relative time windows required raw nanosecond arithmetic, which is hard to read and error-prone:
{{- $start := (.StartsAt.Add -1800000000000).UnixMilli -}} {{- $end := (.StartsAt.Add 3600000000000).UnixMilli -}}With addDuration, the same logic becomes much more expressive and maintainable:
{{- $start := (addDuration .StartsAt "-30m") -}} {{- $end := (addDuration .StartsAt "60m") -}} {{- $url := printf "https://app.checklyhq.com/checks/%s?startTime=%d&endTime=%d" .Labels.check_id $start $end -}} [Checkly Playwright Report|{{ $url }}]Changes