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

Commit73d795f

Browse files
authored
chore: Revert to only using 1 timezone support for template DAUs (#7721)
* chore: Revert to only using 1 timezone support for template DAUsKeeping the logic to support more in case we optimize later
1 parent022372d commit73d795f

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

‎coderd/metricscache/metricscache.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,23 @@ import (
2121
"github.com/coder/retry"
2222
)
2323

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

32+
// templateTimezoneOffsets are the timezones each template will use for it's DAU
33+
// calculations. This is expensive as each template needs to do each timezone, so keep this list
34+
// very small.
35+
vartemplateTimezoneOffsets= []int{
36+
// Only do one for now. If people request more accurate template DAU, we can
37+
// fix this. But it adds too much cost, so optimization is needed first.
38+
0,// UTC - is listed first intentionally.
39+
}
40+
3241
// Cache holds the template metrics.
3342
// The aggregation queries responsible for these values can take up to a minute
3443
// on large deployments. Even in small deployments, aggregation queries can
@@ -166,7 +175,7 @@ func (c *Cache) refreshDeploymentDAUs(ctx context.Context) error {
166175
ctx=dbauthz.AsSystemRestricted(ctx)
167176

168177
deploymentDAUs:=make(map[int]codersdk.DAUsResponse)
169-
for_,tzOffset:=rangetimezoneOffsets {
178+
for_,tzOffset:=rangedeploymentTimezoneOffsets {
170179
rows,err:=c.database.GetDeploymentDAUs(ctx,int32(tzOffset))
171180
iferr!=nil {
172181
returnerr
@@ -199,7 +208,7 @@ func (c *Cache) refreshTemplateDAUs(ctx context.Context) error {
199208
}
200209

201210
for_,template:=rangetemplates {
202-
for_,tzOffset:=rangetimezoneOffsets {
211+
for_,tzOffset:=rangetemplateTimezoneOffsets {
203212
rows,err:=c.database.GetTemplateDAUs(ctx, database.GetTemplateDAUsParams{
204213
TemplateID:template.ID,
205214
TzOffset:int32(tzOffset),

‎coderd/metricscache/metricscache_test.go

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ func TestCache_TemplateUsers(t *testing.T) {
4848
uniqueUsersint
4949
}
5050
tests:= []struct {
51-
namestring
52-
argsargs
53-
wantwant
51+
namestring
52+
argsargs
53+
tplWantwant
54+
// dauWant is optional
55+
dauWant []codersdk.DAUEntry
5456
tzOffsetint
5557
}{
56-
{name:"empty",args:args{},want:want{nil,0}},
58+
{name:"empty",args:args{},tplWant:want{nil,0}},
5759
{
5860
name:"one hole",
5961
args:args{
@@ -62,7 +64,7 @@ func TestCache_TemplateUsers(t *testing.T) {
6264
statRow(zebra,dateH(2022,8,30,0)),
6365
},
6466
},
65-
want:want{[]codersdk.DAUEntry{
67+
tplWant:want{[]codersdk.DAUEntry{
6668
{
6769
Date:date(2022,8,27),
6870
Amount:1,
@@ -90,7 +92,7 @@ func TestCache_TemplateUsers(t *testing.T) {
9092
statRow(zebra,dateH(2022,8,29,0)),
9193
},
9294
},
93-
want:want{[]codersdk.DAUEntry{
95+
tplWant:want{[]codersdk.DAUEntry{
9496
{
9597
Date:date(2022,8,27),
9698
Amount:1,
@@ -116,7 +118,7 @@ func TestCache_TemplateUsers(t *testing.T) {
116118
statRow(tiger,dateH(2022,1,7,0)),
117119
},
118120
},
119-
want:want{[]codersdk.DAUEntry{
121+
tplWant:want{[]codersdk.DAUEntry{
120122
{
121123
Date:date(2022,1,1),
122124
Amount:2,
@@ -159,7 +161,13 @@ func TestCache_TemplateUsers(t *testing.T) {
159161
statRow(tiger,dateH(2022,1,2,0)),
160162
},
161163
},
162-
want:want{[]codersdk.DAUEntry{
164+
tplWant:want{[]codersdk.DAUEntry{
165+
{
166+
Date:date(2022,1,2),
167+
Amount:2,
168+
},
169+
},2},
170+
dauWant: []codersdk.DAUEntry{
163171
{
164172
Date:date(2022,1,1),
165173
Amount:2,
@@ -168,7 +176,7 @@ func TestCache_TemplateUsers(t *testing.T) {
168176
Date:date(2022,1,2),
169177
Amount:2,
170178
},
171-
},2},
179+
},
172180
},
173181
{
174182
name:"tzOffsetPreviousDay",
@@ -181,11 +189,17 @@ func TestCache_TemplateUsers(t *testing.T) {
181189
statRow(tiger,dateH(2022,1,2,0)),
182190
},
183191
},
184-
want:want{[]codersdk.DAUEntry{
192+
dauWant:[]codersdk.DAUEntry{
185193
{
186194
Date:date(2022,1,1),
187195
Amount:2,
188196
},
197+
},
198+
tplWant:want{[]codersdk.DAUEntry{
199+
{
200+
Date:date(2022,1,2),
201+
Amount:2,
202+
},
189203
},2},
190204
},
191205
}
@@ -223,11 +237,18 @@ func TestCache_TemplateUsers(t *testing.T) {
223237
gotUniqueUsers,ok:=cache.TemplateUniqueUsers(template.ID)
224238
require.True(t,ok)
225239

240+
iftt.dauWant!=nil {
241+
_,dauResponse,ok:=cache.DeploymentDAUs(tt.tzOffset)
242+
require.True(t,ok)
243+
require.Equal(t,tt.dauWant,dauResponse.Entries)
244+
}
245+
226246
offset,gotEntries,ok:=cache.TemplateDAUs(template.ID,tt.tzOffset)
227247
require.True(t,ok)
228-
require.Equal(t,offset,tt.tzOffset)
229-
require.Equal(t,tt.want.entries,gotEntries.Entries)
230-
require.Equal(t,tt.want.uniqueUsers,gotUniqueUsers)
248+
// Template only supports 0 offset.
249+
require.Equal(t,0,offset)
250+
require.Equal(t,tt.tplWant.entries,gotEntries.Entries)
251+
require.Equal(t,tt.tplWant.uniqueUsers,gotUniqueUsers)
231252
})
232253
}
233254
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp