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

fix: delete workspace agent stats after 180 days#14489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletionscoderd/database/dbmem/dbmem.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1749,10 +1749,10 @@ func (q *FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
-- use between 15 mins and 1 hour of data. We keep a
-- little bit more (1 day) just in case.
MAX(start_time) - '1 days'::interval,
-- Fall back to 6 months ago if there are no template
-- Fall back to~6 months ago if there are no template
-- usage stats so that we don't delete the data before
-- it's rolled up.
NOW() - '6 months'::interval
NOW() - '180 days'::interval
)
FROM
template_usage_stats
Expand All@@ -1778,7 +1778,7 @@ func (q *FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
}
// COALESCE
if limit.IsZero() {
limit = now.AddDate(0,-6, 0)
limit = now.AddDate(0,0, -180)
}

var validStats []database.WorkspaceAgentStat
Expand Down
20 changes: 10 additions & 10 deletionscoderd/database/dbpurge/dbpurge_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,27 +86,27 @@ func TestDeleteOldWorkspaceAgentStats(t *testing.T) {
// conflicts, verifying DST behavior is beyond the scope of this
// test.
// Let's use RxBytes to identify stat entries.
// Stat inserted6 months + 2 hour ago, should be deleted.
// Stat inserted180 days + 2 hour ago, should be deleted.
first := dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
CreatedAt: now.AddDate(0,-6, 0).Add(-2 * time.Hour),
CreatedAt: now.AddDate(0,0, -180).Add(-2 * time.Hour),
ConnectionCount: 1,
ConnectionMedianLatencyMS: 1,
RxBytes: 1111,
SessionCountSSH: 1,
})

// Stat inserted6 months - 2 hour ago, should not be deleted before rollup.
// Stat inserted180 days - 2 hour ago, should not be deleted before rollup.
second := dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
CreatedAt: now.AddDate(0,-6, 0).Add(2 * time.Hour),
CreatedAt: now.AddDate(0,0, -180).Add(2 * time.Hour),
ConnectionCount: 1,
ConnectionMedianLatencyMS: 1,
RxBytes: 2222,
SessionCountSSH: 1,
})

// Stat inserted6 months - 1 day - 4 hour ago, should not be deleted at all.
// Stat inserted179 days - 4 hour ago, should not be deleted at all.
third := dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
CreatedAt: now.AddDate(0,-6, 0).AddDate(0, 0, 1).Add(4 * time.Hour),
CreatedAt: now.AddDate(0,0, -179).Add(4 * time.Hour),
ConnectionCount: 1,
ConnectionMedianLatencyMS: 1,
RxBytes: 3333,
Expand All@@ -121,8 +121,8 @@ func TestDeleteOldWorkspaceAgentStats(t *testing.T) {
var stats []database.GetWorkspaceAgentStatsRow
var err error
require.Eventuallyf(t, func() bool {
// Query all stats created not earlier than 7 months ago
stats, err = db.GetWorkspaceAgentStats(ctx, now.AddDate(0,-7, 0))
// Query all stats created not earlier than~7 months ago
stats, err = db.GetWorkspaceAgentStats(ctx, now.AddDate(0,0, -210))
if err != nil {
return false
}
Expand All@@ -144,8 +144,8 @@ func TestDeleteOldWorkspaceAgentStats(t *testing.T) {

// then
require.Eventuallyf(t, func() bool {
// Query all stats created not earlier than 7 months ago
stats, err = db.GetWorkspaceAgentStats(ctx, now.AddDate(0,-7, 0))
// Query all stats created not earlier than~7 months ago
stats, err = db.GetWorkspaceAgentStats(ctx, now.AddDate(0,0, -210))
if err != nil {
return false
}
Expand Down
4 changes: 2 additions & 2 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

4 changes: 2 additions & 2 deletionscoderd/database/queries/workspaceagentstats.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,10 +78,10 @@ WHERE
-- use between 15 mins and 1 hour of data. We keep a
-- little bit more (1 day) just in case.
MAX(start_time) - '1 days'::interval,
-- Fall back to 6 months ago if there are no template
-- Fall back to~6 months ago if there are no template
-- usage stats so that we don't delete the data before
-- it's rolled up.
NOW() - '6 months'::interval
NOW() - '180 days'::interval
)
FROM
template_usage_stats
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp