Skip to content

engine: send Cloud metrics with delta temporality - #14930

Merged
vito merged 2 commits into
dagger:mainfrom
vito:cloud-metrics-delta
Oct 29, 2026
Merged

vito merged 2 commits into
dagger:mainfrom
vito:cloud-metrics-delta

Conversation

@vito

@vito vito commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Problem

Long-lived sessions that publish telemetry to Dagger Cloud from the engine leak memory until the engine is OOM-killed. A git-heavy agent session reached 20–33 GB in under an hour. Heap profiles put about 80% of it under cloudMetricQueue.Export → proto.Clone, and about 10% under cumulativeLastValue.collect → collectExemplars.

The session's Cloud metric reader took the OTLP HTTP exporter's default cumulative temporality. That's because cloudMetricQueue.Temporality delegated to the exporter. A cumulative gauge never forgets an attribute set, and it re-exports every series it has seen at each collection, stamped with the collection time.

Resource readings are keyed by span (dagger.io/metrics.trace / dagger.io/metrics.span). Since helper-command accounting, every git/rg/patch call adds its own series too. So a long-lived client kept every series in memory and re-sent all of them every 5s. Once one upload took longer than 5s, the queue's deep copies piled up.

Ingest side

This also affected the data. Cloud's /v1/metrics writes every gauge point as a row in otel_metrics_gauges, and that table's readers treat each distinct TimeUnix as a sample:

  • legacy billing (godmode.BillingDaily) counts each distinct memory.current time as 5s;
  • check resource charts read the same table.

With cumulative export, a finished exec's or helper's last reading repeated as a new sample every 5s until its client closed. Billing for new orgs uses the separate workload export (its own provider, raw points drained per collection), and this PR doesn't touch it.

Fix

cloudMetricQueue.Temporality now always returns delta. That matches the client's own metric stream, which is what the CLI forwarded to Cloud before the engine published it. Each reading is exported once, and the reader forgets the series afterwards.

TestSessionPublishesEachGaugeReadingToCloudOnce records one gauge reading, runs several collections, and checks that Cloud receives exactly one point. Without the fix it received 4.

vito added 2 commits October 28, 2026 23:35
The session's Cloud metric reader took the OTLP exporter's default,
cumulative temporality. A cumulative gauge keeps every attribute set it
ever saw and re-exports all of them at each collection, stamped with the
collection time. Readings are keyed by span, so a long-lived client kept
every exec's and helper command's series in memory and resent them every
5s. With a git-heavy agent session the Cloud uploads fell behind and the
queued copies grew to tens of GB until the engine was OOM-killed.

Cloud stores each gauge point as a sample at its time, and the legacy
billing and check resource queries count each distinct time as a 5s
sample, so the repeats were also wrong on the ingest side. Delta matches
what the CLI forwarded before the engine published to Cloud: each
reading is exported once, and the reader forgets the series afterwards.

Signed-off-by: Alex Suraci <[email protected]>
Records the fix for the engine's memory growth in long sessions that
publish telemetry to Dagger Cloud.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit to vito/dagger that referenced this pull request Oct 29, 2026
Include delta temporality for engine Cloud metrics so completed metric
series are not retained and exported again on every collection.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit to vito/dagger that referenced this pull request Oct 29, 2026
Record the Cloud metric temporality merge and unchanged local dependency
edits. Builds and tests remain skipped for dogfooding.

Signed-off-by: Alex Suraci <[email protected]>
@tiborvass
tiborvass requested a review from matipan October 29, 2026 07:16
@vito
vito merged commit 49caafb into dagger:main Oct 29, 2026
93 checks passed
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.

3 participants