fix: introduce dedicated queries for workspaces and workspace agents metrics #19786
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Over the last 7d, the
GetWorkspaces
query is our most expensive:At least 60k of those 600k calls are from the
prometheusmetrics.Workspaces
andprometheusmetrics.Agents
paths just to generate some Prometheus metrics.The
GetWorkspaces
query is very generic, supporting a range of end use cases in our application by joining on other tables to fill out details about each workspace. In the case of theWorkspaces
andAgents
metrics, we didn't actually need the vast majority of the data being returned in each row.In this PR I'm introducing new queries for these paths that only retrieve the workspaces/agents and the required rows for each as they're used within those code paths. This should make these queries significantly less expensive, but at the very least will help us more accurately attribute query cost more to its actual end use case.
As a quick example, an
EXPLAIN
of a simplified version of the original query has at it's top level:while the new query for
GetWorkspacesForWorkspaceMetrics
has:Besides the tests, I ran som queries to confirm that the results of the new query lined up with the currently exported values for the Prometheus metrics on our own internal deployment.