Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc795a0e

Browse files
authored
feat: Fix Deployment DAUs to work with local timezones (#7647)
* chore: Add timezone param to DAU SQL query* Merge DAUs response* Pass time offsets to metricscache
1 parent68658b5 commitc795a0e

File tree

29 files changed

+601
-305
lines changed

29 files changed

+601
-305
lines changed

‎coderd/apidoc/docs.go

Lines changed: 16 additions & 24 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 16 additions & 24 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbauthz/system.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,19 @@ func (q *querier) GetTemplateAverageBuildTime(ctx context.Context, arg database.
205205
}
206206

207207
// Only used by metrics cache.
208-
func (q*querier)GetTemplateDAUs(ctx context.Context,templateID uuid.UUID) ([]database.GetTemplateDAUsRow,error) {
208+
func (q*querier)GetTemplateDAUs(ctx context.Context,arg database.GetTemplateDAUsParams) ([]database.GetTemplateDAUsRow,error) {
209209
iferr:=q.authorizeContext(ctx,rbac.ActionRead,rbac.ResourceSystem);err!=nil {
210210
returnnil,err
211211
}
212-
returnq.db.GetTemplateDAUs(ctx,templateID)
212+
returnq.db.GetTemplateDAUs(ctx,arg)
213213
}
214214

215215
// Only used by metrics cache.
216-
func (q*querier)GetDeploymentDAUs(ctx context.Context) ([]database.GetDeploymentDAUsRow,error) {
216+
func (q*querier)GetDeploymentDAUs(ctx context.Context,tzOffsetint32) ([]database.GetDeploymentDAUsRow,error) {
217217
iferr:=q.authorizeContext(ctx,rbac.ActionRead,rbac.ResourceSystem);err!=nil {
218218
returnnil,err
219219
}
220-
returnq.db.GetDeploymentDAUs(ctx)
220+
returnq.db.GetDeploymentDAUs(ctx,tzOffset)
221221
}
222222

223223
// UpdateWorkspaceBuildCostByID is used by the provisioning system to update the cost of a workspace build.

‎coderd/database/dbfake/databasefake.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,21 +435,21 @@ func (q *fakeQuerier) InsertWorkspaceAgentStat(_ context.Context, p database.Ins
435435
returnstat,nil
436436
}
437437

438-
func (q*fakeQuerier)GetTemplateDAUs(_ context.Context,templateID uuid.UUID) ([]database.GetTemplateDAUsRow,error) {
438+
func (q*fakeQuerier)GetTemplateDAUs(_ context.Context,arg database.GetTemplateDAUsParams) ([]database.GetTemplateDAUsRow,error) {
439439
q.mutex.RLock()
440440
deferq.mutex.RUnlock()
441441

442442
seens:=make(map[time.Time]map[uuid.UUID]struct{})
443443

444444
for_,as:=rangeq.workspaceAgentStats {
445-
ifas.TemplateID!=templateID {
445+
ifas.TemplateID!=arg.TemplateID {
446446
continue
447447
}
448448
ifas.ConnectionCount==0 {
449449
continue
450450
}
451451

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

454454
dateEntry:=seens[date]
455455
ifdateEntry==nil {
@@ -478,7 +478,7 @@ func (q *fakeQuerier) GetTemplateDAUs(_ context.Context, templateID uuid.UUID) (
478478
returnrs,nil
479479
}
480480

481-
func (q*fakeQuerier)GetDeploymentDAUs(_ context.Context) ([]database.GetDeploymentDAUsRow,error) {
481+
func (q*fakeQuerier)GetDeploymentDAUs(_ context.Context,tzOffsetint32) ([]database.GetDeploymentDAUsRow,error) {
482482
q.mutex.RLock()
483483
deferq.mutex.RUnlock()
484484

@@ -488,7 +488,7 @@ func (q *fakeQuerier) GetDeploymentDAUs(_ context.Context) ([]database.GetDeploy
488488
ifas.ConnectionCount==0 {
489489
continue
490490
}
491-
date:=as.CreatedAt.Truncate(time.Hour*24)
491+
date:=as.CreatedAt.UTC().Add(time.Duration(tzOffset)*time.Hour).Truncate(time.Hour*24)
492492

493493
dateEntry:=seens[date]
494494
ifdateEntry==nil {

‎coderd/database/dbmock/store.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/workspaceagentstats.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ VALUES
2424

2525
-- name: GetTemplateDAUs :many
2626
SELECT
27-
(created_at atTIME ZONE'UTC')::dateasdate,
27+
(created_at atTIME ZONEcast(@tz_offset::integerastext))::dateasdate,
2828
user_id
2929
FROM
3030
workspace_agent_stats
@@ -38,7 +38,7 @@ ORDER BY
3838

3939
-- name: GetDeploymentDAUs :many
4040
SELECT
41-
(created_at atTIME ZONE'UTC')::dateasdate,
41+
(created_at atTIME ZONEcast(@tz_offset::integerastext))::dateasdate,
4242
user_id
4343
FROM
4444
workspace_agent_stats

‎coderd/insights.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// @Security CoderSessionToken
1414
// @Produce json
1515
// @Tags Insights
16-
// @Success 200 {object} codersdk.DeploymentDAUsResponse
16+
// @Success 200 {object} codersdk.DAUsResponse
1717
// @Router /insights/daus [get]
1818
func (api*API)deploymentDAUs(rw http.ResponseWriter,r*http.Request) {
1919
ctx:=r.Context()
@@ -22,9 +22,21 @@ func (api *API) deploymentDAUs(rw http.ResponseWriter, r *http.Request) {
2222
return
2323
}
2424

25-
resp,_:=api.metricsCache.DeploymentDAUs()
25+
vals:=r.URL.Query()
26+
p:=httpapi.NewQueryParamParser()
27+
tzOffset:=p.Int(vals,0,"tz_offset")
28+
p.ErrorExcessParams(vals)
29+
iflen(p.Errors)>0 {
30+
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{
31+
Message:"Query parameters have invalid values.",
32+
Validations:p.Errors,
33+
})
34+
return
35+
}
36+
37+
_,resp,_:=api.metricsCache.DeploymentDAUs(tzOffset)
2638
ifresp==nil||resp.Entries==nil {
27-
httpapi.Write(ctx,rw,http.StatusOK,&codersdk.DeploymentDAUsResponse{
39+
httpapi.Write(ctx,rw,http.StatusOK,&codersdk.DAUsResponse{
2840
Entries: []codersdk.DAUEntry{},
2941
})
3042
return

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp