Skip to content

feat(coderd): support weekly aggregated insights #9684

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 16 commits into from
Sep 19, 2023
Prev Previous commit
Next Next commit
fix six days
  • Loading branch information
mtojek committed Sep 18, 2023
commit 01a1ad8d8be9a5082c821cfda7077ad5203b79df
4 changes: 3 additions & 1 deletion coderd/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,5 +563,7 @@ func lastReportIntervalHasAtLeastSixDays(startTime, endTime time.Time) bool {
if lastReportIntervalDays == 0 {
return true // this is a perfectly full week!
}
return lastReportIntervalDays >= 6*24*time.Hour
// Ensure that the last interval has at least 6 days, or check the special case, forward DST change,
// when the duration can be shorter than 6 days: 5 days 23 hours.
return lastReportIntervalDays >= 6*24*time.Hour || startTime.AddDate(0, 0, 6).Equal(endTime)
}
4 changes: 2 additions & 2 deletions coderd/insights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,12 +814,12 @@ func TestTemplateInsights_Golden(t *testing.T) {
startedAt: frozenWeekAgo.AddDate(0, 0, -12),
endedAt: frozenWeekAgo.AddDate(0, 0, -12).Add(time.Hour),
sessionCountSSH: 1,
sessionCountReconnectingPTY: 0,
sessionCountReconnectingPTY: 1,
},
{ // Another one hour of usage, but "active users" shouldn't be increased twice.
startedAt: frozenWeekAgo.AddDate(0, 0, -10),
endedAt: frozenWeekAgo.AddDate(0, 0, -10).Add(time.Hour),
sessionCountSSH: 0,
sessionCountSSH: 1,
sessionCountReconnectingPTY: 1,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"display_name": "Web Terminal",
"slug": "reconnecting-pty",
"icon": "/icon/terminal.svg",
"seconds": 3600
"seconds": 7200
},
{
"template_ids": [
Expand All @@ -45,7 +45,7 @@
"display_name": "SSH",
"slug": "ssh",
"icon": "/icon/terminal.svg",
"seconds": 7200
"seconds": 10800
},
{
"template_ids": [
Expand Down