Skip to content

Commit cf8d2bc

Browse files
authored
feat: use tz_offset when doing deployment dau query (#7736)
* Have FE query correct tz_offset data
1 parent 555ea64 commit cf8d2bc

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

coderd/database/dbfake/databasefake.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func (q *fakeQuerier) GetTemplateDAUs(_ context.Context, arg database.GetTemplat
453453
continue
454454
}
455455

456-
date := as.CreatedAt.UTC().Add(time.Duration(arg.TzOffset) * time.Hour).Truncate(time.Hour * 24)
456+
date := as.CreatedAt.UTC().Add(time.Duration(arg.TzOffset) * time.Hour * -1).Truncate(time.Hour * 24)
457457

458458
dateEntry := seens[date]
459459
if dateEntry == nil {
@@ -492,7 +492,7 @@ func (q *fakeQuerier) GetDeploymentDAUs(_ context.Context, tzOffset int32) ([]da
492492
if as.ConnectionCount == 0 {
493493
continue
494494
}
495-
date := as.CreatedAt.UTC().Add(time.Duration(tzOffset) * time.Hour).Truncate(time.Hour * 24)
495+
date := as.CreatedAt.UTC().Add(time.Duration(tzOffset) * -1 * time.Hour).Truncate(time.Hour * 24)
496496

497497
dateEntry := seens[date]
498498
if dateEntry == nil {

coderd/metricscache/metricscache_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func TestCache_TemplateUsers(t *testing.T) {
151151
},
152152
{
153153
name: "tzOffset",
154-
tzOffset: -1,
154+
tzOffset: 1,
155155
args: args{
156156
rows: []database.InsertWorkspaceAgentStatParams{
157157
statRow(zebra, dateH(2022, 1, 2, 1)),
@@ -180,7 +180,7 @@ func TestCache_TemplateUsers(t *testing.T) {
180180
},
181181
{
182182
name: "tzOffsetPreviousDay",
183-
tzOffset: -6,
183+
tzOffset: 6,
184184
args: args{
185185
rows: []database.InsertWorkspaceAgentStatParams{
186186
statRow(zebra, dateH(2022, 1, 2, 1)),

site/src/api/api.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,11 @@ export const getTemplateDAUs = async (
831831
return response.data
832832
}
833833

834-
export const getDeploymentDAUs = async (): Promise<TypesGen.DAUsResponse> => {
835-
const response = await axios.get(`/api/v2/insights/daus`)
834+
export const getDeploymentDAUs = async (
835+
// Default to user's local timezone
836+
offset = new Date().getTimezoneOffset() / 60,
837+
): Promise<TypesGen.DAUsResponse> => {
838+
const response = await axios.get(`/api/v2/insights/daus?tz_offset=${offset}`)
836839
return response.data
837840
}
838841

site/src/xServices/deploymentConfig/deploymentConfigMachine.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ export const deploymentConfigMachine = createMachine(
6464
{
6565
services: {
6666
getDeploymentValues: getDeploymentValues,
67-
getDeploymentDAUs: getDeploymentDAUs,
67+
getDeploymentDAUs: async () => {
68+
return getDeploymentDAUs()
69+
},
6870
},
6971
actions: {
7072
assignDeploymentValues: assign({

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy