Add statistics & analytics endpoints (iter-13)#17
Conversation
Planned iterations cover remaining API coverage gaps: statistics, edge rules, access control, video processing, DNS security, and shield advanced features (~51 new API methods). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implements iteration 13: statistics endpoints for account, DNS zones, pull zones (optimizer/origin-shield/safehop), storage zones, video libraries (DRM/transcribing), stream libraries, and shield metrics (detailed/rate-limits/rate-limit/waf-rule/bot-detection/upload-scanning). Includes API client methods, CLI commands, types, fixtures, wiremock tests, and mock e2e CLI tests for all new endpoints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds statistics/analytics coverage across Hoppy’s CLI and underlying API client crates (core, stream, shield), wiring new endpoints into commands and adding fixtures + wiremock tests to validate request/response handling.
Changes:
- Added new CLI commands/subcommands for account statistics, pull zone statistics, DNS zone statistics, storage zone statistics, stream library statistics, and video library DRM/transcribing statistics.
- Implemented new API client methods and response types for the added statistics/metrics endpoints in
bunny-api-core,bunny-api-stream, andbunny-api-shield. - Added fixtures plus wiremock-based integration tests and CLI mock/live tests for the new endpoints; updated knowledgebase iteration docs and CLAUDE.md conventions.
Reviewed changes
Copilot reviewed 52 out of 52 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/cli_video_library.rs | Adds mock CLI tests for video library DRM/transcribing statistics endpoints. |
| tests/cli_stream.rs | Adds mock CLI test for stream library statistics and extends live lifecycle test to call new statistics endpoints. |
| tests/cli_storage_zone.rs | Adds mock CLI test and live lifecycle coverage for storage zone statistics. |
| tests/cli_statistics.rs | Adds mock + live CLI tests for account-level /statistics output in JSON/table formats. |
| tests/cli_shield.rs | Extends live Shield lifecycle to call additional metrics endpoints and adds mock tests for detailed/rate limit/bot/upload scanning metrics. |
| tests/cli_pull_zone.rs | Extends live pull zone lifecycle with optimizer/origin-shield/safehop statistics and adds mock tests for each endpoint. |
| tests/cli_dns.rs | Extends live DNS zone lifecycle and adds mock test for DNS zone statistics. |
| src/main.rs | Wires new statistics and video-library top-level commands into the CLI dispatch. |
| src/commands/video_library.rs | Implements video-library drm-statistics and transcribing-statistics CLI handlers. |
| src/commands/stream.rs | Adds stream library statistics handler and uses stream client stats endpoint. |
| src/commands/storage_zone.rs | Adds storage-zone statistics handler with JSON output and a brief non-JSON summary. |
| src/commands/statistics.rs | Implements the hoppy statistics command output (JSON + summary rows). |
| src/commands/shield.rs | Adds CLI handlers for additional Shield metrics endpoints (detailed, rate-limits, rate-limit, waf-rule, bot-detection, upload-scanning). |
| src/commands/pull_zone.rs | Adds pull zone statistics handler for optimizer/origin-shield/safehop stats. |
| src/commands/mod.rs | Exposes new statistics and video_library command modules. |
| src/commands/dns.rs | Adds DNS zone statistics handler. |
| src/cli.rs | Adds clap subcommands/flags for the new statistics and metrics commands. |
| hoppy-knowledgebase/iterations/iteration-18-shield-advanced.md | Adds planned iteration doc for Shield advanced features. |
| hoppy-knowledgebase/iterations/iteration-17-dns-security.md | Adds planned iteration doc for DNS security features. |
| hoppy-knowledgebase/iterations/iteration-16-stream-video-processing.md | Adds planned iteration doc for stream video processing. |
| hoppy-knowledgebase/iterations/iteration-15-pullzone-access-control.md | Adds planned iteration doc for pull zone access control. |
| hoppy-knowledgebase/iterations/iteration-14-edge-rules.md | Adds planned iteration doc for pull zone edge rules. |
| hoppy-knowledgebase/iterations/iteration-13-statistics.md | Adds completed iteration doc describing the statistics/analytics work delivered here. |
| hoppy-knowledgebase/development-roadmap.md | Updates roadmap with planned iterations 13–18 and removes outdated deferred note. |
| fixtures/stream/library_statistics.json | Adds stream library statistics fixture used by tests. |
| fixtures/shield/metrics_upload_scanning.json | Adds Shield upload scanning metrics fixture. |
| fixtures/shield/metrics_rate_limit.json | Adds Shield single rate-limit metrics fixture. |
| fixtures/core/videolibrary_transcribing_statistics.json | Adds core API fixture for video library transcribing statistics. |
| fixtures/core/videolibrary_drm_statistics.json | Adds core API fixture for video library DRM statistics. |
| fixtures/core/storagezone_statistics.json | Adds core API fixture for storage zone statistics. |
| fixtures/core/pullzone_safehop_statistics.json | Adds core API fixture for SafeHop statistics. |
| fixtures/core/pullzone_originshield_statistics.json | Adds core API fixture for origin shield queue statistics. |
| fixtures/core/pullzone_optimizer_statistics.json | Adds core API fixture for optimizer statistics. |
| fixtures/core/dnszone_statistics.json | Adds core API fixture for DNS zone statistics. |
| fixtures/core/account_statistics.json | Adds core API fixture for account-level statistics. |
| crates/bunny-api-stream/tests/stream_api.rs | Adds wiremock test validating the new stream library statistics client method. |
| crates/bunny-api-stream/src/types.rs | Adds VideoStatistics response type for stream statistics. |
| crates/bunny-api-stream/src/lib.rs | Re-exports VideoStatistics. |
| crates/bunny-api-stream/src/client.rs | Adds get_library_statistics method with query parameter support. |
| crates/bunny-api-shield/tests/shield_api.rs | Adds fixtures + wiremock tests for new Shield metrics endpoints. |
| crates/bunny-api-shield/src/types.rs | Adds detailed metrics and additional metrics response type definitions. |
| crates/bunny-api-shield/src/lib.rs | Re-exports the newly added Shield metrics types. |
| crates/bunny-api-shield/src/client.rs | Adds Shield client methods for the new metrics endpoints. |
| crates/bunny-api-core/tests/videolibrary_api.rs | Adds wiremock tests for core video library DRM/transcribing statistics endpoints. |
| crates/bunny-api-core/tests/storagezone_api.rs | Adds wiremock test for core storage zone statistics endpoint. |
| crates/bunny-api-core/tests/statistics_api.rs | Adds wiremock test for core account-level statistics endpoint. |
| crates/bunny-api-core/tests/pullzone_api.rs | Adds wiremock tests for core pull zone optimizer/originshield/safehop statistics endpoints. |
| crates/bunny-api-core/tests/dns_api.rs | Adds wiremock test for core DNS zone statistics endpoint. |
| crates/bunny-api-core/src/types.rs | Adds core statistics response models for account/storage/DNS/pullzone/video-library stats. |
| crates/bunny-api-core/src/lib.rs | Re-exports the new core statistics types. |
| crates/bunny-api-core/src/client.rs | Adds core client methods for the new statistics endpoints. |
| CLAUDE.md | Updates contributor guidance (knowledgebase structure, quality gates, coding patterns). |
| eprintln!("Storage zone {id} statistics (use --format json for chart data)"); | ||
| if let Some(chart) = &stats.storage_used_chart | ||
| && let Some(latest) = chart.values().max() | ||
| { | ||
| eprintln!(" Latest storage used: {latest} bytes"); | ||
| } |
There was a problem hiding this comment.
In the non-JSON branch, this prints "Latest storage used" but uses chart.values().max(), which returns the peak value (and HashMap iteration order is not chronological). Either compute the latest datapoint by timestamp key (e.g., max key after parsing) or rename the message to "Peak storage used" to match the current behavior.
| for entry in data { | ||
| let id = entry.ratelimit_id.unwrap_or(0); | ||
| if let Some(overview) = &entry.overview { |
There was a problem hiding this comment.
unwrap_or(0) will label a rate limit rule with ID 0 if the API omits ratelimitId, which is misleading. Prefer handling None explicitly (e.g., skip the label, or print "Rate limit rule "), or make ratelimit_id non-optional if it's guaranteed to be present.
- Rename "Latest storage used" to "Peak storage used" since HashMap iteration order is not chronological (Copilot finding) - Replace unwrap_or(0) with explicit "unknown" label for missing rate limit rule IDs (Copilot finding) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
hoppy statistics,hoppy video-library drm-statistics|transcribing-statistics, and statistics subcommands underdns zone,pull-zone,storage-zone,stream library,shield metricsTest plan
cargo fmt— cleancargo clippy --workspace --all-targets -- -D warnings— no warningscargo test --workspace— all 411 tests pass (14 new mock e2e CLI tests added)cargo test --workspace --features live-api🤖 Generated with Claude Code