Skip to content

fix: strip timezone information from a date in dau response #11962

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 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix unit tests
  • Loading branch information
Emyrk committed Jan 31, 2024
commit 033fd4e4402383d7b60e5c8ca53d63a1d19c1555
6 changes: 5 additions & 1 deletion coderd/metricscache/metricscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"github.com/coder/retry"
)

func OnlyDate(t time.Time) string {
return t.Format("2006-01-02")
}

// deploymentTimezoneOffsets are the timezones that are cached and supported.
// Any non-listed timezone offsets will need to use the closest supported one.
var deploymentTimezoneOffsets = []int{
Expand Down Expand Up @@ -168,7 +172,7 @@ func convertDAUResponse[T dauRow](rows []T, tzOffset int) codersdk.DAUsResponse
resp.Entries = append(resp.Entries, codersdk.DAUEntry{
// This date is truncated to 00:00:00 of the given day, so only
// return date information.
Date: date.Format("2006-01-02"),
Date: OnlyDate(date),
Amount: len(respMap[date]),
})
}
Expand Down
38 changes: 19 additions & 19 deletions coderd/metricscache/metricscache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ func TestCache_TemplateUsers(t *testing.T) {
},
tplWant: want{[]codersdk.DAUEntry{
{
Date: date(2022, 8, 27),
Date: metricscache.OnlyDate(date(2022, 8, 27)),
Amount: 1,
},
{
Date: date(2022, 8, 28),
Date: metricscache.OnlyDate(date(2022, 8, 28)),
Amount: 0,
},
{
Date: date(2022, 8, 29),
Date: metricscache.OnlyDate(date(2022, 8, 29)),
Amount: 0,
},
{
Date: date(2022, 8, 30),
Date: metricscache.OnlyDate(date(2022, 8, 30)),
Amount: 1,
},
}, 1},
Expand All @@ -95,15 +95,15 @@ func TestCache_TemplateUsers(t *testing.T) {
},
tplWant: want{[]codersdk.DAUEntry{
{
Date: date(2022, 8, 27),
Date: metricscache.OnlyDate(date(2022, 8, 27)),
Amount: 1,
},
{
Date: date(2022, 8, 28),
Date: metricscache.OnlyDate(date(2022, 8, 28)),
Amount: 1,
},
{
Date: date(2022, 8, 29),
Date: metricscache.OnlyDate(date(2022, 8, 29)),
Amount: 1,
},
}, 1},
Expand All @@ -121,31 +121,31 @@ func TestCache_TemplateUsers(t *testing.T) {
},
tplWant: want{[]codersdk.DAUEntry{
{
Date: date(2022, 1, 1),
Date: metricscache.OnlyDate(date(2022, 1, 1)),
Amount: 2,
},
{
Date: date(2022, 1, 2),
Date: metricscache.OnlyDate(date(2022, 1, 2)),
Amount: 0,
},
{
Date: date(2022, 1, 3),
Date: metricscache.OnlyDate(date(2022, 1, 3)),
Amount: 0,
},
{
Date: date(2022, 1, 4),
Date: metricscache.OnlyDate(date(2022, 1, 4)),
Amount: 1,
},
{
Date: date(2022, 1, 5),
Date: metricscache.OnlyDate(date(2022, 1, 5)),
Amount: 0,
},
{
Date: date(2022, 1, 6),
Date: metricscache.OnlyDate(date(2022, 1, 6)),
Amount: 0,
},
{
Date: date(2022, 1, 7),
Date: metricscache.OnlyDate(date(2022, 1, 7)),
Amount: 2,
},
}, 2},
Expand All @@ -164,17 +164,17 @@ func TestCache_TemplateUsers(t *testing.T) {
},
tplWant: want{[]codersdk.DAUEntry{
{
Date: date(2022, 1, 2),
Date: metricscache.OnlyDate(date(2022, 1, 2)),
Amount: 2,
},
}, 2},
dauWant: []codersdk.DAUEntry{
{
Date: date(2022, 1, 1),
Date: metricscache.OnlyDate(date(2022, 1, 1)),
Amount: 2,
},
{
Date: date(2022, 1, 2),
Date: metricscache.OnlyDate(date(2022, 1, 2)),
Amount: 2,
},
},
Expand All @@ -192,13 +192,13 @@ func TestCache_TemplateUsers(t *testing.T) {
},
dauWant: []codersdk.DAUEntry{
{
Date: date(2022, 1, 1),
Date: metricscache.OnlyDate(date(2022, 1, 1)),
Amount: 2,
},
},
tplWant: want{[]codersdk.DAUEntry{
{
Date: date(2022, 1, 2),
Date: metricscache.OnlyDate(date(2022, 1, 2)),
Amount: 2,
},
}, 2},
Expand Down