Repository navigation
Conversation
This was referenced Oct 19, 2026
EhabY
added this pull request to stack #31031
October 19, 2026 21:32
EhabY
force-pushed
the
feat/session-app-method
branch
from
October 19, 2026 22:41
e436f39 to
078f91c
Compare
Store the connection method of each session app in template_usage_stats_session_apps and nest workspace_agent_stats.session_counts by method. Coderd derives the method from the app name at ingest, so the agent protocol, CLI, and API are unchanged. Migration 000630 blocks writes to workspace_agent_stats, converts the rows the rollup and operational readers still read, and adds a NOT VALID check that rejects flat session counts, so a coderd still on the previous release cannot write rows the new readers fail on. Insights group and fold "Other apps" per method. Operational readers return the stored objects and coderd sums them per app, so metricscache, telemetry, and Prometheus are unchanged. Closes #31012
EhabY
force-pushed
the
feat/session-app-method
branch
from
October 20, 2026 00:00
078f91c to
df31332
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Store the connection method of each session app so insights no longer guess it from the app name at read time.
codersdk.SessionAppMethod). The agent protocol, CLI, and API are unchanged: every current reporter's app name already implies its method.template_usage_stats_session_appsgainsmethod(CHECK onssh,reconnecting_pty,port_forwarding) in its primary key.workspace_agent_stats.session_countsis nested as{method: {app: count}}.GetTemplateInsightsgroup by (method, app). "Other apps" folds per method, and only a folded method's overflow is an upper bound.codersdk.SumSessionCounts), so metricscache, telemetry, and Prometheus output is unchanged.Upgrade. Migration 000630 locks
workspace_agent_statsinEXCLUSIVEmode (writes wait, reads continue) and converts only the rows the rollup and operational readers still read: from the last rollup minus 1 day, the windowDeleteOldWorkspaceAgentStatskeeps. It warns when the rollup is more than 24 hours behind, as 000590 did. ANOT VALIDCHECK then rejects flat session counts, so a replica still on the previous release fails its stats writes instead of storing rows that would stall the new rollup. Until those replicas are replaced, their agent stats writes and session reads fail, as with 000590.A future reporter (for example port-forward counting) only adds a name to the derivation rule; storage and insights already key by method. It will also need a method label in the UI, which keys rows by
method/slugbut does not show the method.Closes #31012
Closes CLIENT-1052
Size
dbgen)Decisions and measurements
Decisions
session_countsby method in place.overflowrow per method.Migration (5M agent stat rows, 968k session app rows, local Postgres)
workspace_agent_stats: about 43 s. Reads continued, inserts waited, and a flat insert after commit failed onworkspace_agent_stats_session_counts_check.template_usage_stats_session_apps: the column default fills existing rows without a rewrite, so onlyreconnecting_ptyandport_forwardingrows are updated (about 1.3 s of blocked reads).Queries, median ms (main / this PR)
5M rows, 2,000 agents, table clustered by
created_at,EXPLAIN (ANALYZE)medians with the window pinned to the newest row:UpsertTemplateUsageStatsGetTemplateInsights(7d)GetTemplateInsightsByTemplate(5m, Prometheus; #29906 rewrites it)GetDeploymentWorkspaceAgentStatsGetDeploymentWorkspaceAgentUsageStatsGetWorkspaceAgentUsageStats(1h)GetWorkspaceAgentUsageStatsAndLabels(without the label joins)GetWorkspaceAgentStatsandGetWorkspaceAgentStatsAndLabelsreturnjsonb_build_arrayof the latest row, at no measurable cost.What keeps these close to main:
jsonb_agg, andGetTemplateInsightsByTemplateexpands app names in one call (jsonb_path_query_array(..., '$.*.keyvalue().key')).latest_start. Without the bound, the overestimate made it scan the whole child table (573 ms down to 24 ms).GetTemplateInsightsuses grouped joins instead of per-method subqueries.The rollup's remaining cost is the extra method level, which needs both keys.
Follow-ups