Add scout billing and scout usage --billing-period backed by the /usage API - #23
Merged
Merged
Conversation
Closed
Contributor
Author
|
It would be nice to have per-app job throughput, but this is currently a limitation on the API side. One workaround would be to query /jobs per app per chunk and total the throughput on the client side, but I think it's a bit overly engineered when making the api change is cleaner and more accurate. I'll file an issue on the backend and try and get that API updated to support this better. It's a fairly narrow use case (having jobs take a significant percentage of your total transaction) but a nice to have. |
jrothrock
approved these changes
Sep 10, 2026
- `scout billing` now uses structuredOutput so --toon and piped output behave like every other command; the report renders one section per block the API returned (billing period, APM, nodes, errors, logs) - `scout usage --billing-period` fetches /usage once, shows the billing period in the header, clamps the query window to now, and prints the server-reported billed total (web + jobs) under the per-app table so the throughput-based calculation can be compared against the exact figure - Add httptest coverage for GetOrgUsage (live payload, minimal payload, plan limit) and unit tests for the billing renderers - Document `scout billing` and `--billing-period` in README and CHANGELOG Closes #8 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BK3fzED9ksTWsvoPfsEwpS
The logs limit reported by /usage is ~10.7 TB and rendered as "10736.3 GB" in `scout billing`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BK3fzED9ksTWsvoPfsEwpS
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BK3fzED9ksTWsvoPfsEwpS
The per-app figures in `scout usage` come from the throughput metric, which counts web requests only, while the billed total from /usage also includes background jobs. Rename the table headers to "Web Transactions" and "% of Web", say "web transactions" in the total footers, and explain the distinction in the command's Long help and the README. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BK3fzED9ksTWsvoPfsEwpS
Replace the live billing period, transaction, node, error and log figures captured from a real account with round synthetic values so the public test suite does not carry account data. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BK3fzED9ksTWsvoPfsEwpS
quinnmil
force-pushed
the
8-usage-billing-endpoint
branch
from
September 10, 2026 21:09
f6fdb0b to
7119b07
Compare
This was referenced Sep 10, 2026
Closed
Merged
This was referenced Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8
Summary
Consumes the new org-level
GET /api/v0/usageendpoint, which reports the exact figures Scout bills against for the current billing period.scout billing— new command showing billing period dates (with days remaining), pricing style, APM transactions (with plan limit + usage bar when the plan has one), active nodes (per-node pricing), errors (when the add-on is enabled), and log bytes (when a logs integration is enabled). Sections the API omits are not shown. Supports--json,--toon, and auto-TOON when piped.scout usage --billing-period— scopes anyscout usagemode (--by-day,--by-app,--app) to the exact billing period dates from the API instead of--from/--to, prints the billing period in the header, and prints the server-reported billed total under the table.scout usagecolumns are now labeled as web transactions (Web Transactions,% of Web, "Total: N web transactions"). The throughput metric the command is built on excludes background jobs, so the old% of Totalheader was misleading for job-heavy orgs. JSON/TOON field names are unchanged.Builds on the earlier
8-billing-databranch (original commit preserved) and modernizes it for TOON output and the currentusagecode.Examples
Sample output (illustrative values)
Why the two totals differ
The per-app numbers come from the app
throughputmetric, whichQueries::Throughputhard-codes tometric_type = 'Controller'(web requests only). The/usagetotal counts web + background job transactions. Reconciled against a live org by adding per-job throughput × minutes to the web sum: within 0.1% of the server total. The footer labels this explicitly so the gap isn't read as a bug. A per-app breakdown that includes jobs needs an API change; tracked in scoutapp/apm#5686.Implementation notes
/usageis fetched once per invocation and threaded through all usage modes via a smallusageTimeframestruct.splitTimeframechunking handles that.--billing-periodis mutually exclusive with--from/--to.scout usage --billing-periodkeeps the same shape as before (per-app list); usescout billing --jsonfor the billing payload.output.FormatBytesgained a TB tier.Test plan
go test -race ./...,go vet,gofmt,golangci-lint run— cleanTestGetOrgUsage(full payload),TestGetOrgUsageMinimal(optional sections nil),TestGetOrgUsageWithLimitrenderBillingSummary,renderUsageBar,formatBillingDate,parseBillingTime,daysRemaining,serverTotalLine,FormatBytesTBscout billing(human/JSON/TOON/piped),scout usage --billing-period(default,--by-day,--by-day --by-app),--billing-period --fromrejected🤖 Generated with Claude Code
https://claude.ai/code/session_01BK3fzED9ksTWsvoPfsEwpS