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
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR bundles two related gh-copilot changes (18 files):
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 newbilling tables, and e2e snapshot fixtures.
fix: report-body double-read zeroing Copilot user/enterprise metrics
parseUserMetricsReportResponseandparseRawReportResponseread theHTTP response body once (via
io.ReadAll) and then calledparseReportMetadataResponse(res, ...), which re-read the already-consumedbody. 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
bodyviaparseReportMetadata(body, logger)and drop the redundant re-read.
Testing
go build ./plugins/gh-copilot/...,go vet, andgo test ./plugins/gh-copilot/models/...pass.collection logged "empty, skipping" and produced 0 rows; after the fix, it
downloads report files and populates
_raw_copilot_user_metricsand_tool_copilot_user_daily_metrics.Notes
Co-authored-by.