Skip to content

feat(gh-copilot): ingest AI credit usage and add credit consumption dashboard panels#8965

Open
ewega wants to merge 1 commit into
mainfrom
ewega-copilot-ai-credit-usage
Open

feat(gh-copilot): ingest AI credit usage and add credit consumption dashboard panels#8965
ewega wants to merge 1 commit into
mainfrom
ewega-copilot-ai-credit-usage

Conversation

@ewega

@ewega ewega commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Resolves #8961. Adds first-class GitHub Copilot AI credit billing consumption ingestion to the gh-copilot plugin and surfaces credit-consumption KPIs on the GitHub Copilot Adoption dashboard.

The change is purely additive — there were no existing premium-request-unit (PRU) references anywhere in the plugin, grafana, or config-ui to retire, so nothing was removed.

What's included

Ingestion

  • New tool-layer model _tool_copilot_ai_credit_usage (GhCopilotAiCreditUsage) with migration 20260701_add_copilot_ai_credit_usage and GetTablesInfo() registration.
  • Daily collectors + extractors for the GitHub Billing Usage AI credit endpoints (API version 2026-03-10):
    • Enterprise: GET /enterprises/{enterprise}/settings/billing/ai_credit/usage
    • Organization: GET /organizations/{org}/settings/billing/ai_credit/usage (note organizations/, not orgs/)
  • Reuses the existing stateful daily-iterator pattern (day-by-day year/month/day, 365-day clamp, Retry-After backoff, ignoreNoContent). Each usageItem (product/sku/model/unitType) is exploded into one row; gross/net quantity and amount stored as float64.
  • 4 new subtask metas wired into register.go / subtasks.go (collect + extract × enterprise/org).

Dashboard

  • New collapsible "AI Credit Consumption" row added to both mysql and postgresql github-copilot-adoption.json:
    • Stat panels: total gross credits, net credits, net amount, gross amount
    • Time series: gross vs net credits consumed over time
    • Tables: credits by model, and by product / SKU (with amount)
  • Per-dialect SQL (MySQL backticks / connection_id = ${connection_id}; Postgres double-quoted identifiers, connection_id::text guard, NULLS LAST).

Tests & docs

  • e2e raw + snapshot fixtures and an extended metrics_test.go exercising the org AI-credit extractor.
  • Unit tests for splitDay and the pure mapAiCreditUsageReport mapping.
  • Updated plugin README.md and dashboard GithubCopilotREADME.md (new subtasks, table, required billing permissions: manage_billing:copilot / admin:enterprise / admin:org, credit terminology).

Verification

  • go build ./plugins/gh-copilot/...
  • go vet ./plugins/gh-copilot/...
  • gofmt -l clean ✅
  • go test ./plugins/gh-copilot/tasks/...

Note: backend/plugins/table_info_test.go requires generated mocks (make mock) to run in a fresh checkout — a pre-existing environment dependency unrelated to this change.

…ashboard panels

Add first-class GitHub Copilot AI credit billing ingestion to the gh-copilot
plugin and surface credit-consumption KPIs on the Copilot Adoption dashboard.

- New tool model _tool_copilot_ai_credit_usage (+ migration, GetTablesInfo)
- Enterprise + organization daily collectors and extractors for the Billing
  Usage AI credit endpoints (API version 2026-03-10), reusing the existing
  stateful daily-iterator pattern
- Wire 4 new subtask metas (collect/extract x enterprise/org)
- Add "AI Credit Consumption" row (stats, time series, by-model and
  by-product/SKU tables) to mysql + postgresql adoption dashboards
- e2e fixtures + extractor unit tests
- Docs: plugin README + dashboard README

Resolves #8961

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant