Skip to content

feat(serverless): add usage command with the billed usage per space - #269

Merged
Robert-Stam merged 2 commits into
mainfrom
feat/serverless-usage-breakdown
Nov 25, 2026
Merged

Robert-Stam merged 2 commits into
mainfrom
feat/serverless-usage-breakdown

Conversation

@Robert-Stam

Copy link
Copy Markdown
Contributor

Summary

Adds qcloud serverless usage, which shows the billed serverless usage per space and billable item from MeteringService.GetUsageBreakdown. Serverless spaces were added to that RPC in public API v0.234.0 (UsageBreakdownAccount.spaces), which this repo already uses, so no dependency bump is needed. Until now the CLI had no metering commands at all.

$ qcloud serverless usage --month 2026-10
Period: 2026-10-01 00:00:00 UTC to 2026-11-01 00:00:00 UTC

MONTH     SPACE      SPACE ID                               ITEM                                 QUANTITY            AMOUNT   DISCOUNT       NET
2026-10   -          7f1e2d3c-4b5a-4968-8776-655443322110   Serverless Search Requests           1234567 requests    $20.00   $5.00 (25%)    $15.00
2026-10   products   0e7a3c1d-5f2b-4c8e-9a6d-1b2c3d4e5f60   Serverless Stored Data (GiB-month)   12.3457 GiB-month   $12.34   -              $12.34

Total: $27.34

Period

Flags Period sent to the API
none First day of the current month (UTC) to now
--month 2026-10 The whole month, [2026-10-01, 2026-11-01). For the current month the end is cut to now. Future months are rejected.
--since / --until RFC3339, YYYY-MM-DD or a duration ago, read with the shared util.ReadTimeRange. --until defaults to now and is cut to now. Without --since the period starts on the first day of the month of --until, or the month before when --until is exactly the first instant of a month.

--month can't be combined with --since or --until.

Output

  • One row per month, space and billable item, sorted by month, account, space name and item. SPACE shows - when the API can no longer resolve the name, for example for a deleted space.
  • NET = AMOUNT - DISCOUNT. Total is the net sum, with one amount per currency if there is more than one. output.Millicents formats non-USD amounts as 1,234.56 EUR.
  • For a parent billing account, the response includes child accounts, and an ACCOUNT column appears when more than one account has space usage.
  • --space <id> filters to one space on the client side, because the RPC has no space filter. Completion uses SpaceIDCompletion.
  • Cluster usage and funding.credits_drawn are removed, from --json too. Both cover all of the account's usage, not only serverless, so they would be misleading under qcloud serverless. Months and accounts with no space usage left are dropped. If we want cluster usage in the CLI, I'd add a separate top-level command (for example qcloud usage) rather than mixing it in here.

The RPC needs the read:payment_information permission. The help text says so.

Plumbing

  • qcloudapi.Client.Metering(), testutil.FakeMeteringService, registered in the test server.
  • output.Millicents(int64, currency) next to output.USDMillicents.

Testing

  • usage_test.go: text output (columns, quantity, discount, net, total, clusters and cluster-only months hidden, sorting, unknown space name), default period, --month (past and current), --since/--until, --until only (mid-month and first instant of a month), --space (match and no match), parent account column, mixed currencies, JSON (clusters and funding stripped), input errors with no API call, and the backend error.
  • money_test.go: output.Millicents.
  • make lint, make build, make test and make docs (docs regenerated) pass. I haven't run it against the real API.

🤖 Generated with Claude Code

Written with Overlord from https://overlord.qdrant.tech/r/1089/t/7445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Robert-Stam
Robert-Stam requested a review from a team November 25, 2026 14:41
@Robert-Stam
Robert-Stam requested a review from a team as a code owner November 25, 2026 14:41
@Robert-Stam
Robert-Stam merged commit f48f3ab into main Nov 25, 2026
5 checks passed
@Robert-Stam
Robert-Stam deleted the feat/serverless-usage-breakdown branch November 25, 2026 15:16
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.

3 participants