Skip to content

[WIP] feat(e2b): add dimension-aware API key quota#565

Open
AiRanthem wants to merge 1 commit into
openkruise:masterfrom
AiRanthem:feature/e2b-api-quota-260622
Open

[WIP] feat(e2b): add dimension-aware API key quota#565
AiRanthem wants to merge 1 commit into
openkruise:masterfrom
AiRanthem:feature/e2b-api-quota-260622

Conversation

@AiRanthem

Copy link
Copy Markdown
Member

Summary

  • add API-key quota modeling for sandbox count plus CPU and memory dimensions
  • enforce quota admission and release in the E2B create/clone flows with Redis-backed live-set tracking
  • add cache health, leader lifecycle, anti-drift reconciliation, storage, config, and documentation updates

Impact

This lets sandbox-manager reject over-quota API key usage before creating new sandbox resources, while keeping the quota implementation scoped to the E2B API and sandbox-manager layers.

Validation

  • GOCACHE=/private/tmp/go-build-cache /Users/sophon/Bin/go test ./pkg/cache ./pkg/sandbox-manager ./pkg/sandbox-manager/infra/sandboxcr ./pkg/servers/e2b ./pkg/servers/e2b/keys ./pkg/servers/e2b/models ./pkg/servers/e2b/quota

@kruise-bot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign furykerry for approval by writing /assign @furykerry in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@AiRanthem AiRanthem changed the title [codex] Add dimension-aware API key quota enforcement feat(e2b): add dimension-aware API key quota Jun 23, 2026
@AiRanthem AiRanthem marked this pull request as ready for review June 23, 2026 03:42
@AiRanthem AiRanthem changed the title feat(e2b): add dimension-aware API key quota [WIP] feat(e2b): add dimension-aware API key quota Jun 23, 2026
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.88060% with 385 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.32%. Comparing base (bfa04b5) to head (2117df0).

Files with missing lines Patch % Lines
pkg/servers/e2b/quota/antidrift.go 75.98% 52 Missing and 27 partials ⚠️
pkg/sandbox-manager/leader.go 60.43% 46 Missing and 9 partials ⚠️
pkg/servers/e2b/models/quota.go 61.97% 50 Missing and 4 partials ⚠️
pkg/cache/cache.go 48.14% 39 Missing and 3 partials ⚠️
pkg/servers/e2b/quota/redis.go 71.81% 22 Missing and 20 partials ⚠️
pkg/servers/e2b/keys/secret.go 78.12% 14 Missing and 7 partials ⚠️
pkg/servers/e2b/core.go 71.87% 12 Missing and 6 partials ⚠️
pkg/servers/e2b/keys/mysql.go 81.81% 7 Missing and 7 partials ⚠️
pkg/sandbox-manager/core.go 40.00% 11 Missing and 1 partial ⚠️
pkg/servers/e2b/create.go 75.00% 9 Missing and 2 partials ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #565      +/-   ##
==========================================
- Coverage   79.82%   79.32%   -0.50%     
==========================================
  Files         202      211       +9     
  Lines       14791    16209    +1418     
==========================================
+ Hits        11807    12858    +1051     
- Misses       2553     2821     +268     
- Partials      431      530      +99     
Flag Coverage Δ
unittests 79.32% <73.88%> (-0.50%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AiRanthem AiRanthem force-pushed the feature/e2b-api-quota-260622 branch from 66b42c2 to ad19bc4 Compare June 25, 2026 02:54
Implement Redis-backed API key quota enforcement for sandbox count, CPU, and memory dimensions across E2B admission and sandbox-manager create paths.

Add quota storage, live accounting, anti-drift reconciliation, fail-open breaker behavior, metrics, config wiring, and focused unit coverage. Fold in follow-up hardening for malformed key rows, failed admission release, delete-event release, resource footprint calculation, Redis breaker behavior, and leadership-loss event writes.

Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com>

� Conflicts:
�	pkg/sandbox-manager/infra/sandboxcr/clone_test.go
�	pkg/servers/e2b/create.go
�	pkg/servers/e2b/create_test.go
@AiRanthem AiRanthem force-pushed the feature/e2b-api-quota-260622 branch from ad19bc4 to 2117df0 Compare June 25, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants