Skip to content

Record the connection method for session app usage #31012

Closed as not planned
Closed as not planned

Description

@EhabY

Follow-up to #29796 (review thread).

Problem

Template insights reports each session app with a method (connection_log_method values). #29796 derives it at read time because session usage is stored per app name only: Stats.session_counts (agent proto) -> workspace_agent_stats.session_counts -> template_usage_stats_session_apps(start_time, user_id, template_id, app_name, usage_mins).

Derivation rule: app name reconnecting_pty -> reconnecting_pty, port_forwarding -> port_forwarding, any other session app -> ssh, template apps -> workspace_app. It is wrong whenever a client picks a name that does not match how it connected.

Session counts have two sources:

  • The agent's Stats.session_counts, from its SSH and web terminal servers.
  • POST /workspaces/{id}/usage (coderd/workspaces.go), which turns the client-chosen app_name into session_counts directly. coder port-forward reports port_forwarding, coder ssh --usage-app any name (default ssh), coder vscodessh vscode, and coder exp rpty reconnecting_pty.

Scope (database only)

Store the connection method of each session app. The agent protocol, the /usage endpoint, the CLI and the HTTP API do not change. Each current reporter uses an app name that matches its method, so coderd derives the method once, at ingest: reconnecting_pty → reconnecting_pty, port_forwarding → port_forwarding, everything else → ssh.

  • Migration: add method connection_log_method NOT NULL to template_usage_stats_session_apps, fill in existing rows with the rule above, add method to the primary key, and allow only ssh, reconnecting_pty and port_forwarding. The down migration adds each app's minutes across methods, capped at 30 per bucket.
  • Store workspace_agent_stats.session_counts as {method: {app: count}}.
  • The rollup and template insights group by (method, app). Apps past the limit fold into one overflow row per method.
  • Prometheus uses the stored method through feat!: label the VS Code family and report built-in app usage per app #29906, which is stacked on this PR. Telemetry and metricscache add up all methods, so their output does not change.

Out of scope

A method field in the agent protocol and in PostWorkspaceUsageRequest. The first reporter whose app name does not match its method adds it (see the port-forward counting follow-up, CLIENT-1053).

Done when

Part of #27413.

Generated with Coder Agents on behalf of @EhabY.

Scope narrowed to database-only storage by Coder Agents on behalf of @EhabY.

Activity

  1. self-assigned this
    on Oct 19, 2026
  2. linear-code commented on Oct 19, 2026

    @linear-code
  3. EhabY commented on Oct 26, 2026

    @EhabY
    CollaboratorAuthor

    Closing: #31028 no longer stores the connection method. Every reporter's app name implies its method, so coderd derives it. Storing it is tracked in CLIENT-1062 (move workspace_agent_stats.session_counts into a child table), for when a reporter first sends a method (CLIENT-1053).

    🤖 Generated by Coder Agents on behalf of @EhabY.

  4. added 2 commits that reference this issue on Oct 26, 2026
    adfa26b
    7e9735c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions