Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

feat: add timedeltaparse function to the jinja template#5142

Merged
joeyorlando merged 4 commits into
devfrom
kelnage/time-delta-parse-jinja
Oct 9, 2024
Merged

feat: add timedeltaparse function to the jinja template#5142
joeyorlando merged 4 commits into
devfrom
kelnage/time-delta-parse-jinja

Conversation

@kelnage
Copy link
Copy Markdown
Contributor

@kelnage kelnage commented Oct 9, 2024

What this PR does

If an OnCall template needs to contain a date relative to a date in the alert response, currently there is no way for the template to add or subtract time from a parsed date.

This PR adds a function that allows a time-window (e.g., 1s, 5m, 6h, 7d, 2w) to be converted into a Python timedelta, which can then be added or subtracted from a datetime. An example usage might be:

{% set delta = alert.timeWindow | timedeltaparse %}
{% set time = alert.startsAt | iso8601_to_time - delta | datetimeformat('%s') %}

Checklist

  • Unit, integration, and e2e (if applicable) tests updated
  • Documentation added (or pr:no public docs PR label added if not required)
  • Added the relevant release notes label (see labels prefixed w/ release:). These labels dictate how your PR will show up in the autogenerated release notes.

If an OnCall template needs to contain a date relative to a date in the
alert response, currently there is no way for the template to add or
subtract time from a parsed date.

This PR adds a function that allows a time-window (1s, 5m, 6h, 7d, 2w)
to be converted into a Python timedelta, which can then be added or
subtracted from a datetime. An example usage might be:

```
{% set delta = alert.timeWindow | timedeltaparse %}
{% set time = alert.startsAt | iso8601_to_time - delta | datetimeformat('%s') %}
```
@kelnage kelnage added the release:enhancement PR will be added to "Exciting New Features 🎉" section of release notes label Oct 9, 2024
@kelnage kelnage self-assigned this Oct 9, 2024
@kelnage kelnage requested review from a team October 9, 2024 15:26
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Oct 9, 2024

CLA assistant check
All committers have signed the CLA.

@kelnage kelnage requested a review from a team as a code owner October 9, 2024 15:46
@kelnage kelnage requested a review from a team October 9, 2024 15:46
Copy link
Copy Markdown
Contributor

@joeyorlando joeyorlando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the contribution @kelnage!

@joeyorlando joeyorlando added this pull request to the merge queue Oct 9, 2024
Merged via the queue into dev with commit cf589d4 Oct 9, 2024
@joeyorlando joeyorlando deleted the kelnage/time-delta-parse-jinja branch October 9, 2024 18:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release:enhancement PR will be added to "Exciting New Features 🎉" section of release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants