From 00ce998bbde8a1edd16b8ce49acf74ba2c29f540 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 | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/internal/frostfs/frostfs.go b/internal/frostfs/frostfs.go index 186d206d..3f4a8ee9 100644 --- a/internal/frostfs/frostfs.go +++ b/internal/frostfs/frostfs.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "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" @@ -57,6 +58,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)) @@ -77,6 +81,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, @@ -92,6 +99,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) @@ -139,6 +149,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 @@ -158,6 +171,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, @@ -169,6 +185,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) @@ -177,6 +196,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 != "" { @@ -271,6 +293,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) @@ -294,6 +319,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) @@ -320,6 +348,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) @@ -345,6 +376,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) @@ -364,6 +398,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() @@ -401,6 +438,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) @@ -419,6 +459,9 @@ func (x *FrostFS) NetmapSnapshot(ctx context.Context) (netmap.NetMap, 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) @@ -467,6 +510,9 @@ func NewResolverFrostFS(p *pool.Pool) *ResolverFrostFS { // SystemDNS implements resolver.FrostFS interface method. func (x *ResolverFrostFS) SystemDNS(ctx context.Context) (string, error) { + ctx, span := tracing.StartSpanFromContext(ctx, "frostfs.SystemDNS") + defer span.End() + networkInfo, err := x.pool.NetworkInfo(ctx) if err != nil { return "", handleObjectError("read network info via client", err)