[PR #311] [MERGED] feat: add sandbox metrics collection APIs #340

Closed
opened 2026-10-29 14:22:23 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/kvcache-ai/AgentENV/pull/311
Author: @zlzGithub-0801
Created: 9/22/2026
Status: ✅ Merged
Merged: 9/24/2026
Merged by: @yingdi-shan

Base: main ← Head: feat/metrics


📝 Commits (1)

  • c09b28e feat: add sandbox metrics collection APIs

📊 Changes

25 files changed (+2209 additions, -13 deletions)

View changed files

📝 config/default.toml (+4 -0)
📝 docs/src/concepts/sandboxes/working.md (+51 -0)
📝 docs/src/configuration/reference.md (+2 -0)
➕ services/gateway/internal/sandbox_metrics.go (+183 -0)
➕ services/gateway/internal/sandbox_metrics_test.go (+118 -0)
📝 services/gateway/internal/server.go (+7 -0)
📝 src/api/generated/src/apis/sandboxes.rs (+57 -0)
📝 src/api/generated/src/models.rs (+445 -0)
📝 src/api/generated/src/server/mod.rs (+325 -0)
📝 src/api/impls/sandbox.rs (+144 -0)
📝 src/api/openapi.yml (+134 -0)
📝 src/api/proxy.rs (+72 -0)
📝 src/cfg.rs (+5 -0)
➕ src/orchestrator/sandbox_metrics.rs (+266 -0)
📝 src/orchestrator/service.rs (+8 -1)
📝 src/orchestrator/tests.rs (+224 -2)
📝 src/sandbox/backend.rs (+8 -0)
📝 src/sandbox/envd.rs (+36 -0)
📝 src/sandbox/firecracker/sandbox.rs (+7 -0)
➕ src/sandbox/metrics.rs (+80 -0)

...and 5 more files

📄 Description

What

Add E2B-compatible sandbox metrics collection and query APIs:

  • GET /sandboxes/{sandboxID}/metrics
  • GET /sandboxes/metrics

Metrics are collected from envd and retained in node-local memory.

Why

AgentENV exposed envd metrics but did not collect, retain, or serve them through its E2B-compatible control-plane API.

Closes #294
#5

Scope and non-goals

Includes envd metric collection, in-memory retention, gateway aggregation, OpenAPI definitions, generated API code, tests, configuration, and user documentation.

Design and behavior changes

The orchestrator collects metrics from all running sandboxes every metrics_interval_secs and retains them for metrics_retention_secs. The defaults are 15 seconds and 3600 seconds, respectively, and both can be configured in default.toml.

Metrics collection is triggered either by sandbox lifecycle changes or by the periodic timer. The orchestrator retrieves each sample through the envd metrics API and stores the retained history in an in-memory HashMap.

For GET /sandboxes/{sandboxID}/metrics, the gateway routes the request to the node hosting that sandbox. For GET /sandboxes/metrics, the gateway groups the requested sandbox IDs by node, sends one request to each node, and combines the node responses.

Compatibility and operations

  • Public API or generated protocol: Adds two E2B-compatible endpoints and the SandboxMetric response model.
  • Configuration or defaults: Adds metrics_interval_secs = 15 and metrics_retention_secs = 3600 under [orchestrator].
  • Snapshot manifest, artifact layout, or storage format: N/A.
  • Upgrade and rollback: N/A.
  • Host requirements, permissions, ports, or dependencies: N/A.

Validation

  • make fmt
  • make clippy
  • make test-unit
  • Relevant Rust integration tests
  • make -C services test (required when services/ changes)
  • Generated clients/server regenerated with the documented make target
  • Documentation updated
  • Benchmarks or performance comparison completed

Manual deployment validation covered history and batch queries, time filtering, CPU and disk load, pause/resume behavior, and invalid requests.

Skipped checks and reasons:

Full repository and service test suites were not run. No benchmarks were added because collection is bounded and runs asynchronously.

Risks and reviewer notes

Metrics are node-local and non-durable. A node restart clears retained history. Collection depends on envd availability; failed or timed-out samples are skipped rather than stored as zero values.

The main review areas are the orchestrator collection lifecycle, runtime-generation validation, gateway batch aggregation, and OpenAPI contract.

Checklist

  • The PR contains one coherent change and no unrelated formatting or refactoring.
  • New behavior is covered by tests, or I explained why testing is impractical.
  • Logs and examples contain no credentials, tokens, or private registry information.
  • I did not manually edit generated code without updating its source and regenerating it.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/kvcache-ai/AgentENV/pull/311 **Author:** [@zlzGithub-0801](https://github.com/zlzGithub-0801) **Created:** 9/22/2026 **Status:** ✅ Merged **Merged:** 9/24/2026 **Merged by:** [@yingdi-shan](https://github.com/yingdi-shan) **Base:** `main` ← **Head:** `feat/metrics` --- ### 📝 Commits (1) - [`c09b28e`](https://github.com/kvcache-ai/AgentENV/commit/c09b28e090a71d29b1052339cf2cb0ee2b7ac57a) feat: add sandbox metrics collection APIs ### 📊 Changes **25 files changed** (+2209 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `config/default.toml` (+4 -0) 📝 `docs/src/concepts/sandboxes/working.md` (+51 -0) 📝 `docs/src/configuration/reference.md` (+2 -0) ➕ `services/gateway/internal/sandbox_metrics.go` (+183 -0) ➕ `services/gateway/internal/sandbox_metrics_test.go` (+118 -0) 📝 `services/gateway/internal/server.go` (+7 -0) 📝 `src/api/generated/src/apis/sandboxes.rs` (+57 -0) 📝 `src/api/generated/src/models.rs` (+445 -0) 📝 `src/api/generated/src/server/mod.rs` (+325 -0) 📝 `src/api/impls/sandbox.rs` (+144 -0) 📝 `src/api/openapi.yml` (+134 -0) 📝 `src/api/proxy.rs` (+72 -0) 📝 `src/cfg.rs` (+5 -0) ➕ `src/orchestrator/sandbox_metrics.rs` (+266 -0) 📝 `src/orchestrator/service.rs` (+8 -1) 📝 `src/orchestrator/tests.rs` (+224 -2) 📝 `src/sandbox/backend.rs` (+8 -0) 📝 `src/sandbox/envd.rs` (+36 -0) 📝 `src/sandbox/firecracker/sandbox.rs` (+7 -0) ➕ `src/sandbox/metrics.rs` (+80 -0) _...and 5 more files_ </details> ### 📄 Description ## What Add E2B-compatible sandbox metrics collection and query APIs: - `GET /sandboxes/{sandboxID}/metrics` - `GET /sandboxes/metrics` Metrics are collected from envd and retained in node-local memory. ## Why AgentENV exposed envd metrics but did not collect, retain, or serve them through its E2B-compatible control-plane API. ## Related issue Closes #294 #5 ## Scope and non-goals Includes envd metric collection, in-memory retention, gateway aggregation, OpenAPI definitions, generated API code, tests, configuration, and user documentation. ## Design and behavior changes The orchestrator collects metrics from all running sandboxes every `metrics_interval_secs` and retains them for `metrics_retention_secs`. The defaults are 15 seconds and 3600 seconds, respectively, and both can be configured in `default.toml`. Metrics collection is triggered either by sandbox lifecycle changes or by the periodic timer. The orchestrator retrieves each sample through the envd metrics API and stores the retained history in an in-memory HashMap. For `GET /sandboxes/{sandboxID}/metrics`, the gateway routes the request to the node hosting that sandbox. For `GET /sandboxes/metrics`, the gateway groups the requested sandbox IDs by node, sends one request to each node, and combines the node responses. ## Compatibility and operations - Public API or generated protocol: Adds two E2B-compatible endpoints and the `SandboxMetric` response model. - Configuration or defaults: Adds `metrics_interval_secs = 15` and `metrics_retention_secs = 3600` under `[orchestrator]`. - Snapshot manifest, artifact layout, or storage format: N/A. - Upgrade and rollback: N/A. - Host requirements, permissions, ports, or dependencies: N/A. ## Validation - [x] `make fmt` - [x] `make clippy` - [x] `make test-unit` - [x] Relevant Rust integration tests - [x] `make -C services test` (required when `services/` changes) - [x] Generated clients/server regenerated with the documented `make` target - [x] Documentation updated - [ ] Benchmarks or performance comparison completed Manual deployment validation covered history and batch queries, time filtering, CPU and disk load, pause/resume behavior, and invalid requests. Skipped checks and reasons: Full repository and service test suites were not run. No benchmarks were added because collection is bounded and runs asynchronously. ## Risks and reviewer notes Metrics are node-local and non-durable. A node restart clears retained history. Collection depends on envd availability; failed or timed-out samples are skipped rather than stored as zero values. The main review areas are the orchestrator collection lifecycle, runtime-generation validation, gateway batch aggregation, and OpenAPI contract. ## Checklist - [x] The PR contains one coherent change and no unrelated formatting or refactoring. - [x] New behavior is covered by tests, or I explained why testing is impractical. - [x] Logs and examples contain no credentials, tokens, or private registry information. - [x] I did not manually edit generated code without updating its source and regenerating it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 14:22:23 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kvcache-ai/AgentENV#340
No description provided.