Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove timeDuration #81

Merged
merged 5 commits into from
Mar 21, 2023
Merged

Remove timeDuration #81

merged 5 commits into from
Mar 21, 2023

Conversation

endorama
Copy link
Member

@endorama endorama commented Mar 16, 2023

Following up on discussion in #62 this PR removes timeDuration helper function.

The same functionality is provided by sprig. This:

{{$startOffsetDuration := timeDuration $startOffsetInSecond}}

becomes

{{$startOffsetDuration := $startOffsetInSecond | int64 | duration}}

@endorama endorama force-pushed the remove-timeDuration branch from a16ae0a to f9a9010 Compare March 16, 2023 14:15
@endorama endorama marked this pull request as ready for review March 16, 2023 14:17
@endorama endorama requested a review from aspacca March 16, 2023 14:17
@endorama endorama self-assigned this Mar 16, 2023
@elasticmachine
Copy link

elasticmachine commented Mar 16, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-03-21T09:58:26.234+0000

  • Duration: 3 min 31 sec

Test stats 🧪

Test Results
Failed 0
Passed 65
Skipped 0
Total 65

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

{{- $startOffset := generate "StartOffset" }}
{{- $startOffsetInSecond := mul -1 1000000000 $startOffset }}
{{- $startOffsetDuration := $startOffsetInSecond | int64 | duration}}
Copy link
Contributor

Choose a reason for hiding this comment

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

$startOffsetInSecond was indeed $startOffsetInNanosecond (my bad :))
$startOffset was multiplied 1000000000 because our timeDuration expected nanoseconds, duration from sprig expects seconds: so we need to use directly the value in $startOffset (still multiplied by -1 since we want to subtract the value) is already the correct one.
Not sure if you prefer a oneliner or not, but this might work as well:

{{- $start := mul -1 $startOffset | int64 | duration | $end.Add }}

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for noticing, I completely missed that.
I updated the template.

Copy link
Contributor

Choose a reason for hiding this comment

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

my oneliner was wrong:
time.Time.Add takes a time.Duration, but duration returns a string, so we must use dateModify from sprig

{{- $start := $end | dateModify  (mul -1 $startOffset | int64 | duration) }}

todo: let's add to CI to generate at least one event for all the templates

@endorama endorama requested a review from aspacca March 20, 2023 15:45
@endorama endorama merged commit 8961f05 into elastic:main Mar 21, 2023
@endorama endorama deleted the remove-timeDuration branch March 21, 2023 10:09
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.

3 participants