-
Notifications
You must be signed in to change notification settings - Fork 875
chore: test metricscache on postgres #16711
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
Conversation
metricscache_test has been running tests against dbmem only, instead of against postgres. Unfortunately the implementations of GetTemplateAverageBuildTime have diverged between dbmem and postgres. This change gets the tests working on Postgres and test for the behaviour postgres provides.
SELECT templates.id AS template_id, COUNT(DISTINCT workspaces.owner_id) AS unique_owners_sum | ||
FROM templates | ||
LEFT JOIN workspaces ON workspaces.template_id = templates.id AND workspaces.deleted = false | ||
WHERE templates.id = ANY(@template_ids :: uuid[]) | ||
GROUP BY templates.id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrote this query as the test-suite expected this query to be able to return unique_owners_sum=0
, however the previous implementation would return nothing if there were no workspaces.
@@ -26,6 +27,7 @@ import ( | |||
type Cache struct { | |||
database database.Store | |||
log slog.Logger | |||
clock quartz.Clock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quartz.Clock
has been added to make the tests more deterministic.
coderd/metricscache/metricscache.go
Outdated
CollectedAt: dbtime.Now(), | ||
NextUpdateAt: dbtime.Now().Add(c.intervals.DeploymentStats), | ||
CollectedAt: c.clock.Now(), | ||
NextUpdateAt: c.clock.Now().Add(c.intervals.DeploymentStats), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be wrapped in a dbtime.Time
like above for the microsecond rounding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, forgot to add that
Fixes #16710
metricscache_test has been running tests against dbmem only, instead of against postgres. Unfortunately the implementations of GetTemplateAverageBuildTime have diverged between dbmem and postgres. This change gets the tests working on Postgres and test for the behaviour postgres provides.