Skip to content

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

Merged
merged 4 commits into from
Feb 27, 2025
Merged

chore: test metricscache on postgres #16711

merged 4 commits into from
Feb 27, 2025

Conversation

DanielleMaywood
Copy link
Contributor

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.

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.
Comment on lines +418 to +422
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;
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@DanielleMaywood DanielleMaywood marked this pull request as ready for review February 26, 2025 12:42
CollectedAt: dbtime.Now(),
NextUpdateAt: dbtime.Now().Add(c.intervals.DeploymentStats),
CollectedAt: c.clock.Now(),
NextUpdateAt: c.clock.Now().Add(c.intervals.DeploymentStats),
Copy link
Member

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?

Copy link
Contributor Author

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

@DanielleMaywood DanielleMaywood merged commit 6dd51f9 into main Feb 27, 2025
30 checks passed
@DanielleMaywood DanielleMaywood deleted the dm-metricscache branch February 27, 2025 09:43
@github-actions github-actions bot locked and limited conversation to collaborators Feb 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metrics Cache test doesn't run on Postgres
2 participants