Skip to content

Commit 8929c89

Browse files
committed
Merge branch 'main' of github.com:coder/coder into dk/notification-docs
2 parents b2b6cd0 + 851df91 commit 8929c89

File tree

7 files changed

+37
-19
lines changed

7 files changed

+37
-19
lines changed

cli/cliutil/awscheck_internal_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestIPV4Check(t *testing.T) {
4141
},
4242
})
4343
}))
44+
t.Cleanup(srv.Close)
4445
ctx := testutil.Context(t, testutil.WaitShort)
4546
ranges, err := FetchAWSIPRanges(ctx, srv.URL)
4647
require.NoError(t, err)

cli/server_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ import (
4545
"github.com/coder/coder/v2/cli/config"
4646
"github.com/coder/coder/v2/coderd/coderdtest"
4747
"github.com/coder/coder/v2/coderd/database/dbtestutil"
48+
"github.com/coder/coder/v2/coderd/httpapi"
4849
"github.com/coder/coder/v2/coderd/telemetry"
4950
"github.com/coder/coder/v2/codersdk"
5051
"github.com/coder/coder/v2/cryptorand"
5152
"github.com/coder/coder/v2/pty/ptytest"
53+
"github.com/coder/coder/v2/tailnet/tailnettest"
5254
"github.com/coder/coder/v2/testutil"
5355
)
5456

@@ -1832,6 +1834,12 @@ func TestServer_InvalidDERP(t *testing.T) {
18321834
func TestServer_DisabledDERP(t *testing.T) {
18331835
t.Parallel()
18341836

1837+
derpMap, _ := tailnettest.RunDERPAndSTUN(t)
1838+
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1839+
httpapi.Write(context.Background(), w, http.StatusOK, derpMap)
1840+
}))
1841+
t.Cleanup(srv.Close)
1842+
18351843
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitShort)
18361844
defer cancelFunc()
18371845

@@ -1843,7 +1851,7 @@ func TestServer_DisabledDERP(t *testing.T) {
18431851
"--http-address", ":0",
18441852
"--access-url", "http://example.com",
18451853
"--derp-server-enable=false",
1846-
"--derp-config-url", "https://controlplane.tailscale.com/derpmap/default",
1854+
"--derp-config-url", srv.URL,
18471855
)
18481856
clitest.Start(t, inv.WithContext(ctx))
18491857
accessURL := waitAccessURL(t, cfg)

coderd/database/dbmem/dbmem.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1749,10 +1749,10 @@ func (q *FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
17491749
-- use between 15 mins and 1 hour of data. We keep a
17501750
-- little bit more (1 day) just in case.
17511751
MAX(start_time) - '1 days'::interval,
1752-
-- Fall back to 6 months ago if there are no template
1752+
-- Fall back to ~6 months ago if there are no template
17531753
-- usage stats so that we don't delete the data before
17541754
-- it's rolled up.
1755-
NOW() - '6 months'::interval
1755+
NOW() - '180 days'::interval
17561756
)
17571757
FROM
17581758
template_usage_stats
@@ -1778,7 +1778,7 @@ func (q *FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
17781778
}
17791779
// COALESCE
17801780
if limit.IsZero() {
1781-
limit = now.AddDate(0, -6, 0)
1781+
limit = now.AddDate(0, 0, -180)
17821782
}
17831783

17841784
var validStats []database.WorkspaceAgentStat

coderd/database/dbpurge/dbpurge_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,27 @@ func TestDeleteOldWorkspaceAgentStats(t *testing.T) {
8686
// conflicts, verifying DST behavior is beyond the scope of this
8787
// test.
8888
// Let's use RxBytes to identify stat entries.
89-
// Stat inserted 6 months + 2 hour ago, should be deleted.
89+
// Stat inserted 180 days + 2 hour ago, should be deleted.
9090
first := dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
91-
CreatedAt: now.AddDate(0, -6, 0).Add(-2 * time.Hour),
91+
CreatedAt: now.AddDate(0, 0, -180).Add(-2 * time.Hour),
9292
ConnectionCount: 1,
9393
ConnectionMedianLatencyMS: 1,
9494
RxBytes: 1111,
9595
SessionCountSSH: 1,
9696
})
9797

98-
// Stat inserted 6 months - 2 hour ago, should not be deleted before rollup.
98+
// Stat inserted 180 days - 2 hour ago, should not be deleted before rollup.
9999
second := dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
100-
CreatedAt: now.AddDate(0, -6, 0).Add(2 * time.Hour),
100+
CreatedAt: now.AddDate(0, 0, -180).Add(2 * time.Hour),
101101
ConnectionCount: 1,
102102
ConnectionMedianLatencyMS: 1,
103103
RxBytes: 2222,
104104
SessionCountSSH: 1,
105105
})
106106

107-
// Stat inserted 6 months - 1 day - 4 hour ago, should not be deleted at all.
107+
// Stat inserted 179 days - 4 hour ago, should not be deleted at all.
108108
third := dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
109-
CreatedAt: now.AddDate(0, -6, 0).AddDate(0, 0, 1).Add(4 * time.Hour),
109+
CreatedAt: now.AddDate(0, 0, -179).Add(4 * time.Hour),
110110
ConnectionCount: 1,
111111
ConnectionMedianLatencyMS: 1,
112112
RxBytes: 3333,
@@ -121,8 +121,8 @@ func TestDeleteOldWorkspaceAgentStats(t *testing.T) {
121121
var stats []database.GetWorkspaceAgentStatsRow
122122
var err error
123123
require.Eventuallyf(t, func() bool {
124-
// Query all stats created not earlier than 7 months ago
125-
stats, err = db.GetWorkspaceAgentStats(ctx, now.AddDate(0, -7, 0))
124+
// Query all stats created not earlier than ~7 months ago
125+
stats, err = db.GetWorkspaceAgentStats(ctx, now.AddDate(0, 0, -210))
126126
if err != nil {
127127
return false
128128
}
@@ -144,8 +144,8 @@ func TestDeleteOldWorkspaceAgentStats(t *testing.T) {
144144

145145
// then
146146
require.Eventuallyf(t, func() bool {
147-
// Query all stats created not earlier than 7 months ago
148-
stats, err = db.GetWorkspaceAgentStats(ctx, now.AddDate(0, -7, 0))
147+
// Query all stats created not earlier than ~7 months ago
148+
stats, err = db.GetWorkspaceAgentStats(ctx, now.AddDate(0, 0, -210))
149149
if err != nil {
150150
return false
151151
}

coderd/database/queries.sql.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceagentstats.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ WHERE
7878
-- use between 15 mins and 1 hour of data. We keep a
7979
-- little bit more (1 day) just in case.
8080
MAX(start_time) - '1 days'::interval,
81-
-- Fall back to 6 months ago if there are no template
81+
-- Fall back to ~6 months ago if there are no template
8282
-- usage stats so that we don't delete the data before
8383
-- it's rolled up.
84-
NOW() - '6 months'::interval
84+
NOW() - '180 days'::interval
8585
)
8686
FROM
8787
template_usage_stats

enterprise/coderd/coderd_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"net/http"
8+
"net/http/httptest"
89
"reflect"
910
"strings"
1011
"testing"
@@ -16,7 +17,9 @@ import (
1617
"go.uber.org/goleak"
1718

1819
"cdr.dev/slog/sloggers/slogtest"
20+
"github.com/coder/coder/v2/coderd/httpapi"
1921
"github.com/coder/coder/v2/coderd/rbac/policy"
22+
"github.com/coder/coder/v2/tailnet/tailnettest"
2023

2124
agplaudit "github.com/coder/coder/v2/coderd/audit"
2225
"github.com/coder/coder/v2/coderd/coderdtest"
@@ -456,13 +459,19 @@ func TestMultiReplica_EmptyRelayAddress(t *testing.T) {
456459
func TestMultiReplica_EmptyRelayAddress_DisabledDERP(t *testing.T) {
457460
t.Parallel()
458461

462+
derpMap, _ := tailnettest.RunDERPAndSTUN(t)
463+
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
464+
httpapi.Write(context.Background(), w, http.StatusOK, derpMap)
465+
}))
466+
t.Cleanup(srv.Close)
467+
459468
ctx := testutil.Context(t, testutil.WaitLong)
460469
db, ps := dbtestutil.NewDB(t)
461470
logger := slogtest.Make(t, nil)
462471

463472
dv := coderdtest.DeploymentValues(t)
464473
dv.DERP.Server.Enable = serpent.Bool(false)
465-
dv.DERP.Config.URL = serpent.String("https://controlplane.tailscale.com/derpmap/default")
474+
dv.DERP.Config.URL = serpent.String(srv.URL)
466475

467476
_, _ = coderdenttest.New(t, &coderdenttest.Options{
468477
EntitlementsUpdateInterval: 25 * time.Millisecond,

0 commit comments

Comments
 (0)