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

chore: Revert to only using 1 timezone support for template DAUs#7721

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 2 commits intomainfromstevenmasley/template_daus
May 30, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
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
17 changes: 13 additions & 4 deletionscoderd/metricscache/metricscache.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,14 +21,23 @@ import (
"github.com/coder/retry"
)

//timezoneOffsets are the timezones that are cached and supported.
//deploymentTimezoneOffsets are the timezones that are cached and supported.
// Any non-listed timezone offsets will need to use the closest supported one.
vartimezoneOffsets = []int{
vardeploymentTimezoneOffsets = []int{
0, // UTC - is listed first intentionally.
-12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
}

// templateTimezoneOffsets are the timezones each template will use for it's DAU
// calculations. This is expensive as each template needs to do each timezone, so keep this list
// very small.
var templateTimezoneOffsets = []int{
// Only do one for now. If people request more accurate template DAU, we can
// fix this. But it adds too much cost, so optimization is needed first.
0, // UTC - is listed first intentionally.
}

// Cache holds the template metrics.
// The aggregation queries responsible for these values can take up to a minute
// on large deployments. Even in small deployments, aggregation queries can
Expand DownExpand Up@@ -166,7 +175,7 @@ func (c *Cache) refreshDeploymentDAUs(ctx context.Context) error {
ctx = dbauthz.AsSystemRestricted(ctx)

deploymentDAUs := make(map[int]codersdk.DAUsResponse)
for _, tzOffset := rangetimezoneOffsets {
for _, tzOffset := rangedeploymentTimezoneOffsets {
rows, err := c.database.GetDeploymentDAUs(ctx, int32(tzOffset))
if err != nil {
return err
Expand DownExpand Up@@ -199,7 +208,7 @@ func (c *Cache) refreshTemplateDAUs(ctx context.Context) error {
}

for _, template := range templates {
for _, tzOffset := rangetimezoneOffsets {
for _, tzOffset := rangetemplateTimezoneOffsets {
rows, err := c.database.GetTemplateDAUs(ctx, database.GetTemplateDAUsParams{
TemplateID: template.ID,
TzOffset: int32(tzOffset),
Expand Down
47 changes: 34 additions & 13 deletionscoderd/metricscache/metricscache_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,12 +48,14 @@ func TestCache_TemplateUsers(t *testing.T) {
uniqueUsers int
}
tests := []struct {
name string
args args
want want
name string
args args
tplWant want
// dauWant is optional
dauWant []codersdk.DAUEntry
tzOffset int
}{
{name: "empty", args: args{},want: want{nil, 0}},
{name: "empty", args: args{},tplWant: want{nil, 0}},
{
name: "one hole",
args: args{
Expand All@@ -62,7 +64,7 @@ func TestCache_TemplateUsers(t *testing.T) {
statRow(zebra, dateH(2022, 8, 30, 0)),
},
},
want: want{[]codersdk.DAUEntry{
tplWant: want{[]codersdk.DAUEntry{
{
Date: date(2022, 8, 27),
Amount: 1,
Expand DownExpand Up@@ -90,7 +92,7 @@ func TestCache_TemplateUsers(t *testing.T) {
statRow(zebra, dateH(2022, 8, 29, 0)),
},
},
want: want{[]codersdk.DAUEntry{
tplWant: want{[]codersdk.DAUEntry{
{
Date: date(2022, 8, 27),
Amount: 1,
Expand All@@ -116,7 +118,7 @@ func TestCache_TemplateUsers(t *testing.T) {
statRow(tiger, dateH(2022, 1, 7, 0)),
},
},
want: want{[]codersdk.DAUEntry{
tplWant: want{[]codersdk.DAUEntry{
{
Date: date(2022, 1, 1),
Amount: 2,
Expand DownExpand Up@@ -159,7 +161,13 @@ func TestCache_TemplateUsers(t *testing.T) {
statRow(tiger, dateH(2022, 1, 2, 0)),
},
},
want: want{[]codersdk.DAUEntry{
tplWant: want{[]codersdk.DAUEntry{
{
Date: date(2022, 1, 2),
Amount: 2,
},
}, 2},
dauWant: []codersdk.DAUEntry{
{
Date: date(2022, 1, 1),
Amount: 2,
Expand All@@ -168,7 +176,7 @@ func TestCache_TemplateUsers(t *testing.T) {
Date: date(2022, 1, 2),
Amount: 2,
},
}, 2},
},
},
{
name: "tzOffsetPreviousDay",
Expand All@@ -181,11 +189,17 @@ func TestCache_TemplateUsers(t *testing.T) {
statRow(tiger, dateH(2022, 1, 2, 0)),
},
},
want: want{[]codersdk.DAUEntry{
dauWant:[]codersdk.DAUEntry{
{
Date: date(2022, 1, 1),
Amount: 2,
},
},
tplWant: want{[]codersdk.DAUEntry{
{
Date: date(2022, 1, 2),
Amount: 2,
},
}, 2},
},
}
Expand DownExpand Up@@ -223,11 +237,18 @@ func TestCache_TemplateUsers(t *testing.T) {
gotUniqueUsers, ok := cache.TemplateUniqueUsers(template.ID)
require.True(t, ok)

if tt.dauWant != nil {
_, dauResponse, ok := cache.DeploymentDAUs(tt.tzOffset)
require.True(t, ok)
require.Equal(t, tt.dauWant, dauResponse.Entries)
}

offset, gotEntries, ok := cache.TemplateDAUs(template.ID, tt.tzOffset)
require.True(t, ok)
require.Equal(t, offset, tt.tzOffset)
require.Equal(t, tt.want.entries, gotEntries.Entries)
require.Equal(t, tt.want.uniqueUsers, gotUniqueUsers)
// Template only supports 0 offset.
require.Equal(t, 0, offset)
require.Equal(t, tt.tplWant.entries, gotEntries.Entries)
require.Equal(t, tt.tplWant.uniqueUsers, gotUniqueUsers)
})
}
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp