Skip to content

test flake: TestDeleteOldWorkspaceAgentStats #13430

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
coadler opened this issue May 31, 2024 · 3 comments · Fixed by #14489
Closed

test flake: TestDeleteOldWorkspaceAgentStats #13430

coadler opened this issue May 31, 2024 · 3 comments · Fixed by #14489
Assignees
Labels
s4 Internal bugs (e.g. test flakes), extreme edge cases, and bug risks

Comments

@coadler
Copy link
Contributor

coadler commented May 31, 2024

Slack context: https://codercom.slack.com/archives/CJURPL8DN/p1717174598761439

Likely due to it being the last of the month.

https://github.com/coder/coder/actions/runs/9325137323/job/25671626698?pr=13429#step:5:345

    dbpurge_test.go:123: 
        	Error Trace:	/home/runner/actions-runner/_work/coder/coder/coderd/database/dbpurge/dbpurge_test.go:123
        	Error:      	Condition never satisfied
        	Test:       	TestDeleteOldWorkspaceAgentStats
        	Messages:   	it should delete old stats: []
@coder-labeler coder-labeler bot added flake s4 Internal bugs (e.g. test flakes), extreme edge cases, and bug risks labels May 31, 2024
@sreya sreya self-assigned this Aug 5, 2024
@ethanndickson ethanndickson assigned ethanndickson and unassigned sreya Aug 30, 2024
@dannykopping
Copy link
Contributor

@ethanndickson
Copy link
Member

It looks like it's going to happen on every commit today, until my PR is merged😭

@dannykopping
Copy link
Contributor

Approved your PR 👍

ethanndickson added a commit that referenced this issue Aug 30, 2024
Fixes #13430.

The test for purging old workspace agent stats from the DB was consistently failing when ran with Postgres towards the end of the month, but not with the in-memory DB. 

This was because month intervals are calculated differently for `time.Time` and the `interval` type in Postgres:

```
ethan=# SELECT
    '2024-08-30'::DATE AS original_date,
    ('2024-08-30'::DATE - INTERVAL '6 months') AS sub_date;
 original_date |      sub_date
---------------+---------------------
 2024-08-30    | 2024-02-29 00:00:00
(1 row)
```

Using `func (t Time) AddDate(years int, months int, days int) Time`, where `months` is `-6`:
```
Original: 2024-08-30 00:00:00 +0000 UTC
6 Months Earlier: 2024-03-01 00:00:00 +0000 UTC
```

Since 6 months was chosen arbitrarily, we should be able to change it to 180 days, to remove any ambiguity between the in-memory DB, and the Postgres DB. The alternative solution would involve implementing Postgres' month interval algorithm in Go.

The UI only shows stats as old as 168 days (24 weeks), so a frontend change isn't required for the extra days of stats we lose in some cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s4 Internal bugs (e.g. test flakes), extreme edge cases, and bug risks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants