Add script for generating API usage report#5197
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA new Elixir script builds api_call_subscription_analysis.csv by querying ClickHouse for per-user API-key call counts (30/60/90 days), fetching user emails and subscriptions from Postgres, labeling plans as "(active)" or "(expired)", and writing one CSV row per eligible user. ChangesAPI Call Subscription Analysis Report
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/api_call_subscription_analysis.exs`:
- Around line 131-137: The query condition combining s.status and
s.current_period_end is causing non-active statuses (e.g., :trialing or
canceled-but-not-expired) to be treated as active; remove the current_period_end
check from the status filter and instead determine "active/expired" after
fetching by comparing s.current_period_end to DateTime.utc_now(). Concretely:
change the from(...) where clause that currently uses "s.status in [:active,
:past_due] or s.current_period_end >= ^cutoff" to only filter by status (or only
by user_ids if you want all subs), and update the labeling logic to use
s.current_period_end >= DateTime.utc_now() (or the cutoff variable computed from
DateTime.utc_now()) to decide if a subscription is expired.
- Around line 137-143: The query in fetch_subscriptions/1 currently selects rows
with any status when s.current_period_end >= ^cutoff, but the label logic only
distinguishes active/past_due vs "expired", causing future or pending
subscriptions to be mislabeled; update the where clause to only include
subscriptions that have actually ended in the recent window (e.g., add
s.current_period_end < ^now or require status in [:canceled, :past_due]
depending on intent) or alternatively change the label logic to check the
timestamp (s.current_period_end < ^now) when deciding between " (expired)" and
other states; make this change inside fetch_subscriptions/1, referencing
s.current_period_end, cutoff/now and the status check to keep labels consistent
with the query.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6642743d-8679-4ce1-84b3-c251f611b1f7
📒 Files selected for processing (1)
scripts/api_call_subscription_analysis.exs
032da9b to
c9c243b
Compare
c9c243b to
2492cd8
Compare
Changes
Ticket
Checklist:
Summary by CodeRabbit
New Features
Chores