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

Commit36555a7

Browse files
committed
fix: delete workspace agent stats after 180 days
1 parent4672849 commit36555a7

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

‎coderd/database/dbmem/dbmem.go

Lines changed: 3 additions & 3 deletions
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
iflimit.IsZero() {
1781-
limit=now.AddDate(0,-6,0)
1781+
limit=now.AddDate(0,0,-180)
17821782
}
17831783

17841784
varvalidStats []database.WorkspaceAgentStat

‎coderd/database/dbpurge/dbpurge_test.go

Lines changed: 10 additions & 10 deletions
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 inserted6 months + 2 hour ago, should be deleted.
89+
// Stat inserted180 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 inserted6 months - 2 hour ago, should not be deleted before rollup.
98+
// Stat inserted180 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 inserted6 months - 1 day - 4 hour ago, should not be deleted at all.
107+
// Stat inserted179 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
varstats []database.GetWorkspaceAgentStatsRow
122122
varerrerror
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
iferr!=nil {
127127
returnfalse
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
iferr!=nil {
150150
returnfalse
151151
}

‎coderd/database/queries.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/workspaceagentstats.sql

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp