Skip to content

refactor: share the session app fold rule and method derivation - #31028

Merged
EhabY merged 3 commits into
mainfrom
feat/session-app-method
Oct 26, 2026
Merged

EhabY merged 3 commits into
mainfrom
feat/session-app-method

Conversation

@EhabY

@EhabY EhabY commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Share one fold rule and one method rule for session apps, so ingest, the template insights API, and the Prometheus collector in #29906 agree.

  • codersdk.SessionAppMethod derives a session app's connection method from its name: reconnecting_pty and port_forwarding keep their own method, every other name is ssh. It moves here from coderd/insights.go so feat!: label the VS Code family and report built-in app usage per app #29906 can label series with it. Every current reporter's app name implies its method, so the method is not stored.
  • codersdk.FoldUnregisteredSessionApps is the fold rule that GetTemplateInsights already applies in SQL: registered apps, unknown, and overflow keep their entries, the 64 busiest other apps keep theirs, ties break by app name in byte order, and the rest add up under overflow.
  • Ingest uses it instead of capSessionCounts. Before, a report kept 64 names in total, ranking registered names first; now registered names and unknown never fold, and at most 64 unregistered names keep theirs.

No schema, API, or protocol change.

Refs #31012, CLIENT-1052

Size

Files Lines
Production 4 +48 / -63
Tests 4 +31 / -49
Decision log
  • The method is derived, not stored (2026-10-26). The first commit stored it: a nested session_counts ({method: {app: count}}), a method column in template_usage_stats_session_apps, and migration 000634, which locked workspace_agent_stats and made replicas still on the previous release fail their stats writes. The last commit reverts that. A stored method adds no information while every app name implies its method. The source that first sends a method (port-forward counting, CLIENT-1053) can store it in the child table that CLIENT-1062 proposes for session_counts, so the data migrates once instead of twice. The branch keeps both commits for the history.
  • One fold rule. The SQL in GetTemplateInsights already ranked by usage, then by app name with COLLATE "C", and exempted registered apps, unknown, and overflow. The Go helper matches it, so the API, ingest, and the metric fold the same apps.

🤖 Generated by Coder Agents on behalf of @EhabY.

@linear-code

linear-code Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

CLIENT-1062

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

@EhabY
EhabY marked this pull request as ready for review October 26, 2026 18:23
@EhabY
EhabY requested a review from nickvigilante as a code owner October 26, 2026 18:23
@EhabY
EhabY force-pushed the feat/session-app-method branch 2 times, most recently from d4effdf to 1935137 Compare October 26, 2026 19:29
@EhabY EhabY changed the title feat: record the connection method for session app usage refactor: share the session app fold rule and method derivation Oct 26, 2026
@EhabY
EhabY force-pushed the feat/session-app-method branch from e7d552f to 98c30b9 Compare October 26, 2026 19:57
Comment thread codersdk/appname.go Resolved
EhabY added 3 commits October 26, 2026 20:40
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. It also adds
session_count_apps, whose row estimate keeps the rollup's plan from
degrading on large tables.

Insights group and fold "Other apps" per method, with the same rule
and order as ingest (codersdk.FoldUnregisteredSessionApps). Operational readers
return the stored objects and coderd sums them per app, so
metricscache, telemetry, and Prometheus are unchanged.

Closes #31012
Migration 000634 now adds the workspace_agent_stats CHECK before it
alters template_usage_stats_session_apps, so it takes its locks in the
same order as UpsertTemplateUsageStats and cannot deadlock with a rollup
on a replica that still runs the previous release.

The CHECK also rejects keys that are not session methods, dbgen emits
constants for CHECKs added with ALTER TABLE, and a test checks the SQL
fold across methods against codersdk.FoldUnregisteredSessionApps.
Every reporter's app name implies its method, so storing the method adds
no information until a reporter sends one (CLIENT-1053), and that change
can store it in the child table of CLIENT-1062 with a single migration.
This drops migration 000634, the nested session_counts, and the method
column, and keeps the shared fold rule: codersdk.SessionAppMethod and an
app-keyed codersdk.FoldUnregisteredSessionApps, used by ingest and
mirrored by GetTemplateInsights.
@EhabY
EhabY force-pushed the feat/session-app-method branch from 98c30b9 to 7123b57 Compare October 26, 2026 20:41
@EhabY
EhabY enabled stacked auto-merge (squash) October 26, 2026 20:46
@EhabY
EhabY merged commit 7e9735c into main Oct 26, 2026
27 checks passed
@EhabY
EhabY deleted the feat/session-app-method branch October 26, 2026 21:48
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 26, 2026
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.

2 participants