Skip to content

feat(gh-copilot): add AI credit usage billing metrics and fix report-body double-read - #9019

Open
PankajChaudhari-Atos wants to merge 2 commits into
apache:mainfrom
PankajChaudhari-Atos:feat-gh-copilot-ai-credit-and-report-fix
Open

feat(gh-copilot): add AI credit usage billing metrics and fix report-body double-read#9019
PankajChaudhari-Atos wants to merge 2 commits into
apache:mainfrom
PankajChaudhari-Atos:feat-gh-copilot-ai-credit-and-report-fix

Conversation

@PankajChaudhari-Atos

Copy link
Copy Markdown

Summary

This PR bundles two related gh-copilot changes (18 files):

  1. feat: AI credit usage billing metrics (ports feat(gh-copilot): add AI credit usage billing metrics collection #8980)
    Adds collection/extraction of GitHub Copilot AI credit usage billing
    metrics at org, user, and enterprise levels — new models, tasks
    (ai_credit_collector/ai_credit_extractor), a migration for the new
    billing tables, and e2e snapshot fixtures.

  2. fix: report-body double-read zeroing Copilot user/enterprise metrics
    parseUserMetricsReportResponse and parseRawReportResponse read the
    HTTP response body once (via io.ReadAll) and then called
    parseReportMetadataResponse(res, ...), which re-read the already-consumed
    body. The second read returned empty → "Report metadata response was empty,
    skipping" → 0 records, silently zeroing user and enterprise Copilot metrics
    (org metrics were unaffected because that path reads the body once inline).
    Fix: parse the already-read body via parseReportMetadata(body, logger)
    and drop the redundant re-read.

Testing

  • go build ./plugins/gh-copilot/..., go vet, and go test ./plugins/gh-copilot/models/... pass.
  • Behavioral validation on a live deployment: before the fix, user-metrics
    collection logged "empty, skipping" and produced 0 rows; after the fix, it
    downloads report files and populates _raw_copilot_user_metrics and
    _tool_copilot_user_daily_metrics.

Notes

PankajChaudhari-Atos and others added 2 commits July 29, 2026 11:11
Adds collection and extraction of GitHub Copilot AI credit usage
billing metrics at org, user, and enterprise levels, including new
models, tasks (ai_credit_collector/extractor), a migration for the
new billing tables, and e2e snapshot fixtures.

Ports the work from apache#8980.

Co-authored-by: Andrei Savu <54935810+AndreiS-gh@users.noreply.github.com>
Signed-off-by: Pankaj Chaudhari <pankaj.chaudhari@atos.net>
The user and enterprise Copilot metrics collectors read the report
metadata HTTP response body with io.ReadAll, then called
parseReportMetadataResponse(res, ...) which read res.Body a second time.
Since the body was already consumed, the second read returned empty,
parseReportMetadata logged "Report metadata response was empty,
skipping" and returned nil, so the collectors produced zero records.

Parse the metadata from the body already read instead. The organization
collector was unaffected because it reads the body only once inline.

Fixes empty _raw_copilot_user_metrics and _raw_copilot_enterprise_metrics
(and downstream _tool_copilot_user_daily_metrics) while org metrics work.

Signed-off-by: Pankaj Chaudhari <pankaj.chaudhari@atos.net>
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