Skip to content

Commit

Permalink
append function id into retry.Retry calls
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed May 14, 2024
1 parent 9d49511 commit 34b3845
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 40 deletions.
3 changes: 3 additions & 0 deletions internal/balancer/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
)
}

Expand Down
12 changes: 12 additions & 0 deletions internal/coordination/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
)
}

Expand Down Expand Up @@ -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(),
),
)
}

Expand Down Expand Up @@ -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(),
),
)
}

Expand Down Expand Up @@ -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)
Expand Down
19 changes: 12 additions & 7 deletions internal/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 8 additions & 2 deletions internal/query/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 29 additions & 2 deletions internal/ratelimiter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
),
)
}

Expand Down Expand Up @@ -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(),
),
)
}

Expand Down Expand Up @@ -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(),
),
)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
),
)
}

Expand Down
15 changes: 15 additions & 0 deletions internal/scheme/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
)
}

Expand Down Expand Up @@ -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(),
),
)
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(),
),
)
}

Expand Down
9 changes: 9 additions & 0 deletions internal/scripting/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
39 changes: 22 additions & 17 deletions internal/table/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
)...,
)

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
7 changes: 6 additions & 1 deletion internal/table/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
),
)...,
)
}

Expand Down
Loading

0 comments on commit 34b3845

Please sign in to comment.