From 0fef7632137e6f687e792722b40dd665cc01a884 Mon Sep 17 00:00:00 2001 From: Roman Loginov Date: Mon, 25 Nov 2024 16:15:48 +0300 Subject: [PATCH] [#498] frostfs: Add spans to detail the trace Signed-off-by: Roman Loginov --- internal/frostfs/frostfs.go | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/internal/frostfs/frostfs.go b/internal/frostfs/frostfs.go index 24de01a..00a76fe 100644 --- a/internal/frostfs/frostfs.go +++ b/internal/frostfs/frostfs.go @@ -9,6 +9,7 @@ import ( "time" objectv2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" + "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/frostfs" frosterr "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/errors" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/util" @@ -55,6 +56,9 @@ func NewFrostFS(p *pool.Pool, key *keys.PrivateKey) *FrostFS { // TimeToEpoch implements layer.FrostFS interface method. func (x *FrostFS) TimeToEpoch(ctx context.Context, now, futureTime time.Time) (uint64, uint64, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.TimeToEpoch") + defer span.End() + if futureTime.Before(now) { return 0, 0, fmt.Errorf("time '%s' must be in the future (after %s)", futureTime.Format(time.RFC3339), now.Format(time.RFC3339)) @@ -75,6 +79,9 @@ func (x *FrostFS) TimeToEpoch(ctx context.Context, now, futureTime time.Time) (u // Container implements layer.FrostFS interface method. func (x *FrostFS) Container(ctx context.Context, layerPrm frostfs.PrmContainer) (*container.Container, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.Container") + defer span.End() + prm := pool.PrmContainerGet{ ContainerID: layerPrm.ContainerID, Session: layerPrm.SessionToken, @@ -90,6 +97,9 @@ func (x *FrostFS) Container(ctx context.Context, layerPrm frostfs.PrmContainer) // CreateContainer implements layer.FrostFS interface method. func (x *FrostFS) CreateContainer(ctx context.Context, prm frostfs.PrmContainerCreate) (*frostfs.ContainerCreateResult, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.CreateContainer") + defer span.End() + var cnr container.Container cnr.Init() cnr.SetPlacementPolicy(prm.Policy) @@ -137,6 +147,9 @@ func (x *FrostFS) CreateContainer(ctx context.Context, prm frostfs.PrmContainerC // AddContainerPolicyChain implements frostfs.FrostFS interface method. func (x *FrostFS) AddContainerPolicyChain(ctx context.Context, prm frostfs.PrmAddContainerPolicyChain) error { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.AddContainerPolicyChain") + defer span.End() + data, err := prm.Chain.MarshalBinary() if err != nil { return err @@ -156,6 +169,9 @@ func (x *FrostFS) AddContainerPolicyChain(ctx context.Context, prm frostfs.PrmAd // UserContainers implements layer.FrostFS interface method. func (x *FrostFS) UserContainers(ctx context.Context, layerPrm frostfs.PrmUserContainers) ([]cid.ID, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.UserContainers") + defer span.End() + prm := pool.PrmContainerList{ OwnerID: layerPrm.UserID, Session: layerPrm.SessionToken, @@ -167,6 +183,9 @@ func (x *FrostFS) UserContainers(ctx context.Context, layerPrm frostfs.PrmUserCo // DeleteContainer implements layer.FrostFS interface method. func (x *FrostFS) DeleteContainer(ctx context.Context, id cid.ID, token *session.Container) error { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.DeleteContainer") + defer span.End() + prm := pool.PrmContainerDelete{ContainerID: id, Session: token, WaitParams: &x.await} err := x.pool.DeleteContainer(ctx, prm) @@ -175,6 +194,9 @@ func (x *FrostFS) DeleteContainer(ctx context.Context, id cid.ID, token *session // CreateObject implements layer.FrostFS interface method. func (x *FrostFS) CreateObject(ctx context.Context, prm frostfs.PrmObjectCreate) (*frostfs.CreateObjectResult, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.CreateObject") + defer span.End() + attrNum := len(prm.Attributes) + 1 // + creation time if prm.Filepath != "" { @@ -268,6 +290,9 @@ func (x payloadReader) Read(p []byte) (int, error) { // HeadObject implements layer.FrostFS interface method. func (x *FrostFS) HeadObject(ctx context.Context, prm frostfs.PrmObjectHead) (*object.Object, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.HeadObject") + defer span.End() + var addr oid.Address addr.SetContainer(prm.Container) addr.SetObject(prm.Object) @@ -291,6 +316,9 @@ func (x *FrostFS) HeadObject(ctx context.Context, prm frostfs.PrmObjectHead) (*o // GetObject implements layer.FrostFS interface method. func (x *FrostFS) GetObject(ctx context.Context, prm frostfs.PrmObjectGet) (*frostfs.Object, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.GetObject") + defer span.End() + var addr oid.Address addr.SetContainer(prm.Container) addr.SetObject(prm.Object) @@ -317,6 +345,9 @@ func (x *FrostFS) GetObject(ctx context.Context, prm frostfs.PrmObjectGet) (*fro // RangeObject implements layer.FrostFS interface method. func (x *FrostFS) RangeObject(ctx context.Context, prm frostfs.PrmObjectRange) (io.ReadCloser, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.RangeObject") + defer span.End() + var addr oid.Address addr.SetContainer(prm.Container) addr.SetObject(prm.Object) @@ -342,6 +373,9 @@ func (x *FrostFS) RangeObject(ctx context.Context, prm frostfs.PrmObjectRange) ( // DeleteObject implements layer.FrostFS interface method. func (x *FrostFS) DeleteObject(ctx context.Context, prm frostfs.PrmObjectDelete) error { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.DeleteObject") + defer span.End() + var addr oid.Address addr.SetContainer(prm.Container) addr.SetObject(prm.Object) @@ -361,6 +395,9 @@ func (x *FrostFS) DeleteObject(ctx context.Context, prm frostfs.PrmObjectDelete) // SearchObjects implements layer.FrostFS interface method. func (x *FrostFS) SearchObjects(ctx context.Context, prm frostfs.PrmObjectSearch) ([]oid.ID, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.SearchObjects") + defer span.End() + filters := object.NewSearchFilters() filters.AddRootFilter() @@ -398,6 +435,9 @@ func (x *FrostFS) SearchObjects(ctx context.Context, prm frostfs.PrmObjectSearch // NetworkInfo implements layer.FrostFS interface method. func (x *FrostFS) NetworkInfo(ctx context.Context) (netmap.NetworkInfo, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.NetworkInfo") + defer span.End() + ni, err := x.pool.NetworkInfo(ctx) if err != nil { return ni, handleObjectError("get network info via connection pool", err) @@ -407,6 +447,9 @@ func (x *FrostFS) NetworkInfo(ctx context.Context) (netmap.NetworkInfo, error) { } func (x *FrostFS) PatchObject(ctx context.Context, prm frostfs.PrmObjectPatch) (oid.ID, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.PatchObject") + defer span.End() + var addr oid.Address addr.SetContainer(prm.Container) addr.SetObject(prm.Object)