Skip to content

feat(export): extract Analytics API hit metrics per product - #57

Merged
fmenesesg merged 4 commits into
mainfrom
feature/extract-hit-metrics
Jul 9, 2026
Merged

feat(export): extract Analytics API hit metrics per product#57
fmenesesg merged 4 commits into
mainfrom
feature/extract-hit-metrics

Conversation

@fmenesesg

Copy link
Copy Markdown
Collaborator

Proposed change

Adds optional hit-traffic export from the 3scale Analytics API (GET /stats/services/{id}/usage.json).

  • PR 1 (foundation): internal/stats client/exporter, metrics window validation in internal/config/metrics.go
  • PR 2 (wiring): --include-metrics on full export, standalone threescale-export metrics subcommand, manifest/verify layout for stats/, README and test cases

Output layout (when enabled):

stats/
├── query.json
└── products/{system_name}/hits.json

Requires Enterprise tier and a PAT with Analytics scope. Fail-fast when metrics are requested and the Analytics API returns an error.

Type of change

  • New feature

RHCL checklist

  • Tests added or updated (go test ./...)
  • No secrets in diff
  • PR description and docs in English
  • Tested in local lab if applicable (seed → export → analyze)

Test plan

  • go test ./... passes locally
  • TestExportIncludeMetrics / TestVerifyExportWithMetrics — full export with mock Analytics API
  • TestRunMetricsHappyPath — standalone metrics subcommand writes only stats/
  • TestExportGoldenLayout unchanged — default export without --include-metrics still produces 10 files
  • Manual: run against lab tenant with Analytics scope and confirm stats/products/*/hits.json

Additional information

  • Related: SDD extract-hit-metrics (Engram)
  • Schema version remains 1.0; manifest gains optional metrics fields when --include-metrics is set

Made with Cursor

Francisco Meneses and others added 2 commits July 9, 2026 15:37
Introduces metrics config flags with date validation and a new internal/stats
package with Analytics client and per-product exporter. Wiring and CLI follow in PR 2.

Co-authored-by: Cursor <cursoragent@cursor.com>
Connect Analytics API stats to full export via --include-metrics, add a
standalone metrics subcommand, extend manifest/verify layout, and document
the stats/ output contract.

Co-authored-by: Cursor <cursoragent@cursor.com>
@fmenesesg
fmenesesg requested a review from pcastelo as a code owner July 9, 2026 19:43
Francisco Meneses and others added 2 commits July 9, 2026 16:31
Use errors.Is when asserting ErrInvalidMetricsDateRange so wrapped errors
still match in CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
Cover metrics config helpers, ValidateOutput with include-metrics, stats
parsers, and export ListProducts to restore the 80% coverage gate.

Co-authored-by: Cursor <cursoragent@cursor.com>
@fmenesesg
fmenesesg merged commit fa8d640 into main Jul 9, 2026
1 check passed
@fmenesesg
fmenesesg deleted the feature/extract-hit-metrics branch July 9, 2026 20:34
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.

1 participant