From 34b3845de600050438a02f84e7c67afadf9e010a Mon Sep 17 00:00:00 2001 From: Aleksey Myasnikov Date: Tue, 14 May 2024 18:10:48 +0300 Subject: [PATCH] append function id into retry.Retry calls --- internal/balancer/balancer.go | 3 ++ internal/coordination/client.go | 12 ++++++ internal/pool/pool.go | 19 ++++++---- internal/query/client.go | 10 ++++- internal/ratelimiter/client.go | 31 +++++++++++++++- internal/scheme/client.go | 15 ++++++++ internal/scripting/client.go | 9 +++++ internal/table/client.go | 39 +++++++++++--------- internal/table/retry.go | 7 +++- internal/topic/topicclientinternal/client.go | 21 +++++++++++ internal/xsql/conn.go | 38 +++++++++++++------ 11 files changed, 164 insertions(+), 40 deletions(-) diff --git a/internal/balancer/balancer.go b/internal/balancer/balancer.go index b33f7266a..d7d49990f 100644 --- a/internal/balancer/balancer.go +++ b/internal/balancer/balancer.go @@ -90,6 +90,9 @@ func (b *Balancer) clusterDiscovery(ctx context.Context) (err error) { retry.WithIdempotent(true), retry.WithTrace(b.driverConfig.TraceRetry()), retry.WithBudget(b.driverConfig.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/balancer.(*Balancer).clusterDiscovery").FunctionID(), + ), ) } diff --git a/internal/coordination/client.go b/internal/coordination/client.go index c3685cc64..1be66643e 100644 --- a/internal/coordination/client.go +++ b/internal/coordination/client.go @@ -118,6 +118,9 @@ func (c *Client) CreateNode(ctx context.Context, path string, config coordinatio retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/coordination.(*Client).CreateNode").FunctionID(), + ), ) } @@ -151,6 +154,9 @@ func (c *Client) AlterNode(ctx context.Context, path string, config coordination retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/coordination.(*Client).AlterNode").FunctionID(), + ), ) } @@ -212,6 +218,9 @@ func (c *Client) DropNode(ctx context.Context, path string) (finalErr error) { retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/coordination.(*Client).DropNode").FunctionID(), + ), ) } @@ -272,6 +281,9 @@ func (c *Client) DescribeNode( retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/coordination.(*Client).DescribeNode").FunctionID(), + ), ) if err != nil { return nil, nil, xerrors.WithStackTrace(err) diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 3368aadc8..885e343fb 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -437,13 +437,18 @@ func (p *Pool[PT, T]) With( } return nil - }, append(opts, retry.WithTrace(&trace.Retry{ - OnRetry: func(info trace.RetryLoopStartInfo) func(trace.RetryLoopDoneInfo) { - return func(info trace.RetryLoopDoneInfo) { - attempts = info.Attempts - } - }, - }))...) + }, append(opts, + retry.WithTrace(&trace.Retry{ + OnRetry: func(info trace.RetryLoopStartInfo) func(trace.RetryLoopDoneInfo) { + return func(info trace.RetryLoopDoneInfo) { + attempts = info.Attempts + } + }, + }), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/pool.(*Pool).With").FunctionID(), + ), + )...) if err != nil { return xerrors.WithStackTrace(err) } diff --git a/internal/query/client.go b/internal/query/client.go index 3019e83cd..9ad8aa7d9 100644 --- a/internal/query/client.go +++ b/internal/query/client.go @@ -102,7 +102,9 @@ func (c *Client) Do(ctx context.Context, op query.Operation, opts ...options.DoO onDone := trace.QueryOnDo(c.config.Trace(), &ctx, stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Client).Do"), ) - attempts, err := do(ctx, c.pool, op, c.config.Trace(), opts...) + attempts, err := do(ctx, c.pool, op, c.config.Trace(), append(opts, + options.WithLabel(stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Client).Do").FunctionID()), + )...) onDone(attempts, err) return err @@ -159,7 +161,11 @@ func (c *Client) DoTx(ctx context.Context, op query.TxOperation, opts ...options onDone := trace.QueryOnDoTx(c.config.Trace(), &ctx, stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Client).DoTx"), ) - attempts, err := doTx(ctx, c.pool, op, c.config.Trace(), opts...) + attempts, err := doTx(ctx, c.pool, op, c.config.Trace(), append(opts, + options.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Client).DoTx").FunctionID(), + ), + )...) onDone(attempts, err) return err diff --git a/internal/ratelimiter/client.go b/internal/ratelimiter/client.go index c1db4c0ce..f2ce1458a 100644 --- a/internal/ratelimiter/client.go +++ b/internal/ratelimiter/client.go @@ -14,6 +14,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/ratelimiter/config" ratelimiterErrors "github.com/ydb-platform/ydb-go-sdk/v3/internal/ratelimiter/errors" "github.com/ydb-platform/ydb-go-sdk/v3/internal/ratelimiter/options" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" "github.com/ydb-platform/ydb-go-sdk/v3/ratelimiter" "github.com/ydb-platform/ydb-go-sdk/v3/retry" @@ -64,6 +65,9 @@ func (c *Client) CreateResource( retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/ratelimiter.(*Client).CreateResource").FunctionID(), + ), ) } @@ -114,6 +118,9 @@ func (c *Client) AlterResource( retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/ratelimiter.(*Client).AlterResource").FunctionID(), + ), ) } @@ -164,6 +171,9 @@ func (c *Client) DropResource( retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/ratelimiter.(*Client).DropResource").FunctionID(), + ), ) } @@ -210,6 +220,9 @@ func (c *Client) ListResource( retry.WithStackTrace(), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/ratelimiter.(*Client).ListResource").FunctionID(), + ), ) return list, err @@ -262,17 +275,28 @@ func (c *Client) DescribeResource( } if !c.config.AutoRetry() { err = call(ctx) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } - return + return resource, nil } err = retry.Retry(ctx, call, retry.WithIdempotent(true), retry.WithStackTrace(), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID( + "github.com/ydb-platform/ydb-go-sdk/3/internal/ratelimiter.(*Client).DescribeResource", + ).FunctionID(), + ), ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } - return + return resource, nil } func (c *Client) describeResource( @@ -339,6 +363,9 @@ func (c *Client) AcquireResource( retry.WithStackTrace(), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/ratelimiter.(*Client).AcquireResource").FunctionID(), + ), ) } diff --git a/internal/scheme/client.go b/internal/scheme/client.go index 154c44eed..6c1e91b3e 100644 --- a/internal/scheme/client.go +++ b/internal/scheme/client.go @@ -65,6 +65,9 @@ func (c *Client) MakeDirectory(ctx context.Context, path string) (finalErr error retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scheme.(*Client).MakeDirectory").FunctionID(), + ), ) } @@ -105,6 +108,9 @@ func (c *Client) RemoveDirectory(ctx context.Context, path string) (finalErr err retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scheme.(*Client).RemoveDirectory").FunctionID(), + ), ) } @@ -147,6 +153,9 @@ func (c *Client) ListDirectory(ctx context.Context, path string) (d scheme.Direc retry.WithStackTrace(), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scheme.(*Client).ListDirectory").FunctionID(), + ), ) return d, xerrors.WithStackTrace(err) @@ -211,6 +220,9 @@ func (c *Client) DescribePath(ctx context.Context, path string) (e scheme.Entry, retry.WithStackTrace(), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scheme.(*Client).DescribePath").FunctionID(), + ), ) return e, xerrors.WithStackTrace(err) @@ -273,6 +285,9 @@ func (c *Client) ModifyPermissions( retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scheme.(*Client).ModifyPermissions").FunctionID(), + ), ) } diff --git a/internal/scripting/client.go b/internal/scripting/client.go index 92b88b895..4a6768c92 100644 --- a/internal/scripting/client.go +++ b/internal/scripting/client.go @@ -61,6 +61,9 @@ func (c *Client) Execute( retry.WithStackTrace(), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scripting.(*Client).Execute").FunctionID(), + ), ) return r, xerrors.WithStackTrace(err) @@ -141,6 +144,9 @@ func (c *Client) Explain( retry.WithIdempotent(true), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scripting.(*Client).Explain").FunctionID(), + ), ) return e, xerrors.WithStackTrace(err) @@ -216,6 +222,9 @@ func (c *Client) StreamExecute( retry.WithStackTrace(), retry.WithTrace(c.config.TraceRetry()), retry.WithBudget(c.config.RetryBudget()), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scripting.(*Client).StreamExecute").FunctionID(), + ), ) return r, xerrors.WithStackTrace(err) diff --git a/internal/table/client.go b/internal/table/client.go index 4965b8b6f..5ac9bb931 100644 --- a/internal/table/client.go +++ b/internal/table/client.go @@ -259,21 +259,22 @@ func (c *Client) CreateSession(ctx context.Context, opts ...table.Option) (_ tab return nil }, - append( - []retry.Option{ - retry.WithIdempotent(true), - retry.WithTrace(&trace.Retry{ - OnRetry: func(info trace.RetryLoopStartInfo) func(trace.RetryLoopDoneInfo) { - onDone := trace.TableOnCreateSession(c.config.Trace(), info.Context, - stack.FunctionID( - "github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).CreateSession")) - - return func(info trace.RetryLoopDoneInfo) { - onDone(s, info.Attempts, info.Error) - } - }, - }), - }, c.retryOptions(opts...).RetryOptions..., + append(c.retryOptions(opts...).RetryOptions, + retry.WithIdempotent(true), + retry.WithTrace(&trace.Retry{ + OnRetry: func(info trace.RetryLoopStartInfo) func(trace.RetryLoopDoneInfo) { + onDone := trace.TableOnCreateSession(c.config.Trace(), info.Context, + stack.FunctionID( + "github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).CreateSession")) + + return func(info trace.RetryLoopDoneInfo) { + onDone(s, info.Attempts, info.Error) + } + }, + }), + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).CreateSession").FunctionID(), + ), )..., ) @@ -656,7 +657,9 @@ func (c *Client) Do(ctx context.Context, op table.Operation, opts ...table.Optio return xerrors.WithStackTrace(errClosedClient) } - config := c.retryOptions(opts...) + config := c.retryOptions(append(opts, + table.WithLabel(stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).Do").FunctionID()), + )...) attempts, onDone := 0, trace.TableOnDo(config.Trace, &ctx, stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).Do"), @@ -685,7 +688,9 @@ func (c *Client) DoTx(ctx context.Context, op table.TxOperation, opts ...table.O return xerrors.WithStackTrace(errClosedClient) } - config := c.retryOptions(opts...) + config := c.retryOptions(append(opts, + table.WithLabel(stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).DoTx").FunctionID()), + )...) attempts, onDone := 0, trace.TableOnDoTx(config.Trace, &ctx, stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).DoTx"), diff --git a/internal/table/retry.go b/internal/table/retry.go index e2b522b45..e62549f08 100644 --- a/internal/table/retry.go +++ b/internal/table/retry.go @@ -3,6 +3,7 @@ package table import ( "context" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/config" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" @@ -87,7 +88,11 @@ func retryBackoff( return nil }, - opts..., + append(opts, + retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.retryBackoff").FunctionID(), + ), + )..., ) } diff --git a/internal/topic/topicclientinternal/client.go b/internal/topic/topicclientinternal/client.go index 4609df17a..91548ca45 100644 --- a/internal/topic/topicclientinternal/client.go +++ b/internal/topic/topicclientinternal/client.go @@ -9,6 +9,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/credentials" "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic" "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawydb" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/topic" "github.com/ydb-platform/ydb-go-sdk/v3/internal/topic/topicreaderinternal" "github.com/ydb-platform/ydb-go-sdk/v3/internal/topic/topicwriterinternal" @@ -88,6 +89,11 @@ func (c *Client) Alter(ctx context.Context, path string, opts ...topicoptions.Al retry.WithIdempotent(true), retry.WithTrace(c.cfg.TraceRetry()), retry.WithBudget(c.cfg.RetryBudget()), + retry.WithLabel( + stack.FunctionID( + "github.com/ydb-platform/ydb-go-sdk/3/internal/topic/topicclientinternal.(*Client).Alter", + ).FunctionID(), + ), ) } @@ -121,6 +127,11 @@ func (c *Client) Create( retry.WithIdempotent(true), retry.WithTrace(c.cfg.TraceRetry()), retry.WithBudget(c.cfg.RetryBudget()), + retry.WithLabel( + stack.FunctionID( + "github.com/ydb-platform/ydb-go-sdk/3/internal/topic/topicclientinternal.(*Client).Create", + ).FunctionID(), + ), ) } @@ -159,6 +170,11 @@ func (c *Client) Describe( retry.WithIdempotent(true), retry.WithTrace(c.cfg.TraceRetry()), retry.WithBudget(c.cfg.RetryBudget()), + retry.WithLabel( + stack.FunctionID( + "github.com/ydb-platform/ydb-go-sdk/3/internal/topic/topicclientinternal.(*Client).Describe", + ).FunctionID(), + ), ) } else { err = call(ctx) @@ -196,6 +212,11 @@ func (c *Client) Drop(ctx context.Context, path string, opts ...topicoptions.Dro retry.WithIdempotent(true), retry.WithTrace(c.cfg.TraceRetry()), retry.WithBudget(c.cfg.RetryBudget()), + retry.WithLabel( + stack.FunctionID( + "github.com/ydb-platform/ydb-go-sdk/3/internal/topic/topicclientinternal.(*Client).Drop", + ).FunctionID(), + ), ) } diff --git a/internal/xsql/conn.go b/internal/xsql/conn.go index 42d5517e1..c3fdbc47e 100644 --- a/internal/xsql/conn.go +++ b/internal/xsql/conn.go @@ -557,7 +557,9 @@ func (c *conn) IsColumnExists(ctx context.Context, tableName, columnName string) } return nil - }) + }, retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).IsColumnExists").FunctionID(), + )) if err != nil { return false, xerrors.WithStackTrace(err) } @@ -588,7 +590,9 @@ func (c *conn) GetColumns(ctx context.Context, tableName string) (columns []stri } return nil - }) + }, retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).GetColumns").FunctionID(), + )) if err != nil { return nil, xerrors.WithStackTrace(err) } @@ -631,7 +635,9 @@ func (c *conn) GetColumnType(ctx context.Context, tableName, columnName string) } return nil - }) + }, retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).GetColumnType").FunctionID(), + )) if err != nil { return "", xerrors.WithStackTrace(err) } @@ -660,7 +666,9 @@ func (c *conn) GetPrimaryKeys(ctx context.Context, tableName string) (pkCols []s pkCols = append(pkCols, desc.PrimaryKey...) return nil - }) + }, retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).GetPrimaryKeys").FunctionID(), + )) if err != nil { return nil, xerrors.WithStackTrace(err) } @@ -733,7 +741,9 @@ func (c *conn) getTables(ctx context.Context, absPath string, recursive, exclude d, err = c.connector.parent.Scheme().ListDirectory(ctx, absPath) return err - }) + }, retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).getTables").FunctionID(), + )) if err != nil { return nil, xerrors.WithStackTrace(err) } @@ -770,7 +780,9 @@ func (c *conn) GetTables(ctx context.Context, folder string, recursive, excludeS e, err = c.connector.parent.Scheme().DescribePath(ctx, absPath) return err - }) + }, retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).GetTables").FunctionID(), + )) if err != nil { return nil, xerrors.WithStackTrace(err) } @@ -819,7 +831,9 @@ func (c *conn) GetIndexes(ctx context.Context, tableName string) (indexes []stri } return nil - }) + }, retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).GetIndexes").FunctionID(), + )) if err != nil { return nil, xerrors.WithStackTrace(err) } @@ -827,12 +841,12 @@ func (c *conn) GetIndexes(ctx context.Context, tableName string) (indexes []stri return indexes, nil } -func (c *conn) retryIdempotent(ctx context.Context, f func(ctx context.Context) error) error { - err := retry.Retry(ctx, f, +func (c *conn) retryIdempotent(ctx context.Context, f func(ctx context.Context) error, opts ...retry.Option) error { + err := retry.Retry(ctx, f, append(opts, retry.WithIdempotent(true), retry.WithTrace(c.connector.traceRetry), retry.WithBudget(c.connector.retryBudget), - ) + )...) if err != nil { return xerrors.WithStackTrace(err) } @@ -867,7 +881,9 @@ func (c *conn) GetIndexColumns(ctx context.Context, tableName, indexName string) } return xerrors.WithStackTrace(fmt.Errorf("index '%s' not found in table '%s'", indexName, tableName)) - }) + }, retry.WithLabel( + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).GetIndexColumns").FunctionID(), + )) if err != nil { return nil, xerrors.WithStackTrace(err) }