feat(template): Add addDuration template helper for time offsets - #5550
feat(template): Add addDuration template helper for time offsets#5550holger-waschke wants to merge 1 commit into
Conversation
Signed-off-by: Holger Waschke <holger.waschke@dvag.com>
a729d96 to
c1fbbad
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe template package adds an ChangesTemplate duration support
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: 🟡 Moderate · up to Templates using standard pipeline syntax may fail to render when calling the new timestamp-shifting helper. Correct the argument handling and add a pipeline regression test before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description explains the purpose, motivation, implementation changes, usage example, and tests. However, it omits the required Pull Request Checklist, issue information, documentation and sign-off confirmations, best-practices confirmation, and release-notes section. Resolution Add the required Pull Request Checklist with all applicable boxes marked, list related issues or state that none apply, provide the required documentation and sign-off confirmations, and complete the release-notes block with NONE or an appropriate user-facing entry.
✨ 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 |
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