Skip to content

fix(coderd): humanize duration on notifications #14333

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

Merged
merged 4 commits into from
Aug 19, 2024

Conversation

BrunoQuaresma
Copy link
Collaborator

Close #14325

I added tests for the Humanize function, but we might want to consider adding snapshot tests for the notifications in the near future.

Since these tests would require a database (as the templates are stored there), it can be challenging to update the golden files locally with our current test setup. I’m wondering if we should start considering the use of an embedded database for some tests. 🤔

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

Almost there, please address CI issues.

Comment on lines 9 to 11
func Humanize(d time.Duration) string {
endTime := time.Now().Add(d)
return humanize.Time(endTime)
Copy link
Contributor

Choose a reason for hiding this comment

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

Given this is only used in two places, I'm not convinced we need any indirection in front of humanize.Time; we should just use it directly.

If we were using this very broadly, I could see some value is hiding this behind our own interface so we could swap out the underlying implementation, but I don't think we're there yet.

Copy link
Member

Choose a reason for hiding this comment

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

Happy you noticed this to reduce abstraction!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

100%, I was just too lazy to remove the first abstraction I added. My bad 🙏

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

Couple minor thoughts but LGTM!

@@ -323,14 +324,15 @@ func (e *Executor) runOnce(t time.Time) Stats {
}
}
if shouldNotifyDormancy {
dormantTime := time.Now().Add(time.Duration(tmpl.TimeTilDormant))
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing to check: is the dormancy value in the database in UTC? If so, the timezone of the control plane might make things weird and we may want to add a .UTC() call in here too or use dbtime.Now()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good to know

@@ -691,7 +691,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
"reason": "breached the template's threshold for inactivity",
"initiator": "autobuild",
"dormancyHours": "24",
"timeTilDormant": "24h",
"timeTilDormant": "24 hours",
Copy link
Contributor

Choose a reason for hiding this comment

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

A test which includes not such a round number would also be helpful for illustrative purposes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

@BrunoQuaresma BrunoQuaresma merged commit 10327fb into main Aug 19, 2024
27 checks passed
@BrunoQuaresma BrunoQuaresma deleted the bq/fix-dormant-notification branch August 19, 2024 18:49
@github-actions github-actions bot locked and limited conversation to collaborators Aug 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Humanize the duration time in the dormant notification email
3 participants