From eaf252a26cc4f22f79693311643c56a2ccb4838f Mon Sep 17 00:00:00 2001 From: Abhishek Pandey Date: Wed, 6 Dec 2023 21:35:33 -0800 Subject: [PATCH] Dont log req --- src/pkg/services/m365/api/graph/logging.go | 31 +++++++++---------- src/pkg/services/m365/api/graph/middleware.go | 2 +- src/pkg/services/m365/api/graph/service.go | 8 ++--- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/pkg/services/m365/api/graph/logging.go b/src/pkg/services/m365/api/graph/logging.go index a08eeb3a4..bc8448bb1 100644 --- a/src/pkg/services/m365/api/graph/logging.go +++ b/src/pkg/services/m365/api/graph/logging.go @@ -45,8 +45,7 @@ func logResp(ctx context.Context, resp *http.Response) { // Dump both request and response for graph 400 errors. This is a temporary // measure to help us understand why graph is returning transient 400s. if resp.StatusCode == http.StatusBadRequest { - log.With("request", getRequestDump(ctx, resp.Request, true)). - With("response", getRespDump(ctx, resp, logBody)). + log.With("response", getRespDump(ctx, resp, logBody)). Info("graph api bad request") } @@ -69,14 +68,14 @@ func logResp(ctx context.Context, resp *http.Response) { } } -func logReq(ctx context.Context, req *http.Request) { - var ( - log = logger.Ctx(ctx) - ) +// func logReq(ctx context.Context, req *http.Request) { +// var ( +// log = logger.Ctx(ctx) +// ) - log.With("request", getRequestDump(ctx, req, true)). - Info("graph api req") -} +// log.With("request", getRequestDump(ctx, req, true)). +// Info("graph api req") +// } func getRespDump(ctx context.Context, resp *http.Response, getBody bool) string { respDump, err := httputil.DumpResponse(resp, getBody) @@ -87,11 +86,11 @@ func getRespDump(ctx context.Context, resp *http.Response, getBody bool) string return string(respDump) } -func getRequestDump(ctx context.Context, req *http.Request, getBody bool) string { - reqDump, err := httputil.DumpRequest(req, getBody) - if err != nil { - logger.CtxErr(ctx, err).Error("dumping http request") - } +// func getRequestDump(ctx context.Context, req *http.Request, getBody bool) string { +// reqDump, err := httputil.DumpRequest(req, getBody) +// if err != nil { +// logger.CtxErr(ctx, err).Error("dumping http request") +// } - return string(reqDump) -} +// return string(reqDump) +// } diff --git a/src/pkg/services/m365/api/graph/middleware.go b/src/pkg/services/m365/api/graph/middleware.go index 8be93be1f..a976c7812 100644 --- a/src/pkg/services/m365/api/graph/middleware.go +++ b/src/pkg/services/m365/api/graph/middleware.go @@ -118,7 +118,7 @@ func (mw *LoggingMiddleware) Intercept( middlewareIndex int, req *http.Request, ) (*http.Response, error) { - logReq(req.Context(), req) + // logReq(req.Context(), req) // call the next middleware resp, err := pipeline.Next(req, middlewareIndex) diff --git a/src/pkg/services/m365/api/graph/service.go b/src/pkg/services/m365/api/graph/service.go index a1b1d009c..032a2dc92 100644 --- a/src/pkg/services/m365/api/graph/service.go +++ b/src/pkg/services/m365/api/graph/service.go @@ -291,16 +291,16 @@ func kiotaMiddlewares( chaosOpt := &khttp.ChaosHandlerOptions{ ChaosStrategy: khttp.Random, ChaosPercentage: 50, - StatusCode: 502, + StatusCode: 503, ResponseBody: &http.Response{ - Status: "Bad Gateway", - StatusCode: 502, + Status: "Service Unavailable", + StatusCode: 503, // Retry-After header // Header: http.Header{ // "Retry-After": []string{"1"}, // }, // Dummy body - Body: io.NopCloser(strings.NewReader("bad gateway, deal with it")), + Body: io.NopCloser(strings.NewReader("service is down. deal with it")), }, }