Skip to content

Commit eb81fcf

Browse files
authored
fix: lower amount of cached timezones for deployment daus (#11196)
Updates https://github.com/coder/customers/issues/384 This should help alleviate some pressure, but doesn't really fix the root cause. See above issue for more details.
1 parent a3432b4 commit eb81fcf

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

coderd/httpmw/workspaceagentparam_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"net/http/httptest"
77
"testing"
88

9-
"cdr.dev/slog"
109
"github.com/go-chi/chi/v5"
1110
"github.com/google/uuid"
1211
"github.com/stretchr/testify/require"
1312
"golang.org/x/xerrors"
1413

14+
"cdr.dev/slog"
1515
"github.com/coder/coder/v2/coderd/coderdtest"
1616
"github.com/coder/coder/v2/coderd/database"
1717
"github.com/coder/coder/v2/coderd/database/dbauthz"

coderd/metricscache/metricscache.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ import (
2626
// Any non-listed timezone offsets will need to use the closest supported one.
2727
var deploymentTimezoneOffsets = []int{
2828
0, // UTC - is listed first intentionally.
29-
-12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
30-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
29+
// Shortened list of 4 timezones that should encompass *most* users. Caching
30+
// all 25 timezones can be too computationally expensive for large
31+
// deployments. This is a stop-gap until more robust fixes can be made for
32+
// the deployment DAUs query.
33+
-6, 3, 6, 10,
34+
35+
// -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
36+
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
3137
}
3238

3339
// templateTimezoneOffsets are the timezones each template will use for it's DAU

coderd/metricscache/metricscache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ func TestCache_TemplateUsers(t *testing.T) {
152152
},
153153
{
154154
name: "tzOffset",
155-
tzOffset: 1,
155+
tzOffset: 3,
156156
args: args{
157157
rows: []database.InsertWorkspaceAgentStatParams{
158-
statRow(zebra, dateH(2022, 1, 2, 1)),
159-
statRow(tiger, dateH(2022, 1, 2, 1)),
158+
statRow(zebra, dateH(2022, 1, 2, 3)),
159+
statRow(tiger, dateH(2022, 1, 2, 3)),
160160
// With offset these should be in the previous day
161161
statRow(zebra, dateH(2022, 1, 2, 0)),
162162
statRow(tiger, dateH(2022, 1, 2, 0)),

codersdk/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ when required by your organization's security policy.`,
16301630
Flag: "metrics-cache-refresh-interval",
16311631
Env: "CODER_METRICS_CACHE_REFRESH_INTERVAL",
16321632
Hidden: true,
1633-
Default: time.Hour.String(),
1633+
Default: (4 * time.Hour).String(),
16341634
Value: &c.MetricsCacheRefreshInterval,
16351635
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
16361636
},

0 commit comments

Comments
 (0)