Define core metrics/traces for BatchSandbox controller and systematically integrate OpenTelemetry

Author: PangjipingCreated Sep 8, 2026Updated Sep 24, 2026

Summary

Define the core metrics and traces for the BatchSandbox controller (kubernetes/internal/controller/batchsandbox_controller.go) and systematically integrate OpenTelemetry (OTel) for instrumentation and export.

Motivation

The BatchSandbox controller is the core of pool scheduling and sandbox lifecycle reconciliation, but it has no systematic telemetry. A minimal, well-defined set of metrics and traces is needed to answer production questions: reconcile health, batch allocation latency, pool fill rate, and pause/resume outcomes.

Design Principles

  • Restrained by design: metrics and traces must stay minimal; avoid over-engineering
  • Core-only first phase: only the essential signals below; no speculative dashboards, exotic samplers, or per-subsystem metric sprawl in phase 1
  • Reuse standard OTel semantic conventions (including K8s controller semantic conventions) where they exist

Phase 1 Scope (core only)

  1. Core metrics

    • Reconcile loop: reconcile count and duration per controller (by result: success/error/requeue)
    • BatchSandbox lifecycle: create/delete/snapshot counts and durations (success vs error), current BatchSandbox count by phase/state
    • Pool allocation: allocation latency and success/error counts from the scheduler path
    • Workqueue depth (via standard controller-runtime metrics if already exposed — reuse, don't duplicate)
  2. Core traces

    • One span per reconcile attempt for BatchSandbox (and its sub-operations: allocation, pause/resume, snapshot) with name/namespace/phase attributes
    • Spans for downstream calls made by the controller (API server updates, server/runtime integration calls)
  3. OTel integration

    • Consistent tracer/meter provider setup in cmd/controller/main.go, wired from controller flags/config
    • OTLP exporter (endpoint, headers, interval) configurable; graceful shutdown flushing
    • Do not double-instrument what controller-runtime already exposes (workqueue, client metrics) — integrate rather than duplicate

Out of Scope (explicitly deferred)

  • Metrics for scheduler internals (bin-packing details, strategy internals), eviction/recycle subsystems
  • Per-node-agent or execd-side telemetry
  • Dashboards, alerting definitions, tail-based sampling
  • Traces for Pool/SandboxSnapshot controllers beyond minimal reuse of the same wiring (separate issue if needed)

Acceptance Criteria

  • Core metrics and traces are defined in a short telemetry spec under kubernetes/docs/ (names, types, attributes, units)
  • Controller emits the defined signals with standard OTel SDK setup configured via flags/config
  • Unit/env tests cover instrumentation wiring and key metric emission
  • Docs updated: how to enable/configure OTLP export for the controller, what signals to expect

Source: opensandbox-group/OpenSandbox