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
defaultDelay = 3 * time.Second
absoluteMaxDelaySeconds = 180
rateLimitHeader = "RateLimit-Limit"
rateRemainingHeader = "RateLimit-Remaining"
rateResetHeader = "RateLimit-Reset"
)
// AllMetadataFileNames produces the standard set of filenames used to store graph
@ -313,7 +316,12 @@ func (handler *LoggingMiddleware) Intercept(
} else {
// special case for supportability: log all throttling cases.
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 {
respDump, _ := httputil.DumpResponse(resp, true)
logger.Ctx(ctx).Infow(

View File

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

View File

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