Skip to content

fix(gh-copilot): skip empty report responses for dates without Copilot data#8804

Merged
ewega merged 1 commit intoapache:mainfrom
breymander:main
Mar 30, 2026
Merged

fix(gh-copilot): skip empty report responses for dates without Copilot data#8804
ewega merged 1 commit intoapache:mainfrom
breymander:main

Conversation

@breymander
Copy link
Copy Markdown
Contributor

@breymander breymander commented Mar 23, 2026

Summary

GitHub's Copilot Usage Metrics Reports API returns HTTP 200 with body "" for dates before usage data was available, instead of returning a 404. The existing ignore404 callback does not catch this, so the ResponseParser attempts json.Unmarshal on "" which fails and crashes the collector pipeline.

Changes:

  • Add an isEmptyReport(body []byte) bool helper in report_download_helper.go that detects empty, "", or null bodies
  • Guard the ResponseParser in all three collectors (enterprise_metrics_collector.go, org_metrics_collector.go, user_metrics_collector.go) to return nil, nil when an empty report is detected, so the collector silently skips those days
  • Add unit tests for isEmptyReport covering empty body, "", null, whitespace, and valid metadata cases

Fixes #8789

Test Plan

  • Unit tests added for isEmptyReport covering edge cases (empty body, "", null, whitespace, valid JSON)
  • Manual verification: configure a Copilot connection with a since date predating available usage data and confirm the collector no longer crashes

Made with Cursor

…t data

GitHub's Copilot Usage Metrics Reports API returns HTTP 200 with body
"" for dates before usage data was available, instead of returning a
404.  The existing ignore404 callback does not catch this, so the
ResponseParser attempts json.Unmarshal on "" which fails and crashes
the collector pipeline.

Add an isEmptyReport guard that detects empty/null bodies and returns
nil so the collector silently skips those days.

Fixes apache#8789
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. component/plugins This issue or PR relates to plugins pr-type/bug-fix This PR fixes a bug labels Mar 23, 2026
@ewega ewega self-assigned this Mar 24, 2026
@ewega ewega requested a review from Copilot March 24, 2026 19:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents the gh-copilot metrics collectors from failing when GitHub’s Copilot Usage Metrics Reports API returns HTTP 200 with an empty/""/null body for days with no available Copilot usage data (instead of returning 404), by detecting and skipping those responses before JSON unmarshalling.

Changes:

  • Added an isEmptyReport([]byte) bool helper to detect empty report metadata responses ("", null, empty/whitespace).
  • Updated enterprise/org/user metrics collectors to short-circuit and skip processing when an empty report is detected.
  • Added unit tests covering isEmptyReport edge cases.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
backend/plugins/gh-copilot/tasks/report_download_helper.go Adds isEmptyReport helper to detect empty/""/null metadata bodies.
backend/plugins/gh-copilot/tasks/enterprise_metrics_collector.go Skips parsing/processing when metadata body is detected as empty.
backend/plugins/gh-copilot/tasks/org_metrics_collector.go Skips parsing/processing when metadata body is detected as empty.
backend/plugins/gh-copilot/tasks/user_metrics_collector.go Skips parsing/processing when metadata body is detected as empty.
backend/plugins/gh-copilot/tasks/metrics_collector_test.go Adds unit tests for isEmptyReport behaviors and edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@breymander
Copy link
Copy Markdown
Contributor Author

@ewega any concerns with accepting this PR?

@klesh klesh requested a review from ewega March 30, 2026 14:39
@klesh
Copy link
Copy Markdown
Contributor

klesh commented Mar 30, 2026

Hi, @ewega . Can you have a look at the PR when you find time? Thanks.

Copy link
Copy Markdown
Contributor

@ewega ewega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Apologies on getting back to you late

@ewega ewega merged commit 2e9cca0 into apache:main Mar 30, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/plugins This issue or PR relates to plugins pr-type/bug-fix This PR fixes a bug size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][gh-copilot] collectOrgMetrics fails with "error parsing response" for organization-1-day endpoint

4 participants