Context
With the design from #221, we now build the feature that measures how long each compute instance actually runs and reports per-second CPU and memory usage to the platform's billing pipeline. The implementation follows the approved design.
What this issue covers
We build the capability to measure how long each instance actually runs and report that usage to the billing pipeline. Customers are billed only while an instance is running — the final slice of time is reported when an instance stops, suspends, or is terminated, and nothing accrues while it's not running.
The metering has to stay accurate through failures, so a failure never loses or double-counts usage. We also follow the design's guidance on how the feature is switched on, how operators can tell usage is flowing, and how we verify the running, stopped, suspended, and failure paths are handled correctly.
Scope
Implementation details below are a checklist derived from the approved design doc; adjust to match what the design actually specifies.
- Usage emitter: compute per-second usage (vCPU-seconds and memory byte-seconds) for each running interval and hand it off to the billing pipeline.
- Lifecycle handling: report in intervals while running; report the final partial interval on stop/terminate/suspend; bill nothing while not running.
- Idempotency / retries: failed hand-offs retry the same window; a crash between hand-off and watermark save must not double-count (confirm the pipeline dedups by content).
- Meter wiring: declare/register the CPU and memory meter definitions that match the billing platform's expectations.
- Enablement: ship behind a feature gate (off by default) and gateable configuration so a deployment can opt in and roll back cleanly.
- Observability: surface "usage emitted" vs "usage errored/rejected" signals so billing health is visible.
- Tests: cover running/stopped/suspended lifecycle, interval reporting, retry idempotency, crash-recovery, and the disabled/no-op path.
Context
With the design from #221, we now build the feature that measures how long each compute instance actually runs and reports per-second CPU and memory usage to the platform's billing pipeline. The implementation follows the approved design.
What this issue covers
We build the capability to measure how long each instance actually runs and report that usage to the billing pipeline. Customers are billed only while an instance is running — the final slice of time is reported when an instance stops, suspends, or is terminated, and nothing accrues while it's not running.
The metering has to stay accurate through failures, so a failure never loses or double-counts usage. We also follow the design's guidance on how the feature is switched on, how operators can tell usage is flowing, and how we verify the running, stopped, suspended, and failure paths are handled correctly.
Scope