Skip to content

Deploy tools 6/6: metrics for deploys and uploads - #259

Closed
raymondk wants to merge 1 commit into
deploy-core-5-remotefrom
deploy-core-6-metrics
Closed

raymondk wants to merge 1 commit into
deploy-core-5-remotefrom
deploy-core-6-metrics

Conversation

@raymondk

Copy link
Copy Markdown
Contributor

Sixth of six. Stacked on the remote server PR.

Why

The request metrics cannot see deploys. A deploy is one tools/call inside a POST, answered 200 whether it succeeded, failed or was refused because every slot was taken. The upload route is visible by status code, but one code covers several reasons.

What this PR adds

Where a server serves the deploy tools, the Metrics handle an embedder already builds also publishes these, as process totals:

Series What it answers
imcp2_deploys_running, imcp2_deploy_slots How full the server is
imcp2_deploy_refusals_total{reason} busy, session_busy, stopping, no_room. A sustained busy rate means the cap is too low
imcp2_deploys_total{outcome} succeeded, failed, rejected, setup_failed (the server's own failure), interrupted
imcp2_deploy_duration_seconds How long a deploy holds its slot
imcp2_deploy_uploads_total{outcome} accepted, bad_ticket, too_large, extracts_too_large, not_a_bundle, plugin_not_allowed, store_full, session_busy, body_error, storage_error
imcp2_deploy_upload_bytes, imcp2_deploy_bundle_extracted_bytes Real bundle sizes, to judge where the two limits should sit
imcp2_deploy_upload_store_bytes, ..._capacity_bytes What the deploy tools keep under the state directory
imcp2_deploy_uploads_held, imcp2_deploy_uploads_arriving Uploads waiting and in progress
  • No embedder code is needed: the series register through Metrics::new and the gauges update in Metrics::refresh.
  • Every label value is a variant named in code; nothing a client sends becomes a label. All series start at zero.
  • A deploy dropped mid-run and an upload abandoned mid-body are still counted.

Limitations

  • rejected includes a deploy refused because the session's identity could not be derived, whether the grant lapsed or Internet Identity was unreachable. The code cannot tell those apart today.
  • The deploy state reports counters to the first Metrics handle built over it.

Testing

One test drives uploads and deploy calls through the router and checks each series, including zero-fill and the gauges after a refresh. The succeeded, failed and interrupted outcomes need a deploy against a network and are covered only by the classification unit test.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV

@raymondk
raymondk requested a review from a team as a code owner November 19, 2026 02:52
Copilot AI max review requested due to automatic review settings November 19, 2026 02:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Upload-handler cancellation can misclassify retained bundles and lose acceptance and size metrics, while post-claim refusals are omitted from slot-duration metrics and slot-holder totals.

2 open issues
What changed in this PR

Adds process-wide Prometheus metrics for deploy tools and bundle uploads, exposing outcomes and resource usage that HTTP status metrics cannot distinguish.

Changes:

  • Registers zero-initialized counters, gauges, and duration/size histograms through the existing Metrics API.
  • Connects deploy observers and upload reporting, with gauges updated by Metrics::refresh.
  • Adds router-level integration coverage and documents the new series.
File Description
src/​metrics/​deploy.rs Defines deploy and upload collectors, labels, and reporting methods.
src/​metrics.rs Registers deploy collectors and refreshes their gauges.
src/​deploy.rs Connects outcome reporting and adds metrics integration tests.
README.md Documents deploy metrics and embedder integration.

Review effort: Max

Comment thread src/deploy.rs
Comment on lines +542 to +543
if let Some(metrics) = self.0.take().as_ref().and_then(|m| m.0.get()) {
metrics.upload(Upload::BodyError);
Comment thread src/metrics/deploy.rs
Comment on lines +255 to +257
fn ended(&self, how: Ended, lasted: Duration) {
self.deploys.with_label_values(&[how.as_str()]).inc();
self.duration.observe(lasted.as_secs_f64());
@raymondk
raymondk added this pull request to stack #260 November 19, 2026 03:11
@raymondk
raymondk marked this pull request as draft November 19, 2026 03:12
@raymondk
raymondk force-pushed the deploy-core-6-metrics branch from 59ff894 to 7a07457 Compare November 19, 2026 04:06
@raymondk
raymondk force-pushed the deploy-core-6-metrics branch from 7a07457 to 0873cc8 Compare November 19, 2026 15:59
A deploy is one `tools/call` inside a `POST`, answered 200 whether it
succeeded, failed or was refused for want of a slot, so the request
metrics say nothing about deploys; and the upload route's status codes
fold several reasons into one.

The `Metrics` handle an embedder already builds over its servers also
publishes, where a server serves the deploy tools, as totals for the
process:

- `imcp2_deploys_running` against `imcp2_deploy_slots`: how full it is.
- `imcp2_deploy_refusals_total{reason}`: busy, session_busy, stopping,
  no_room. A sustained rate of `busy` is a cap that is too low.
- `imcp2_deploys_total{outcome}`: succeeded, failed, rejected,
  setup_failed (the server's own failure, not the request's),
  interrupted; and `imcp2_deploy_duration_seconds`.
- `imcp2_deploy_uploads_total{outcome}`: accepted, bad_ticket, too_large,
  extracts_too_large, not_a_bundle, plugin_not_allowed, store_full,
  session_busy, body_error, storage_error.
- `imcp2_deploy_upload_bytes` and `imcp2_deploy_bundle_extracted_bytes`,
  which is where the two size limits should sit is read off.
- `imcp2_deploy_upload_store_bytes` against its capacity, and the uploads
  held and arriving: what the deploy tools keep under the state directory.

The counters are fed as things happen, a deploy dropped mid-run and an
upload abandoned mid-body included; the gauges by `Metrics::refresh`.
Every label value is a variant named in code: nothing a client sends
becomes a label. Every series starts at zero.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
@raymondk
raymondk force-pushed the deploy-core-6-metrics branch from 0873cc8 to f8ae6aa Compare November 19, 2026 16:21
@aterga aterga closed this Nov 19, 2026
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