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.
This commit is contained in:
Colin Adler 2023-12-13 16:50:29 -06:00 committed by GitHub
parent a3432b4265
commit eb81fcf1e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions

View File

@ -6,12 +6,12 @@ import (
"net/http/httptest" "net/http/httptest"
"testing" "testing"
"cdr.dev/slog"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"cdr.dev/slog"
"github.com/coder/coder/v2/coderd/coderdtest" "github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/coderd/database" "github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbauthz" "github.com/coder/coder/v2/coderd/database/dbauthz"

View File

@ -26,8 +26,14 @@ import (
// Any non-listed timezone offsets will need to use the closest supported one. // Any non-listed timezone offsets will need to use the closest supported one.
var deploymentTimezoneOffsets = []int{ var deploymentTimezoneOffsets = []int{
0, // UTC - is listed first intentionally. 0, // UTC - is listed first intentionally.
-12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, // Shortened list of 4 timezones that should encompass *most* users. Caching
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, // all 25 timezones can be too computationally expensive for large
// deployments. This is a stop-gap until more robust fixes can be made for
// the deployment DAUs query.
-6, 3, 6, 10,
// -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 // templateTimezoneOffsets are the timezones each template will use for it's DAU

View File

@ -152,11 +152,11 @@ func TestCache_TemplateUsers(t *testing.T) {
}, },
{ {
name: "tzOffset", name: "tzOffset",
tzOffset: 1, tzOffset: 3,
args: args{ args: args{
rows: []database.InsertWorkspaceAgentStatParams{ rows: []database.InsertWorkspaceAgentStatParams{
statRow(zebra, dateH(2022, 1, 2, 1)), statRow(zebra, dateH(2022, 1, 2, 3)),
statRow(tiger, dateH(2022, 1, 2, 1)), statRow(tiger, dateH(2022, 1, 2, 3)),
// With offset these should be in the previous day // With offset these should be in the previous day
statRow(zebra, dateH(2022, 1, 2, 0)), statRow(zebra, dateH(2022, 1, 2, 0)),
statRow(tiger, dateH(2022, 1, 2, 0)), statRow(tiger, dateH(2022, 1, 2, 0)),

View File

@ -1630,7 +1630,7 @@ when required by your organization's security policy.`,
Flag: "metrics-cache-refresh-interval", Flag: "metrics-cache-refresh-interval",
Env: "CODER_METRICS_CACHE_REFRESH_INTERVAL", Env: "CODER_METRICS_CACHE_REFRESH_INTERVAL",
Hidden: true, Hidden: true,
Default: time.Hour.String(), Default: (4 * time.Hour).String(),
Value: &c.MetricsCacheRefreshInterval, Value: &c.MetricsCacheRefreshInterval,
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"), Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
}, },