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

feat: Fix Deployment DAUs to work with local timezones#7647

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 18 commits intomainfromstevenmasley/dau_timezones
May 30, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
18 commits
Select commitHold shift + click to select a range
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
40 changes: 16 additions & 24 deletionscoderd/apidoc/docs.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

40 changes: 16 additions & 24 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

8 changes: 4 additions & 4 deletionscoderd/database/dbauthz/system.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -205,19 +205,19 @@ func (q *querier) GetTemplateAverageBuildTime(ctx context.Context, arg database.
}

// Only used by metrics cache.
func (q *querier) GetTemplateDAUs(ctx context.Context,templateID uuid.UUID) ([]database.GetTemplateDAUsRow, error) {
func (q *querier) GetTemplateDAUs(ctx context.Context,arg database.GetTemplateDAUsParams) ([]database.GetTemplateDAUsRow, error) {
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceSystem); err != nil {
return nil, err
}
return q.db.GetTemplateDAUs(ctx,templateID)
return q.db.GetTemplateDAUs(ctx,arg)
}

// Only used by metrics cache.
func (q *querier) GetDeploymentDAUs(ctx context.Context) ([]database.GetDeploymentDAUsRow, error) {
func (q *querier) GetDeploymentDAUs(ctx context.Context, tzOffset int32) ([]database.GetDeploymentDAUsRow, error) {
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceSystem); err != nil {
return nil, err
}
return q.db.GetDeploymentDAUs(ctx)
return q.db.GetDeploymentDAUs(ctx, tzOffset)
}

// UpdateWorkspaceBuildCostByID is used by the provisioning system to update the cost of a workspace build.
Expand Down
10 changes: 5 additions & 5 deletionscoderd/database/dbfake/databasefake.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -434,21 +434,21 @@ func (q *fakeQuerier) InsertWorkspaceAgentStat(_ context.Context, p database.Ins
return stat, nil
}

func (q *fakeQuerier) GetTemplateDAUs(_ context.Context,templateID uuid.UUID) ([]database.GetTemplateDAUsRow, error) {
func (q *fakeQuerier) GetTemplateDAUs(_ context.Context,arg database.GetTemplateDAUsParams) ([]database.GetTemplateDAUsRow, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

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

for _, as := range q.workspaceAgentStats {
if as.TemplateID !=templateID {
if as.TemplateID !=arg.TemplateID {
continue
}
if as.ConnectionCount == 0 {
continue
}

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

dateEntry := seens[date]
if dateEntry == nil {
Expand DownExpand Up@@ -477,7 +477,7 @@ func (q *fakeQuerier) GetTemplateDAUs(_ context.Context, templateID uuid.UUID) (
return rs, nil
}

func (q *fakeQuerier) GetDeploymentDAUs(_ context.Context) ([]database.GetDeploymentDAUsRow, error) {
func (q *fakeQuerier) GetDeploymentDAUs(_ context.Context, tzOffset int32) ([]database.GetDeploymentDAUsRow, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

Expand All@@ -487,7 +487,7 @@ func (q *fakeQuerier) GetDeploymentDAUs(_ context.Context) ([]database.GetDeploy
if as.ConnectionCount == 0 {
continue
}
date := as.CreatedAt.Truncate(time.Hour * 24)
date := as.CreatedAt.UTC().Add(time.Duration(tzOffset) * time.Hour).Truncate(time.Hour * 24)

dateEntry := seens[date]
if dateEntry == nil {
Expand Down
10 changes: 5 additions & 5 deletionscoderd/database/dbmock/store.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

4 changes: 2 additions & 2 deletionscoderd/database/querier.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

17 changes: 11 additions & 6 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

4 changes: 2 additions & 2 deletionscoderd/database/queries/workspaceagentstats.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ VALUES

-- name: GetTemplateDAUs :many
SELECT
(created_at at TIME ZONE'UTC')::date as date,
(created_at at TIME ZONEcast(@tz_offset::integer as text))::date as date,
user_id
FROM
workspace_agent_stats
Expand All@@ -38,7 +38,7 @@ ORDER BY

-- name: GetDeploymentDAUs :many
SELECT
(created_at at TIME ZONE'UTC')::date as date,
(created_at at TIME ZONEcast(@tz_offset::integer as text))::date as date,
user_id
FROM
workspace_agent_stats
Expand Down
18 changes: 15 additions & 3 deletionscoderd/insights.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,7 @@ import (
// @Security CoderSessionToken
// @Produce json
// @Tags Insights
// @Success 200 {object} codersdk.DeploymentDAUsResponse
// @Success 200 {object} codersdk.DAUsResponse
// @Router /insights/daus [get]
func (api *API) deploymentDAUs(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
Expand All@@ -22,9 +22,21 @@ func (api *API) deploymentDAUs(rw http.ResponseWriter, r *http.Request) {
return
}

resp, _ := api.metricsCache.DeploymentDAUs()
vals := r.URL.Query()
p := httpapi.NewQueryParamParser()
tzOffset := p.Int(vals, 0, "tz_offset")
p.ErrorExcessParams(vals)
if len(p.Errors) > 0 {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Query parameters have invalid values.",
Validations: p.Errors,
})
return
}

_, resp, _ := api.metricsCache.DeploymentDAUs(tzOffset)
if resp == nil || resp.Entries == nil {
httpapi.Write(ctx, rw, http.StatusOK, &codersdk.DeploymentDAUsResponse{
httpapi.Write(ctx, rw, http.StatusOK, &codersdk.DAUsResponse{
Entries: []codersdk.DAUEntry{},
})
return
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp