From 06ca30bf17fbe53e41e3e42f819e8ce108884c8a Mon Sep 17 00:00:00 2001 From: Roman Loginov Date: Thu, 28 Nov 2024 05:48:14 +0300 Subject: [PATCH] [#145] handler: Add spans to detail the trace Signed-off-by: Roman Loginov --- internal/handler/download.go | 21 ++++++++++++++++++++- internal/handler/head.go | 13 +++++++++++++ internal/handler/upload.go | 5 ++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/internal/handler/download.go b/internal/handler/download.go index cd4e55a..f324460 100644 --- a/internal/handler/download.go +++ b/internal/handler/download.go @@ -13,6 +13,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs" "git.frostfs.info/TrueCloudLab/frostfs-http-gw/response" "git.frostfs.info/TrueCloudLab/frostfs-http-gw/utils" + "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" @@ -28,10 +29,22 @@ func (h *Handler) DownloadByAddressOrBucketName(c *fasthttp.RequestCtx) { switch { case isObjectID(oidURLParam): + ctx, span := tracing.StartSpanFromContext(utils.GetContextFromRequest(c), "handler.DownloadByNativeAddress") + defer span.End() + + utils.SetContextToRequest(ctx, c) h.byNativeAddress(c, h.receiveFile) case !isContainerRoot(oidURLParam) && (downloadQueryParam || !isDir(oidURLParam)): + ctx, span := tracing.StartSpanFromContext(utils.GetContextFromRequest(c), "handler.DownloadByS3Path") + defer span.End() + + utils.SetContextToRequest(ctx, c) h.byS3Path(c, h.receiveFile) default: + ctx, span := tracing.StartSpanFromContext(utils.GetContextFromRequest(c), "handler.BrowseIndex") + defer span.End() + + utils.SetContextToRequest(ctx, c) h.browseIndex(c) } } @@ -45,6 +58,10 @@ func (h *Handler) newRequest(ctx *fasthttp.RequestCtx, log *zap.Logger) *request // DownloadByAttribute handles attribute-based download requests. func (h *Handler) DownloadByAttribute(c *fasthttp.RequestCtx) { + ctx, span := tracing.StartSpanFromContext(utils.GetContextFromRequest(c), "handler.DownloadByAttribute") + defer span.End() + + utils.SetContextToRequest(ctx, c) h.byAttribute(c, h.receiveFile) } @@ -84,10 +101,12 @@ func (h *Handler) addObjectToZip(zw *zip.Writer, obj *object.Object) (io.Writer, // DownloadZipped handles zip by prefix requests. func (h *Handler) DownloadZipped(c *fasthttp.RequestCtx) { + ctx, span := tracing.StartSpanFromContext(utils.GetContextFromRequest(c), "handler.DownloadZipped") + defer span.End() + scid, _ := c.UserValue("cid").(string) prefix, _ := c.UserValue("prefix").(string) - ctx := utils.GetContextFromRequest(c) log := utils.GetReqLogOrDefault(ctx, h.log) prefix, err := url.QueryUnescape(prefix) diff --git a/internal/handler/head.go b/internal/handler/head.go index ccd6a91..09fe1e0 100644 --- a/internal/handler/head.go +++ b/internal/handler/head.go @@ -9,6 +9,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs" "git.frostfs.info/TrueCloudLab/frostfs-http-gw/utils" + "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "github.com/valyala/fasthttp" @@ -107,13 +108,25 @@ func (h *Handler) HeadByAddressOrBucketName(c *fasthttp.RequestCtx) { err := id.DecodeString(test) if err != nil { + ctx, span := tracing.StartSpanFromContext(utils.GetContextFromRequest(c), "handler.HeadByS3Path") + defer span.End() + + utils.SetContextToRequest(ctx, c) h.byS3Path(c, h.headObject) } else { + ctx, span := tracing.StartSpanFromContext(utils.GetContextFromRequest(c), "handler.HeadByNativeAddress") + defer span.End() + + utils.SetContextToRequest(ctx, c) h.byNativeAddress(c, h.headObject) } } // HeadByAttribute handles attribute-based head requests. func (h *Handler) HeadByAttribute(c *fasthttp.RequestCtx) { + ctx, span := tracing.StartSpanFromContext(utils.GetContextFromRequest(c), "handler.HeadByAttribute") + defer span.End() + + utils.SetContextToRequest(ctx, c) h.byAttribute(c, h.headObject) } diff --git a/internal/handler/upload.go b/internal/handler/upload.go index 867025d..158018e 100644 --- a/internal/handler/upload.go +++ b/internal/handler/upload.go @@ -12,6 +12,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-http-gw/response" "git.frostfs.info/TrueCloudLab/frostfs-http-gw/tokens" "git.frostfs.info/TrueCloudLab/frostfs-http-gw/utils" + "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -44,6 +45,9 @@ func (pr *putResponse) encode(w io.Writer) error { // Upload handles multipart upload request. func (h *Handler) Upload(c *fasthttp.RequestCtx) { + ctx, span := tracing.StartSpanFromContext(utils.GetContextFromRequest(c), "handler.Upload") + defer span.End() + var ( file MultipartFile idObj oid.ID @@ -54,7 +58,6 @@ func (h *Handler) Upload(c *fasthttp.RequestCtx) { bodyStream := c.RequestBodyStream() drainBuf := make([]byte, drainBufSize) - ctx := utils.GetContextFromRequest(c) reqLog := utils.GetReqLogOrDefault(ctx, h.log) log := reqLog.With(zap.String("cid", scid))