-
Notifications
You must be signed in to change notification settings - Fork 11
Surface inaccessible GDrive items and root folders in SourceCrawler status #294
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,15 +138,44 @@ func (r *SourceCrawlerReconciler) Reconcile(ctx context.Context, req ctrl.Reques | |
| return ctrl.Result{}, r.handleError(ctx, sourceCrawlerCR, fmt.Errorf("unsupported source type: %s", sourceCrawlerConfig.Type)) | ||
| } | ||
|
|
||
| storedFiles, err := source.SyncFilesToFilestore(ctx, r.fileStore) | ||
| if err != nil { | ||
| return ctrl.Result{}, r.handleError(ctx, sourceCrawlerCR, fmt.Errorf("failed to store files to filestore: %w", err)) | ||
| syncResult, syncErr := source.SyncFilesToFilestore(ctx, r.fileStore) | ||
|
|
||
| // Build inaccessible root folders status from GDriveSource if applicable | ||
| var failedRootFolders []operatorv1alpha1.InaccessibleRootFolder | ||
| if gds, ok := source.(*unstructured.GDriveSource); ok && len(gds.FailedRootFolders) > 0 { | ||
| failedRootFolders = buildInaccessibleRootFolders(gds.FailedRootFolders, sourceCrawlerConfig.GoogleDriveConfig) | ||
| } | ||
|
|
||
| if syncErr != nil { | ||
| if syncResult != nil { | ||
| inaccessible, _ := buildInaccessibleSummary(syncResult.InaccessibleItems) | ||
| if err := controllerutils.StatusPatch(ctx, r.Client, sourceCrawlerCR, func() { | ||
| sourceCrawlerCR.Status.FilesProcessed += int64(len(syncResult.StoredFiles)) | ||
| sourceCrawlerCR.Status.InaccessibleItems = inaccessible | ||
| sourceCrawlerCR.Status.InaccessibleRootFolders = failedRootFolders | ||
| sourceCrawlerCR.UpdateStatus("", syncErr) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we updating the status twice here ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, we are writing error twice, @gshikhar2021, can you please fix this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gshikhar2021 can we address this comment please, as this will hit the kube api server redundantly
Comment on lines
+149
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Include the inaccessible-item count in failure conditions. The error path discards 🤖 Prompt for AI Agents |
||
| }); err != nil { | ||
| logger.Error(err, "failed to update SourceCrawler CR status with partial results") | ||
| return ctrl.Result{}, err | ||
| } | ||
| } | ||
| return ctrl.Result{}, r.handleError(ctx, sourceCrawlerCR, syncErr) | ||
|
Comment on lines
+149
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win Avoid the second status patch on partial sync errors. When 🤖 Prompt for AI Agents |
||
| } | ||
| logger.Info("successfully stored files to filestore", "count", len(storedFiles)) | ||
| logger.Info("successfully stored files to filestore", "count", len(syncResult.StoredFiles)) | ||
|
|
||
| successMessage := fmt.Sprintf("successfully reconciled source crawler: %s", sourceCrawlerCR.Name) | ||
| if len(failedRootFolders) > 0 { | ||
| successMessage += fmt.Sprintf(", %d inaccessible root folders", len(failedRootFolders)) | ||
| } | ||
| inaccessible, total := buildInaccessibleSummary(syncResult.InaccessibleItems) | ||
| if inaccessible != nil { | ||
| successMessage += fmt.Sprintf(", %d inaccessible items (service account may lack access)", total) | ||
| } | ||
|
|
||
| if err := controllerutils.StatusPatch(ctx, r.Client, sourceCrawlerCR, func() { | ||
| sourceCrawlerCR.Status.FilesProcessed += int64(len(storedFiles)) | ||
| sourceCrawlerCR.Status.FilesProcessed += int64(len(syncResult.StoredFiles)) | ||
| sourceCrawlerCR.Status.InaccessibleItems = inaccessible | ||
| sourceCrawlerCR.Status.InaccessibleRootFolders = failedRootFolders | ||
| sourceCrawlerCR.UpdateStatus(successMessage, nil) | ||
| }); err != nil { | ||
| logger.Error(err, "failed to update SourceCrawler CR status") | ||
|
|
@@ -308,6 +337,50 @@ func (r *SourceCrawlerReconciler) handleError(ctx context.Context, sourceCrawler | |
| return reconcileErr | ||
| } | ||
|
|
||
| const maxInaccessibleItems = 100 | ||
|
|
||
| func buildInaccessibleRootFolders(failed []unstructured.FailedRootFolder, gdriveConfig *operatorv1alpha1.GoogleDriveConfig) []operatorv1alpha1.InaccessibleRootFolder { | ||
| folderIDToURL := make(map[string]string, len(gdriveConfig.Folders)) | ||
| for _, f := range gdriveConfig.Folders { | ||
| id, err := extractGDriveFolderID(f.URL) | ||
| if err == nil { | ||
| folderIDToURL[id] = f.URL | ||
| } | ||
| } | ||
| result := make([]operatorv1alpha1.InaccessibleRootFolder, 0, len(failed)) | ||
| for _, f := range failed { | ||
| result = append(result, operatorv1alpha1.InaccessibleRootFolder{ | ||
| FolderID: f.FolderID, | ||
| URL: folderIDToURL[f.FolderID], | ||
| Error: f.Error, | ||
| }) | ||
| } | ||
| return result | ||
|
Comment on lines
+342
to
+358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift Bound inaccessible root-folder status details.
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| func buildInaccessibleSummary(items []unstructured.InaccessibleItem) (*operatorv1alpha1.InaccessibleSummary, int) { | ||
| total := len(items) | ||
| if total == 0 { | ||
| return nil, 0 | ||
| } | ||
| capped := items | ||
| if len(capped) > maxInaccessibleItems { | ||
| capped = capped[:maxInaccessibleItems] | ||
| } | ||
| apiItems := make([]operatorv1alpha1.InaccessibleItem, 0, len(capped)) | ||
| for _, item := range capped { | ||
| apiItems = append(apiItems, operatorv1alpha1.InaccessibleItem{ | ||
| Kind: item.Kind, | ||
| ItemID: item.ItemID, | ||
| Name: item.Name, | ||
| TargetID: item.TargetID, | ||
| RootFolderID: item.RootFolderID, | ||
| Reason: item.Reason, | ||
| }) | ||
| } | ||
| return &operatorv1alpha1.InaccessibleSummary{Items: apiItems, Count: total}, total | ||
| } | ||
|
|
||
| // findDependents maps a changed pipeline stage back to the SourceCrawlers that depend on it. | ||
| // | ||
| // Given a SourceCrawler CR like: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
we might have to see what's the upper cap that CR can hold else we might end up blowing 1.5MB limit