From 93079b08122086f0d5ec8a965fcadd464fd82259 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey Date: Wed, 6 Dec 2023 19:33:01 -0800 Subject: [PATCH] Always GET items --- .../m365/collection/drive/collection.go | 40 +++++++++---------- src/pkg/services/m365/api/graph/service.go | 27 +++++++------ 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/internal/m365/collection/drive/collection.go b/src/internal/m365/collection/drive/collection.go index c51ac5d15..5e6ce1469 100644 --- a/src/internal/m365/collection/drive/collection.go +++ b/src/internal/m365/collection/drive/collection.go @@ -362,27 +362,27 @@ func downloadContent( itemID := ptr.Val(item.GetId()) ctx = clues.Add(ctx, "item_id", itemID) - content, err := downloadItem(ctx, iaag, item) - if err == nil { - return content, nil - } else if !graph.IsErrUnauthorizedOrBadToken(err) { - return nil, err - } + // content, err := downloadItem(ctx, iaag, item) + // if err == nil { + // return content, nil + // } else if !graph.IsErrUnauthorizedOrBadToken(err) { + // return nil, err + // } - // Assume unauthorized requests are a sign of an expired jwt - // token, and that we've overrun the available window to - // download the file. Get a fresh url from the cache and attempt to - // download again. - content, err = readItemContents(ctx, iaag, uc, itemID) - if err == nil { - logger.Ctx(ctx).Debug("found item in url cache") - return content, nil - } + // // Assume unauthorized requests are a sign of an expired jwt + // // token, and that we've overrun the available window to + // // download the file. Get a fresh url from the cache and attempt to + // // download again. + // content, err = readItemContents(ctx, iaag, uc, itemID) + // if err == nil { + // logger.Ctx(ctx).Debug("found item in url cache") + // return content, nil + // } - // Consider cache errors(including deleted items) as cache misses. - // Fallback to refetching the item using the graph API. - logger.CtxErr(ctx, err).Debug("url cache miss: refetching from API") - counter.Inc(count.URLCacheMiss) + // // Consider cache errors(including deleted items) as cache misses. + // // Fallback to refetching the item using the graph API. + // logger.CtxErr(ctx, err).Debug("url cache miss: refetching from API") + // counter.Inc(count.URLCacheMiss) di, err := iaag.GetItem(ctx, driveID, ptr.Val(item.GetId())) if err != nil { @@ -391,7 +391,7 @@ func downloadContent( cdi := custom.ToCustomDriveItem(di) - content, err = downloadItem(ctx, iaag, cdi) + content, err := downloadItem(ctx, iaag, cdi) if err != nil { return nil, clues.Wrap(err, "content download retry") } diff --git a/src/pkg/services/m365/api/graph/service.go b/src/pkg/services/m365/api/graph/service.go index a51fa6533..a1b1d009c 100644 --- a/src/pkg/services/m365/api/graph/service.go +++ b/src/pkg/services/m365/api/graph/service.go @@ -170,7 +170,7 @@ func KiotaHTTPClient( // --------------------------------------------------------------------------- const ( - defaultDelay = 3 * time.Second + defaultDelay = 1 * time.Second defaultHTTPClientTimeout = 1 * time.Hour defaultMaxRetries = 3 // FIXME: This should ideally be 0, but if we set to 0, graph @@ -291,15 +291,16 @@ func kiotaMiddlewares( chaosOpt := &khttp.ChaosHandlerOptions{ ChaosStrategy: khttp.Random, ChaosPercentage: 50, - StatusCode: 429, + StatusCode: 502, ResponseBody: &http.Response{ - StatusCode: 429, + Status: "Bad Gateway", + StatusCode: 502, // Retry-After header - Header: http.Header{ - "Retry-After": []string{"1"}, - }, + // Header: http.Header{ + // "Retry-After": []string{"1"}, + // }, // Dummy body - Body: io.NopCloser(strings.NewReader("hello")), + Body: io.NopCloser(strings.NewReader("bad gateway, deal with it")), }, } @@ -324,7 +325,7 @@ func kiotaMiddlewares( mw := []khttp.Middleware{ msgraphgocore.NewGraphTelemetryHandler(options), &RetryMiddleware{ - MaxRetries: cc.maxRetries, + MaxRetries: 9, Delay: cc.minDelay, }, // We use default kiota retry handler for 503 and 504 errors @@ -342,14 +343,14 @@ func kiotaMiddlewares( mw = append(mw, concurrencyLimitMiddlewareSingleton) } - throttler := &throttlingMiddleware{ - tf: newTimedFence(), - counter: counter, - } + // throttler := &throttlingMiddleware{ + // tf: newTimedFence(), + // counter: counter, + // } mw = append( mw, - throttler, + //throttler, &RateLimiterMiddleware{}, &MetricsMiddleware{ counter: counter,