Skip to content

fix(shell): Label shell-session metrics by project, not namespace - #668

Merged
vvoytovych merged 2 commits into
mainfrom
alerts-week-2026-11-24/03-build
Nov 25, 2026
Merged

vvoytovych merged 2 commits into
mainfrom
alerts-week-2026-11-24/03-build

Conversation

@vvoytovych

Copy link
Copy Markdown
Contributor

The shell-session metrics label each session with its namespace, under the label name project. Every project keeps its sessions in its default namespace, so the label does not tell one project from another. The "Which projects" query in the ComputeShellSessionVolumeUnusual runbook cannot answer its question.

This change labels compute_shell_sessions_created_total and compute_shell_sessions_open with the project's cluster name, which the reconciler gets with each request. With the Milo provider, the cluster name is the project's name: the provider keys each cluster by project name, and the Internal DNS publisher uses it as the project ID. The number of series stays bounded by the number of projects.

Before After
The project label on the counter and the open-sessions gauge the session's namespace the project's cluster name
Two projects, each with one session in default one series, value 2 two series, value 1 each

The runbook's query and the dashboard's project filter read this label. The alert reads a recording rule that sums the label away, so the alert does not change.

Test. TestInstanceConsoleSessionMetricsLabelTheProject delivers one session in each of two projects, in namespaces with the same name. It reads two series of each metric. When one project's session goes, only that project's open series goes. On main the test reads one series.

The open-sessions update moves out of Reconcile into trackOpenSession, which takes the cluster name.

Draft #465 changes the same line in deliver: it puts the sessionsCreated increment under if firstDelivery. The second of the two to merge resolves that one conflict and keeps both changes:

if firstDelivery {
	sessionsCreated.WithLabelValues(string(clusterName), placement.location).Inc()
}

Fixes #667

The project label on compute_shell_sessions_created_total and
compute_shell_sessions_open names the session's namespace. Every project
keeps its sessions in its default namespace, so two projects count as one
series. This test is red until the label names the project.

Refs #667
compute_shell_sessions_created_total and compute_shell_sessions_open
labelled each session with its namespace under the name project. Every
project keeps its sessions in its default namespace, so in production
every series read project="default", and the runbook's "Which projects"
query for ComputeShellSessionVolumeUnusual could not name a project.

Both series now take the project's cluster name from the reconcile
request. In Milo mode it is the project's name, and other controllers
here use it as the project ID. The number of series stays bounded by the
number of projects. The open-sessions update moves out of Reconcile into
trackOpenSession, which takes the cluster name.

Fixes #667
@vvoytovych vvoytovych self-assigned this Nov 25, 2026
@vvoytovych
vvoytovych marked this pull request as ready for review November 25, 2026 19:01
@vvoytovych
vvoytovych requested a review from a team as a code owner November 25, 2026 19:01

@ecv ecv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve.

The project label now carries the project's cluster name on both the created counter and the open gauge, and the new test proves two projects with same-named namespaces become separate series. Reconcile returns early on an empty cluster name (controller.go:97), so the label is never empty, and a delete and an end both go through the same tracker, which recomputes the gauge from stored series, so the gauge cannot drift from the counter's label.

  • Every consumer in this repo already queries project (shell-sessions dashboard jsonnet and generated JSON, volume-unusual runbook's sum by (project)) and none filters on a namespace value, so nothing needs changing. Alerts aggregate by location only. A search of datum-cloud/infra found no compute_shell_sessions_* references.
  • Cardinality is bounded by project count times locations, same as before in kind, and the tracker deletes series with no sessions left.

Follow-ups:

  • Existing series history flips meaning at deploy (namespace value to project name), so a dashboard range spanning the roll shows both. Worth a line in the release note.

@vvoytovych
vvoytovych merged commit ab642d8 into main Nov 25, 2026
15 checks passed
@vvoytovych
vvoytovych deleted the alerts-week-2026-11-24/03-build branch November 25, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell-session metrics label the namespace, not the project

2 participants