Skip to content

fix: Copilot plugin - add backfill time window to ensure data consistency#8811

Open
la-tamas wants to merge 1 commit intoapache:mainfrom
archfz:chore/copilot-user-metrics-backfill
Open

fix: Copilot plugin - add backfill time window to ensure data consistency#8811
la-tamas wants to merge 1 commit intoapache:mainfrom
archfz:chore/copilot-user-metrics-backfill

Conversation

@la-tamas
Copy link
Copy Markdown

@la-tamas la-tamas commented Mar 26, 2026

⚠️ Pre Checklist

Please complete ALL items in this checklist, and remove before submitting

  • I have read through the Contributing Documentation.
  • I have added relevant tests.
  • I have added relevant documentation.
  • I will add labels to the PR, such as pr-type/bug-fix, pr-type/feature-development, etc.

Summary

Add backfill time window to ensure data consistency for GitHub Copilot metrics collection.
GitHub reports are generated hours after midnight, so a midnight run gets 404 for the previous day.
Without a lookback buffer, LatestSuccessStart advances past the missed day permanently.

This change introduces: reportLookbackDays constant: extra days rewound from 'until' on incremental runs dailyMetricsTrailingBackfillDays constant: extends retries for delayed daily report generation\n- clampDailyMetricsStartForBackfill helper to apply the trailing backfill window.

Does this close any open issues?

Screenshots

Other Information

Any other information that is important to this PR.

chore: Add backfill time window to ensure data consistency
(cherry picked from commit 52a9555b782860f9c8ba9db409bd56e0c8f58272)
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. cherrypick This PR is cherry-picked from another branch component/plugins This issue or PR relates to plugins pr-type/bug-fix This PR fixes a bug labels Mar 26, 2026
@ewega ewega requested review from Copilot and ewega March 30, 2026 15:53
@ewega
Copy link
Copy Markdown
Contributor

ewega commented Mar 30, 2026

Mind fixing conflicts? Hint: if you use copilot you can ask it to fix conflicts for you - https://github.blog/changelog/2026-03-26-ask-copilot-to-resolve-merge-conflicts-on-pull-requests/

@ewega ewega self-assigned this Mar 30, 2026
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

Adds a lookback/backfill window to the GitHub Copilot metrics collectors so incremental runs retry recently-missed days (e.g., reports not yet generated around midnight), improving data consistency.

Changes:

  • Rewinds incremental collection start by a fixed reportLookbackDays and further clamps daily metrics to a trailing backfill window (dailyMetricsTrailingBackfillDays).
  • Refactors report metadata parsing/downloading into shared helpers (parseReportMetadataResponse, parseRawReportResponse, parseUserMetricsReportResponse).
  • Adds unit tests covering the new date-range/backfill behavior and metadata “empty/204” handling.

Reviewed changes

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

Show a summary per file
File Description
backend/plugins/gh-copilot/tasks/report_download_helper.go Introduces lookback/backfill constants and shared metadata/record collection helpers.
backend/plugins/gh-copilot/tasks/user_metrics_collector.go Applies trailing backfill and uses shared user-metrics response parsing.
backend/plugins/gh-copilot/tasks/org_metrics_collector.go Applies trailing backfill and switches to shared raw-report response parsing.
backend/plugins/gh-copilot/tasks/enterprise_metrics_collector.go Applies trailing backfill and switches to shared raw-report response parsing.
backend/plugins/gh-copilot/tasks/metrics_collector_test.go Adds tests for lookback/backfill and metadata parsing edge cases.

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

Comment on lines +101 to +105
snippet := string(body)
if len(snippet) > 200 {
snippet = snippet[:200]
}
logger.Error(err, "failed to parse report metadata, body=%s", snippet)
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

logReportMetadataParseError logs a snippet of the raw metadata response body. This metadata includes download_links (signed URLs), so on parse errors this can leak sensitive, time-limited URLs into logs. Please redact/remove download_links before logging, or log only non-sensitive fields (e.g., report_day/range and response size/status) instead of the raw body snippet.

Suggested change
snippet := string(body)
if len(snippet) > 200 {
snippet = snippet[:200]
}
logger.Error(err, "failed to parse report metadata, body=%s", snippet)
logger.Error(err, "failed to parse report metadata, body_size=%d bytes", len(body))

Copilot uses AI. Check for mistakes.
}
reportRange := reportMetadataRange(meta)
if reportRange != "" {
logger.Info("No download links for report day=%s, skipping", reportRange)
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The log message says report day=%s but reportMetadataRange() can return a range like start..end. Please adjust the wording (e.g., report=%s/range=%s) so logs remain accurate for both 1-day and multi-day metadata.

Suggested change
logger.Info("No download links for report day=%s, skipping", reportRange)
logger.Info("No download links for report=%s, skipping", reportRange)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherrypick This PR is cherry-picked from another branch component/plugins This issue or PR relates to plugins pr-type/bug-fix This PR fixes a bug size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants