Skip to content

feat: expose per-app session counts - #29351

Merged
EhabY merged 2 commits into
mainfrom
feat/expose-app-session-counts
Sep 24, 2026
Merged

EhabY merged 2 commits into
mainfrom
feat/expose-app-session-counts

Conversation

@EhabY

@EhabY EhabY commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Expose per-app session counts in deployment stats, Prometheus, telemetry, and the deployment banner.

SessionCountDeploymentStats.Apps retains each reported app's normalized identifier with its count, current family, display name, and optional bundled icon. The server-owned registry supplies attribution and presentation; unrecognized apps keep their identifiers, and reported names never become image URLs. The banner retains family totals, adds an Other slot, and lists individual apps alphabetically on hover or focus.

Prometheus exports app-keyed observations in coderd_agentstats_session_count, without a family label. A separate coderd_agentstats_app_info{app_name,family} gauge exposes the current registry. The documented queries enrich retained app history with current metadata and preserve unmatched counts as unknown, without rewriting historical samples. Metadata is initialized once when the collector starts and served on every scrape. The join runs in the querying Prometheus server, not in the coderd API or background SQL collection path.

Each statistics report retains up to 64 distinct app names and sums excess names into app_name="overflow". Blank names and client-supplied reserved overflow names normalize to unknown. Collections with reports replace session series; empty collections retain the previous snapshot. The four deprecated API fields and four family-specific gauges remain for compatibility; removal is tracked in https://linear.app/codercom/issue/CLIENT-980.

Refs https://linear.app/codercom/issue/DEVEX-641

Before merge

  • Telemetry review. WorkspaceAgentStat.SessionCounts sends normalized app names off the deployment, including custom names supplied by templates. docs/admin/setup/telemetry.md discloses this, but the same page states Coder does not collect parameters or environment variables, so this needs an explicit decision. Names are truncated to 64 runes and reports retain up to 64 distinct names plus overflow. Receiver schema and ingestion sign-off are also required.
  • Removal release. CLIENT-980 asks that the exact removal version be recorded in the Prometheus documentation before merge. Not yet assigned.
Implementation decisions and performance evidence

The branch has two reviewable commits: bc5a57219b contains the per-app feature and loading accessibility fix; 9334e827bf contains query-time family grouping, concise Prometheus guidance, and spacing after the connection icons.

Agreed implementation

  1. Keep app_name and existing identity labels on count observations; export family metadata separately for every registered app, including apps without active sessions.
  2. Use the current registry to enrich historical observations, consistent with read-time classification elsewhere in the codebase. Pin both metadata selectors to the current Unix timestamp on each query execution, independently of the graph's time range; @ end() is not current metadata for an old graph.
  3. Preaggregate counts before the join and retain the unless fallback so missing mappings do not silently drop sessions. Missing metadata, including scrape failures or staleness, appears as unknown.
  4. Deduplicate identical replica metadata. Keep Prometheus's explicit matching error when replicas disagree about a family rather than silently choose one. Scope multi-deployment queries with an operator-provided deployment label.
  5. Preserve the deprecated gauges, update collector regression coverage, and regenerate the metric reference. No experimental flags, query generator, or mandatory recording rules.
  6. Keep this follow-up scoped to feat: expose per-app session counts #29351. The separate family-only insights metric in feat!: report template insights session usage per app #29796 remains for that PR to address.

Performance and execution path

A synthetic Prometheus 3.11.2 benchmark used approximately 100.8 million samples, 15-second sampling, and a 2-CPU/4-GiB limit. For 10,000 series over 24 hours at one-minute graph steps, the current-metadata fallback query took approximately 2.96 seconds median versus 1.48 seconds for direct family grouping. These are graph-query timings, not coderd request timings or production capacity estimates.

The fallback evaluates counts twice. A separate controlled comparison at 0%, 1%, 2%, and 5% unknowns showed essentially unchanged fallback cost. Stable low-effort rewrites did not materially improve it. We accept this cost initially while retaining app-keyed observations so queries can be optimized later; optional app-keyed recording rules would require configuration and resolution/dimension decisions.

The registry currently contains 18 entries. Their metadata gauges are populated once per collector initialization, then scraped routinely. This follow-up adds no SQL query or synchronous dependency to Coder API requests. Prometheus queries can still compete for host resources if Prometheus and Coder share a host; net scrape-latency changes were not benchmarked.

Completed validation for the follow-up

  • go test -race ./coderd/prometheusmetrics/... -count=1
  • Scoped Go lint and the full pre-commit generation, formatting, lint, and slim-build suite.
  • Metric documentation regeneration and Markdown checks; condensed guidance preserves both tested PromQL examples unchanged.
  • Banner unit tests (2) and Storybook tests (7), frontend check/lint/type checks/formatting, and FE1-FE10 review passed. Visual verification covered the section gap and keyboard-focused loading tooltip.
  • PromQL fixture checks for current metadata over historical counts, unknown fallback, identical replicas, and deployment isolation; separate live investigation verified conflicting mappings return an error.
Earlier review follow-ups

The banner uses family slots rather than the four busiest apps, with alphabetical app rows, restored SSH and Web Terminal icons, and corrected icon padding. The overflow bucket is separate from blank-name unknown, and the overflow counter help text matches. The broken-icon fallback was removed; app names remain visible beside their icons. Loading connection labels and tooltips no longer report zero sessions. Padding before the timestamp section preserves separation from the last connection icon; it adds 32px to the banner's minimum content width.

Updated by Coder Agents on behalf of @EhabY. Earlier implementation assistance: Claude Code.

@linear-code

linear-code Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

DEVEX-641

CLIENT-980

@github-actions

github-actions Bot commented Sep 15, 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 added this pull request to stack #29135 September 15, 2026 14:57
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from a5de245 to 9abc1e5 Compare September 16, 2026 11:27
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from 9abc1e5 to 72f01ce Compare September 16, 2026 12:19
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from 72f01ce to 01c9c50 Compare September 16, 2026 12:37
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from 01c9c50 to f1e6046 Compare September 16, 2026 12:42
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from f1e6046 to 4cc62ca Compare September 17, 2026 08:55
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch 2 times, most recently from fb5193f to ddc428f Compare September 17, 2026 17:31
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from ddc428f to 91b570e Compare September 18, 2026 13:02
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from 91b570e to eddc4ac Compare September 18, 2026 13:26
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from eddc4ac to fdf6f82 Compare September 18, 2026 22:22
Base automatically changed from feat/arbitrary-session-count-producers to main September 18, 2026 22:32
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch 2 times, most recently from c9ba7be to acfe371 Compare September 21, 2026 14:36
@EhabY
EhabY marked this pull request as ready for review September 21, 2026 15:12
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from acfe371 to 57faaf8 Compare September 21, 2026 15:29
@EhabY
EhabY requested a review from code-asher September 21, 2026 15:44

@code-asher code-asher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broadly looks good to me!

return nil, err
}

sessionCountLabels := append(slices.Clone(aggregateByLabels), "app_name", "family")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an IMO thing, but I feel like we should only emit the app name. Grouping is something that should be done at query/display time when necessary, especially since we would not be able to change the metrics retroactively to account for new families or apps, but a query change can.

That gives us a smooth continuation from vscode to still vscode, as well, rather than having vscode and then vscode_vscode.

But I am not super familiar with Prometheus so there could be some bad assumptions I am making.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep family. It comes straight from app_name, so it adds no series. Prometheus also can't look up our app list, so without the label, totaling by family means a regex per app. app_name is still there if you want to regroup differently at query time.

On continuity, VS Code shows up as {app_name="vscode", family="vscode"}, so there's no vscode_vscode.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right yeah that makes sense, I just meant the testuser:workspace-1:example:coderd_agentstats_session_count_vscode_vscode

Fair though that users can group them and just ignore the family label, although that requires operators to be aware the categorization is best-effort and possibly wrong.

Just feels sketchy to me to emit data that is basically guaranteed to be wrong eventually (as long as we keep adding support for new VS Code forks and other editors, which happens at a faster pace than people update Coder to get a new family list).

Part of the problem for me is I am not sure how people actually use this data, so it is hard to know if the design for it is correct. If they are just displaying some total counts per family on a dashboard somewhere, probably not a big deal if some of the numbers are incorrectly in one family versus another. If the numbers are used to justify something about one family of editors versus another, then maybe it does become more important.

If the family is important to emit, maybe this is an indication that the client should report its own family instead of coderd.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, I am probably overthinking it lol

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it's because the old way is basically the family. Family here essentially means "program", VS Code has one codebase, jetbrains is the same, Zed can potentially be a family if we decide to go there.

Would another name make more sense for this?

@code-asher code-asher Sep 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My take on it is that it was meant to be more just a loose grouping like "the jetbrains editors", "vs code", "everything else that uses ssh") than strictly "these are based off the same codebase". Just to sort of help admins get a big-picture view of how the product was being used. (I suspect the fragmentation of VS Code was not considered when implemented.)

The naming itself is not really a problem though imo, it is more that previously, adding a new vs code editor for example would go into the right group "vscode" without a coderd update since it would send "vscode" as its name. Now, a coderd update is separately required which means the data emitted prior to upgrading will be incorrectly grouped.

Unlike for example the stats endpoint, where once coderd updates it would start emitting the correct family for older entries (since it is runtime and not in the database).

So the issue is more that classification happens during storage instead of run/query time. Having clients emit their own family/category/type would sort of work around it.

But idk if this is a real issue in practice, just stuck out to me is all. Possibly no one cares at all lol

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a brain fart from switching contexts but actually the family is derived at runtime literally everywhere else so I'll look for a way

@EhabY EhabY Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now achieves this but it sadly makes the PromQL query slower: a324817

This happens in Prometheus and it's only the query we suggest in the MD file so admins still have to use it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooo nice makes sense to me!

Comment thread codersdk/appname.go Resolved
Comment thread docs/admin/integrations/prometheus.md Resolved
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch 2 times, most recently from 5ee9c3f to b2004e9 Compare September 23, 2026 11:25
@EhabY
EhabY requested a review from code-asher September 23, 2026 11:30
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from b2004e9 to f9a89c3 Compare September 23, 2026 14:30

@code-asher code-asher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it!!

@code-asher

Copy link
Copy Markdown
Member

tiny lil nit, can we add a gap after the connections sections like the others, right now it is a bit close to the next section

image

EhabY and others added 2 commits September 24, 2026 11:33
Expose normalized app identifiers, counts, and registry presentation metadata
in deployment stats, Prometheus, and telemetry. Retain deprecated family
fields and gauges for compatibility and bound per-report names with an
explicit overflow bucket.

Group deployment banner connections by family with alphabetical app tooltips,
a Visual Studio Code label, and distinct loading and empty states.

Generated with Coder Agents.
Keep app-keyed session counts separate from current registry metadata.
Document pinned metadata joins with unknown fallback and explicit replica
conflicts, with concise guidance and a collapsible multi-deployment query.

Add separation between connection icons and the banner's timestamp section.

Generated with Coder Agents.
@EhabY
EhabY force-pushed the feat/expose-app-session-counts branch from a324817 to 9334e82 Compare September 24, 2026 11:34
@EhabY
EhabY merged commit bacb4fc into main Sep 24, 2026
34 of 35 checks passed
@EhabY
EhabY deleted the feat/expose-app-session-counts branch September 24, 2026 12:12
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 24, 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