Compare commits

...

3 Commits

Author SHA1 Message Date
Vaibhav Kamra
e9ef8eb69d Fix lint 2023-03-07 19:21:41 -08:00
Vaibhav Kamra
c2330e7262 Remove extra Graph API call 2023-03-07 19:20:57 -08:00
Vaibhav Kamra
fe0642c88d Log throttling headers 2023-03-07 19:20:57 -08:00
3 changed files with 43 additions and 31 deletions

View File

@ -30,6 +30,9 @@ const (
defaultMaxRetries = 3 defaultMaxRetries = 3
defaultDelay = 3 * time.Second defaultDelay = 3 * time.Second
absoluteMaxDelaySeconds = 180 absoluteMaxDelaySeconds = 180
rateLimitHeader = "RateLimit-Limit"
rateRemainingHeader = "RateLimit-Remaining"
rateResetHeader = "RateLimit-Reset"
) )
// AllMetadataFileNames produces the standard set of filenames used to store graph // AllMetadataFileNames produces the standard set of filenames used to store graph
@ -313,7 +316,12 @@ func (handler *LoggingMiddleware) Intercept(
} else { } else {
// special case for supportability: log all throttling cases. // special case for supportability: log all throttling cases.
if resp.StatusCode == http.StatusTooManyRequests { if resp.StatusCode == http.StatusTooManyRequests {
logger.Ctx(ctx).Infow("graph api throttling", "method", req.Method, "url", req.URL) logger.Ctx(ctx).Infow("graph api throttling",
"method", req.Method,
"url", req.URL,
"limit", resp.Header.Get(rateLimitHeader),
"remaining", resp.Header.Get(rateRemainingHeader),
"reset", resp.Header.Get(rateResetHeader))
} else if resp.StatusCode == http.StatusBadRequest { } else if resp.StatusCode == http.StatusBadRequest {
respDump, _ := httputil.DumpResponse(resp, true) respDump, _ := httputil.DumpResponse(resp, true)
logger.Ctx(ctx).Infow( logger.Ctx(ctx).Infow(

View File

@ -333,13 +333,17 @@ func (oc *Collection) populateItems(ctx context.Context, errs *fault.Bus) {
"backup_item_size", itemSize, "backup_item_size", itemSize,
) )
pr, err := fetchParentReference(ctx, oc.service, item.GetParentReference()) // TODO: Removing the logic below because it introduces an extra Graph API call for
if err != nil { // every item being backed up. This can lead to throttling errors.
el.AddRecoverable(clues.Wrap(err, "getting parent reference").Label(fault.LabelForceNoBackupCreation)) //
return // pr, err := fetchParentReference(ctx, oc.service, item.GetParentReference())
} // if err != nil {
// el.AddRecoverable(clues.Wrap(err, "getting parent reference").Label(fault.LabelForceNoBackupCreation))
// return
// }
// item.SetParentReference(pr)
item.SetParentReference(pr)
isFile := item.GetFile() != nil isFile := item.GetFile() != nil
if isFile { if isFile {

View File

@ -405,33 +405,33 @@ func constructWebURL(adtl map[string]any) string {
return url return url
} }
func fetchParentReference( // func fetchParentReference(
ctx context.Context, // ctx context.Context,
service graph.Servicer, // service graph.Servicer,
orig models.ItemReferenceable, // orig models.ItemReferenceable,
) (models.ItemReferenceable, error) { // ) (models.ItemReferenceable, error) {
if orig == nil || service == nil || ptr.Val(orig.GetName()) != "" { // if orig == nil || service == nil || ptr.Val(orig.GetName()) != "" {
return orig, nil // return orig, nil
} // }
options := &msdrives.DriveItemRequestBuilderGetRequestConfiguration{ // options := &msdrives.DriveItemRequestBuilderGetRequestConfiguration{
QueryParameters: &msdrives.DriveItemRequestBuilderGetQueryParameters{ // QueryParameters: &msdrives.DriveItemRequestBuilderGetQueryParameters{
Select: []string{"name"}, // Select: []string{"name"},
}, // },
} // }
driveID := ptr.Val(orig.GetDriveId()) // driveID := ptr.Val(orig.GetDriveId())
if driveID == "" { // if driveID == "" {
return orig, nil // return orig, nil
} // }
drive, err := service.Client().DrivesById(driveID).Get(ctx, options) // drive, err := service.Client().DrivesById(driveID).Get(ctx, options)
if err != nil { // if err != nil {
return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...) // return nil, graph.Stack(ctx, err)
} // }
orig.SetName(drive.GetName()) // orig.SetName(drive.GetName())
return orig, nil // return orig, nil
} // }