-
Notifications
You must be signed in to change notification settings - Fork 724
fix: Copilot plugin - add backfill time window to ensure data consistency #8811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
la-tamas
wants to merge
1
commit into
apache:main
Choose a base branch
from
archfz:chore/copilot-user-metrics-backfill
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -33,6 +33,14 @@ import ( | |||||
| // reportMaxDays is the maximum historical window the new report API supports (1 year). | ||||||
| const reportMaxDays = 365 | ||||||
|
|
||||||
| // reportLookbackDays: extra days rewound from 'until' on incremental runs. | ||||||
| // GitHub reports are generated hours after midnight, so a midnight run gets 404 for the previous | ||||||
| // day. Without this buffer, 'LatestSuccessStart' advances past the missed day permanently. | ||||||
| const reportLookbackDays = 2 | ||||||
|
|
||||||
| // dailyMetricsTrailingBackfillDays extends retries for delayed daily report generation. | ||||||
| const dailyMetricsTrailingBackfillDays = 4 | ||||||
|
|
||||||
| // copilotRawParams identifies a set of raw data records for a given connection/scope. | ||||||
| type copilotRawParams struct { | ||||||
| ConnectionId uint64 | ||||||
|
|
@@ -60,6 +68,14 @@ func ignore404(res *http.Response) errors.Error { | |||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| func clampDailyMetricsStartForBackfill(start, until time.Time) time.Time { | ||||||
| trailingStart := until.AddDate(0, 0, -(dailyMetricsTrailingBackfillDays - 1)) | ||||||
| if start.After(trailingStart) { | ||||||
| return trailingStart | ||||||
| } | ||||||
| return start | ||||||
| } | ||||||
|
|
||||||
| // reportMetadataResponse represents the JSON returned by the report metadata endpoints. | ||||||
| type reportMetadataResponse struct { | ||||||
| DownloadLinks []string `json:"download_links"` | ||||||
|
|
@@ -69,7 +85,120 @@ type reportMetadataResponse struct { | |||||
| ReportEndDay string `json:"report_end_day"` | ||||||
| } | ||||||
|
|
||||||
| func readReportMetadataBody(res *http.Response) ([]byte, errors.Error) { | ||||||
| body, readErr := io.ReadAll(res.Body) | ||||||
| res.Body.Close() | ||||||
| if readErr != nil { | ||||||
| return nil, errors.Default.Wrap(readErr, "failed to read report metadata") | ||||||
| } | ||||||
| return body, nil | ||||||
| } | ||||||
|
|
||||||
| func logReportMetadataParseError(body []byte, err error, logger log.Logger) { | ||||||
| if logger == nil { | ||||||
| return | ||||||
| } | ||||||
| snippet := string(body) | ||||||
| if len(snippet) > 200 { | ||||||
| snippet = snippet[:200] | ||||||
| } | ||||||
| logger.Error(err, "failed to parse report metadata, body=%s", snippet) | ||||||
| } | ||||||
|
|
||||||
| func reportMetadataRange(meta reportMetadataResponse) string { | ||||||
| if meta.ReportDay != "" { | ||||||
| return meta.ReportDay | ||||||
| } | ||||||
| if meta.ReportStartDay != "" && meta.ReportEndDay != "" { | ||||||
| return fmt.Sprintf("%s..%s", meta.ReportStartDay, meta.ReportEndDay) | ||||||
| } | ||||||
| return "" | ||||||
| } | ||||||
|
|
||||||
| func logMissingDownloadLinks(meta reportMetadataResponse, logger log.Logger) { | ||||||
| if logger == nil || len(meta.DownloadLinks) != 0 { | ||||||
| return | ||||||
| } | ||||||
| reportRange := reportMetadataRange(meta) | ||||||
| if reportRange != "" { | ||||||
| logger.Info("No download links for report day=%s, skipping", reportRange) | ||||||
|
||||||
| logger.Info("No download links for report day=%s, skipping", reportRange) | |
| logger.Info("No download links for report=%s, skipping", reportRange) |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logReportMetadataParseErrorlogs a snippet of the raw metadata response body. This metadata includesdownload_links(signed URLs), so on parse errors this can leak sensitive, time-limited URLs into logs. Please redact/removedownload_linksbefore logging, or log only non-sensitive fields (e.g., report_day/range and response size/status) instead of the raw body snippet.