Skip to content

fix: reset metering billing cycles without Redis KEYS - #743

Merged
kang-heewon merged 1 commit into
trunkfrom
fix/703-redis-reset-without-keys
Jun 14, 2026
Merged

fix: reset metering billing cycles without Redis KEYS#743
kang-heewon merged 1 commit into
trunkfrom
fix/703-redis-reset-without-keys

Conversation

@kang-heewon

@kang-heewon kang-heewon commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #703.

RedisUsageStorage.resetBillingCycle(tenantId) now resets tenant-wide billing cycle usage with bounded Redis SCAN batches instead of the blocking KEYS command. Single-meter reset keeps the exact-key delete path, and tenant-wide patterns now escape Redis glob metacharacters in tenant IDs.

변경 사항

  • Replaced the tenant-wide reset Lua KEYS script with repeated SCAN MATCH ... COUNT 500 batches that delete only each returned batch.
  • Added RedisUsageStorage regressions for single-meter reset, cursor batching, Redis-like tenant-wide deletion behavior, and tenant glob escaping.
  • Documented tenant-wide reset idempotency/operational behavior and added a patch changeset for @croco/metering-core.
  • Regenerated the @croco/testing API docs from Typedoc so the required docs-sync and docs-catalog checks agree on trunk-generated documentation.

Verification

  • pnpm --filter @croco/metering-core exec vitest run src/tests/RedisUsageStorage.spec.ts --reporter verbose - 26 tests passed.
  • pnpm --filter @croco/metering-core test - 13 files, 158 tests passed.
  • pnpm test --filter=@croco/metering-core - 14 Turbo tasks passed.
  • pnpm typecheck --filter=@croco/metering-core - 14 Turbo tasks passed.
  • pnpm build --filter=@croco/metering-core - 7 Turbo tasks passed.
  • pnpm --filter @croco/metering-core lint - 0 warnings/errors.
  • pnpm docs:build - generated docs successfully and emitted @croco/testing API reference pages.
  • pnpm check - passed package manifest, docs catalog, circular dependency, oxlint, and oxfmt checks after docs regeneration.
  • pnpm exec changeset status --since origin/trunk - patch bump reported for @croco/metering-core and dependent packages.
  • Pre-push hook: full pnpm test 197/197 tasks passed; full pnpm typecheck 196/196 tasks passed.

Self-review

  • Correctness/regression: PASS. [metering-core] RedisUsageStorage.resetBillingCycle이 tenant-wide reset에서 KEYS를 사용함 #703 acceptance is covered by the Redis-like fake-keyspace reset test, which deletes only same-tenant/current-cycle usage keys while preserving other tenants, other cycles, and idempotency keys. The script-shape regression also proves tenant-wide reset uses SCAN and not KEYS.
  • API/security/compatibility/release: PASS. RedisClient and UsageStorage public contracts are unchanged, no dependencies or lockfile entries changed, tenant glob metacharacters are escaped before MATCH, and a patch changeset covers the runtime behavior change.
  • Maintainability/minimality: PASS. The runtime change is localized to RedisUsageStorage, keeps single-meter reset unchanged, uses the existing eval boundary, and avoids new abstractions or unrelated cleanup.
  • Adversarial review: PASS after fix. Review found the initial test only proved script shape; the fake-keyspace behavior test was added and all validation was rerun.

Risk

Low to moderate. Tenant-wide reset still scans the Redis keyspace, but it does so in bounded batches instead of blocking on KEYS. Redis Cluster-specific Lua key declaration restrictions are not covered by the current RedisClient test harness; this PR keeps the existing eval-based storage boundary unchanged.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@kang-heewon, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 32 minutes and 16 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 45ca2367-caaf-4665-b4a8-42836b430422

📥 Commits

Reviewing files that changed from the base of the PR and between 4e329aa and 8ee40e7.

📒 Files selected for processing (23)
  • .changeset/metering-reset-scan.md
  • packages/docs/astro.config.mjs
  • packages/docs/src/content/docs/api/testing/index.md
  • packages/docs/src/content/docs/api/testing/src/classes/CrocoTestingApp.md
  • packages/docs/src/content/docs/api/testing/src/functions/assertOpenAPIRoute.md
  • packages/docs/src/content/docs/api/testing/src/functions/assertProblemResponse.md
  • packages/docs/src/content/docs/api/testing/src/functions/createRpcTestFetch.md
  • packages/docs/src/content/docs/api/testing/src/functions/createTestingApp.md
  • packages/docs/src/content/docs/api/testing/src/functions/createTestingHarness.md
  • packages/docs/src/content/docs/api/testing/src/functions/readProblemResponse.md
  • packages/docs/src/content/docs/api/testing/src/functions/readResponseJson.md
  • packages/docs/src/content/docs/api/testing/src/functions/resetCrocoTestingContext.md
  • packages/docs/src/content/docs/api/testing/src/type-aliases/OpenAPIRouteExpectation.md
  • packages/docs/src/content/docs/api/testing/src/type-aliases/ProblemResponseExpectation.md
  • packages/docs/src/content/docs/api/testing/src/type-aliases/TestLogger.md
  • packages/docs/src/content/docs/api/testing/src/type-aliases/TestingAppOptions.md
  • packages/docs/src/content/docs/api/testing/src/type-aliases/TestingHarnessOptions.md
  • packages/docs/src/content/docs/api/testing/src/type-aliases/TestingProvider.md
  • packages/docs/src/content/docs/api/testing/src/type-aliases/TestingRequestOptions.md
  • packages/docs/tsconfig.typedoc.json
  • packages/metering-core/README.md
  • packages/metering-core/src/libs/RedisUsageStorage.ts
  • packages/metering-core/src/tests/RedisUsageStorage.spec.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/703-redis-reset-without-keys

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown

📊 Benchmark Results

❌ Some benchmarks failed

Benchmark p75 Threshold Baseline vs Baseline Status
CrocoApp benchmarks 3.3μs - - - ⚠️
EventBusConfig.start (10 handlers) 1.4μs - 9.0μs -84.6%
EventPublisher.publishNow single event 1.7μs - - - ⚠️
DefaultHandlerResolver.resolve × 10 0.1μs - 0.2μs -59.5%
Container.get singleton (cold) 1.0μs - 0.5μs +100.2%
Container.register × 50 components 10.6μs - 8.0μs +32.7%
Container.validate (50 components) 27.7μs - 25.0μs +10.8%
Container.get singleton (warm) 0.4μs - 0.3μs +33.7%
TelemetryRuntime benchmarks 1.9μs - 2.0μs -3.9%

Updated: 2026-06-14T21:07:29.884Z · Commit: 2beed79

@kang-heewon
kang-heewon force-pushed the fix/703-redis-reset-without-keys branch from 6fc54d1 to 539d672 Compare June 14, 2026 20:59
@kang-heewon
kang-heewon force-pushed the fix/703-redis-reset-without-keys branch from 539d672 to 8ee40e7 Compare June 14, 2026 21:03
@kang-heewon
kang-heewon merged commit 997d84d into trunk Jun 14, 2026
8 checks passed
@kang-heewon
kang-heewon deleted the fix/703-redis-reset-without-keys branch June 14, 2026 21:16
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.

[metering-core] RedisUsageStorage.resetBillingCycle이 tenant-wide reset에서 KEYS를 사용함

1 participant