Ingest, the template insights API, and the Prometheus metric now use one rule to fold apps and one rule to derive each app's connection method. The method is derived from the app name, not stored. Every current reporter's app name implies its method.
- Add codersdk.SessionAppMethod: reconnecting_pty and port_forwarding keep their own method, and every other app name is ssh. It replaces the private helper in coderd/insights.go.
- Add codersdk.FoldUnregisteredSessionApps, the fold rule that GetTemplateInsights already applies in SQL. Registered apps, unknown, and overflow keep their entries, and so do the 64 busiest other apps. Ties break by app name in byte order, and the rest add up under overflow.
- Ingest uses the shared rule instead of capSessionCounts. Registered apps and unknown no longer fold, and at most 64 unregistered app names keep their entries.
Refs #31012, CLIENT-1062
Report template insights session usage per app instead of five fixed
family rows, with registry names and icons.
- Add per-app rows for reported session apps (VS Code, Cursor, GoLand,
Zed, etc.); unused apps are omitted
- Replace `type` (`builtin`/`app`) with `method` (`ssh`,
`reconnecting_pty`, `port_forwarding`, `workspace_app`); session
methods are derived from the app name until #31012 stores them
- Add `usage_total_seconds` to count each user's active minutes once,
and use it as the UI bar denominator so overlapping apps can exceed
100%
- Merge template apps sharing a slug into one row across templates,
using the newest display name and icon
- Rename Web Terminal slug from `reconnecting-pty` to
`reconnecting_pty`
- Cap the response at the 64 busiest unregistered apps and fold the
rest into "Other apps", flagged with `seconds_is_upper_bound`
("Up to" in the UI)
- Add `unknown` and `overflow` accounting rows with explanatory
tooltips, and a fallback icon for apps without one
- Remove the unused `codersdk.UnionByFamily` helper from the Go SDK
BREAKING CHANGE: `report.apps_usage` in `GET /api/v2/insights/templates`
no longer returns the fixed five rows, family slugs, or previous display
names. Consumers must update.
Part of CLIENT-642
Prometheus metrics handled separately in #29906
coderd_insights_applications_usage_seconds summed each family's per-app
minutes, so a user with VS Code and Cursor open in the same minute was
counted as two VS Code minutes. GetTemplateInsightsByTemplate now takes
the registry's app-to-family mapping as jsonb, groups the raw agent
stats by family, and counts each minute once per user and family.
- Keep the metric's four built-in series (Visual Studio Code, JetBrains,
Web Terminal, SSH) and their labels; only their values change. The
HELP text now says built-in apps are grouped by family.
- Add AppFamilyName.DisplayName() and remove the duplicate
TemplateBuiltinAppDisplayName* constants from codersdk. The template
insights handler returns the same display names.
- Pin how the migration 000596 rollback approximates family minutes
from per-app rows.
Family values can drop wherever the old per-app sum double-counted
overlapping apps. No migration or storage changes.
Store per-app session minutes in a child table instead of fixed family-minute columns, so adding an IDE no longer needs a rollup schema change. API, Prometheus, and telemetry output are unchanged.
- Add `template_usage_stats_session_apps`, keyed by start time, template, user, and app name, replacing the `ssh_mins`, `sftp_mins`, `reconnecting_pty_mins`, `vscode_mins`, and `jetbrains_mins` columns.
- Group app names into families at read time through the `codersdk` registry, so the registry never reaches SQL and attribution covers all history rather than only the buckets the rollup still revisits.
- Group `GetTemplateInsightsByTemplate` by app name so that Prometheus and the API report a family identically.
- Drop the `@app_families` query parameter and its dbauthz validation.
- Report a family total as the sum of its apps rather than the distinct minutes any of them was active. Numbers are unchanged today, because every agent reports one canonical name per family.
- Keep the child table window index-usable and count minutes with `COUNT(DISTINCT)` in the grouping, so a dashboard-sized range uses an index scan and a large deployment does not spill the sort to disk.
Part of #27410
closes https://github.com/coder/internal/issues/464
# Summary
This PR resolves a flaky test that was sensitive to DST transitions in
various time zones. The root of the flake was:
* a bug; the query and its tests assume 24 hours per day
* the tests used local system time, which resulted in failures for dates
proximal to DST transitions
# Changes
Query:
The original query assumed 24 hour intervals between each day, which is
not a valid assumption. It now increments `1 day` at a time.
Database tests:
Database level tests for the query all assumed 24 hour days. They now
increment in DST-aware days instead. Instead of using time.Now() as a
base for testing, the test uses a series of dates over the course of an
entire year, to ensure that DST transition dates are present in every
test run.
# API Endpoint
The endpoint that delivers the user status chart now accepts an IANA
timezone name as a parameter and passes it, keeping the existing offset
as a fallback, to the database query.
API level tests were added to ensure the correct response form and error
behaviour. Correctness of content is tested at the database level.
- Update go.mod to use Go 1.24.1
- Update GitHub Actions setup-go action to use Go 1.24.1
- Fix linting issues with golangci-lint by:
- Updating to golangci-lint v1.57.1 (more compatible with Go 1.24.1)
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <claude@anthropic.com>
The experimental functions in `golang.org/x/exp/slices` are now
available in the standard library since Go 1.21.
Reference: https://go.dev/doc/go1.21#slices
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
RE: https://github.com/coder/coder/issues/15740,
https://github.com/coder/coder/issues/15297
In order to add a graph to the coder frontend to show user status over
time as an indicator of license usage, this PR adds the following:
* a new `api.insightsUserStatusCountsOverTime` endpoint to the API
* which calls a new `GetUserStatusCountsOverTime` query from postgres
* which relies on two new tables `user_status_changes` and
`user_deleted`
* which are populated by a new trigger and function that tracks updates
to the users table
The chart itself will be added in a subsequent PR
---------
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
Removes our pseudo rbac resources like `WorkspaceApplicationConnect` in favor of additional verbs like `ssh`. This is to make more intuitive permissions for building custom roles.
The source of truth is now `policy.go`
Just moved `rbac.Action` -> `policy.Action`. This is for the stacked PR to not have circular dependencies when doing autogen. Without this, the autogen can produce broken golang code, which prevents the autogen from compiling.
So just avoiding circular dependencies. Doing this in it's own PR to reduce LoC diffs in the primary PR, since this has 0 functional changes.
* chore: add /v2 to import module path
go mod requires semantic versioning with versions greater than 1.x
This was a mechanical update by running:
```
go install github.com/marwan-at-work/mod/cmd/mod@latest
mod upgrade
```
Migrate generated files to import /v2
* Fix gen