Skip to content

Add new stats subcommands and improve historical stats#1678

Merged
jedisct1 merged 13 commits intomainfrom
fdenis/stats
Mar 10, 2026
Merged

Add new stats subcommands and improve historical stats#1678
jedisct1 merged 13 commits intomainfrom
fdenis/stats

Conversation

@jedisct1
Copy link
Contributor

@jedisct1 jedisct1 commented Mar 8, 2026

Change summary

This PR adds four new subcommands under stats to expose more of the Fastly stats and metrics APIs through the CLI.

stats aggregate provides aggregated stats across all services, with the usual time range and region filtering. stats usage shows bandwidth and request usage, with an optional --by-service flag to break the numbers down per service.

The two inspector commands, stats domain-inspector and stats origin-inspector, surface domain-level and origin-level metrics for a specific service.

Both accept time ranges as either RFC3339 or Unix timestamps, and support downsampling, datacenter and region filtering, group-by dimensions, pagination via cursors, and JSON output.

This PR also adds a --field flag to the existing stats historical command, allowing output to be filtered to a single stats field like bandwidth or requests.

It also fixes a bug where write errors in the output path were silently swallowed instead of being reported back to the caller.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  • Does your submission pass tests?

Changes to Core Features:

  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

User Impact

Four new commands. Users who previously had to call the API directly for these can now use the CLI.

jedisct1 added 7 commits March 8, 2026 12:56
Previously, write errors in the JSON and table output paths were logged
but silently swallowed. Now they are properly returned to the caller.

Also removes an unused service ID parameter from writeBlocksJSON.
Allows filtering historical stats output to a single field
(e.g. bandwidth, requests).
Adds `stats aggregate` for viewing cross-service aggregated stats.
Supports --from, --to, --by, --region, and --format flags.
Adds `stats usage` for viewing bandwidth/request usage stats.
Supports --by-service flag to break down usage per service,
and --from, --to, --by, --region, --format flags.
Adds `stats domain-inspector` for viewing domain-level metrics
for a Fastly service. Supports service ID/name lookup, time range
filtering (RFC3339/Unix), downsampling, domain/datacenter/region
filtering, group-by dimensions, pagination, and JSON output.
Adds `stats origin-inspector` for viewing origin-level metrics
for a Fastly service. Supports service ID/name lookup, time range
filtering (RFC3339/Unix), downsampling, host/datacenter/region
filtering, group-by dimensions, pagination, and JSON output.
Reflects the newly added subcommands in the stats help text.
@jedisct1 jedisct1 requested a review from a team as a code owner March 8, 2026 12:02
No need to compute the hit rate, the API provides it.

Also fixes the --field test cases to use the CLIScenario struct
format.
Copy link
Contributor

@anthony-gomez-fastly anthony-gomez-fastly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, if we need a second reviewer for LLM reasons please add them

@jedisct1 jedisct1 enabled auto-merge (squash) March 10, 2026 16:12
@jedisct1 jedisct1 merged commit 08e3681 into main Mar 10, 2026
13 checks passed
@jedisct1 jedisct1 deleted the fdenis/stats branch March 10, 2026 16:53
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.

3 participants