Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

cstyan
Copy link
Contributor

@cstyan cstyan commented Sep 12, 2025

Over the last 7d, the GetWorkspaces query is our most expensive:

Screenshot 2025-09-11 at 7 10 49 PM

At least 60k of those 600k calls are from the prometheusmetrics.Workspaces and prometheusmetrics.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 the Workspaces and Agents 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:

 Nested Loop Left Join  (cost=118.41..8478.57 rows=368 width=50) (actual time=2.904..24.491 rows=368 l
oops=1)

while the new query for GetWorkspacesForWorkspaceMetrics has:

 Nested Loop Left Join  (cost=33.91..3568.64 rows=2 width=50) (actual time=0.208..7.242 rows=368 loops
=1)

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.

Screenshot 2025-09-11 at 3 29 57 PM Screenshot 2025-09-11 at 3 29 43 PM

@cstyan cstyan changed the title bug: introduce dedicated queries for workspaces and workspace agents metrics fix: introduce dedicated queries for workspaces and workspace agents metrics Sep 12, 2025
Signed-off-by: Callum Styan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant