Skip to content

fix: restore Redis usage timestamps - #741

Merged
kang-heewon merged 1 commit into
trunkfrom
fix-705-redis-usage-timestamps
Jun 14, 2026
Merged

fix: restore Redis usage timestamps#741
kang-heewon merged 1 commit into
trunkfrom
fix-705-redis-usage-timestamps

Conversation

@kang-heewon

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

Copy link
Copy Markdown
Member

Summary

Fixes #705.

RedisUsageStorage.fetchUsageRecords() now restores each usage record timestamp from the Redis sorted-set score instead of substituting the read time. The Redis client contract exposes the existing Redis WITHSCORES path, and the Upstash adapter maps that to zrange(..., { byScore: true, withScores: true }).

변경 사항

  • Fetch usage records with Redis scores and reconstruct UsageRecord.timestamp from those scores.
  • Treat malformed or score-less WITHSCORES responses as explicit Redis read errors instead of falling back to new Date().
  • Keep usage total reads member-only so existing aggregation behavior stays unchanged.
  • Add RedisUsageStorage and Upstash adapter regressions, plus patch changesets for @croco/metering-core and @croco/metering-upstash.
  • Regenerate the affected API docs and align the docs catalog with the generated @croco/testing API-doc baseline so docs drift checks remain stable.

Verification

  • pnpm --filter @croco/metering-core exec vitest run src/tests/RedisUsageStorage.spec.ts - 23 tests passed.
  • pnpm --filter @croco/metering-upstash exec vitest run src/tests/UpstashRedisClient.spec.ts - 10 tests passed.
  • pnpm --filter @croco/metering-core test - 155 tests passed.
  • pnpm --filter @croco/metering-upstash test - 10 tests passed.
  • pnpm --filter @croco/metering-core typecheck - passed.
  • pnpm --filter @croco/metering-upstash typecheck - passed.
  • pnpm --filter @croco/metering-core build - passed.
  • pnpm --filter @croco/metering-upstash build - passed.
  • pnpm docs:catalog:check - passed.
  • pnpm turbo run docs:build --force && git diff --exit-code -- packages/docs/src/content/docs/api/ && git diff --check - passed.
  • pnpm check - passed.
  • Pre-push pnpm test - 197/197 tasks successful.
  • Pre-push pnpm typecheck - 196/196 tasks successful.

Self-review

  • Correctness/regression: PASS. The regression test verifies two records with different Redis scores return matching timestamps in score order, metadata still round-trips, empty reads still return [], and missing scores throw RedisProblem.
  • API/security/compatibility/release: PASS. RedisClient.zrangebyscore keeps the existing three-argument member-only call and adds the Redis-compatible WITHSCORES overload; Upstash implements the new path; no dependencies, secrets, or lockfile entries changed; patch changesets cover the publishable behavior.
  • Maintainability/minimality: PASS. The behavior diff is limited to Redis record reading, the one official adapter, focused tests, release metadata, and generated/docs-catalog updates required by the repository checks. An independent code-reviewer pass found no actionable issues.

Risk

Low. No live Redis or Upstash service was run locally; validation uses the repository adapter contract and the installed Upstash SDK implementation/types for the withScores option shape.

@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 38 minutes and 15 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: d9f3b06c-cf3e-424d-95f7-094a555ca1f1

📥 Commits

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

📒 Files selected for processing (11)
  • .changeset/redis-usage-timestamps.md
  • README.md
  • docs/package-docs-baseline.json
  • docs/package-docs-report.md
  • packages/docs/src/content/docs/api/metering-core/src/interfaces/RedisClient.md
  • packages/docs/src/content/docs/api/testing/index.md
  • packages/metering-core/src/libs/RedisClient.ts
  • packages/metering-core/src/libs/RedisUsageStorage.ts
  • packages/metering-core/src/tests/RedisUsageStorage.spec.ts
  • packages/metering-upstash/src/libs/UpstashRedisClient.ts
  • packages/metering-upstash/src/tests/UpstashRedisClient.spec.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-705-redis-usage-timestamps

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.2μs - - - ⚠️
EventBusConfig.start (10 handlers) 1.4μs - 9.0μs -84.4%
EventPublisher.publishNow single event 1.6μs - - - ⚠️
DefaultHandlerResolver.resolve × 10 0.1μs - 0.2μs -60.0%
Container.get singleton (cold) 1.0μs - 0.5μs +92.4%
Container.register × 50 components 10.9μs - 8.0μs +36.4%
Container.validate (50 components) 28.0μs - 25.0μs +12.2%
Container.get singleton (warm) 0.4μs - 0.3μs +27.0%
TelemetryRuntime benchmarks 2.0μs - 2.0μs +0.1%

Updated: 2026-06-14T21:01:19.295Z · Commit: 56c5f2e

@kang-heewon
kang-heewon force-pushed the fix-705-redis-usage-timestamps branch from ee5d952 to de1f9d2 Compare June 14, 2026 20:57
@kang-heewon
kang-heewon merged commit 4f24761 into trunk Jun 14, 2026
8 checks passed
@kang-heewon
kang-heewon deleted the fix-705-redis-usage-timestamps branch June 14, 2026 21:10
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] fetchUsageRecords가 Redis sorted set score의 원래 timestamp를 버림

1 participant