Skip to content

Commit 3f9dbc3

Browse files
committed
Added export of advanced metric information for QueryService calls
1 parent 4082973 commit 3f9dbc3

File tree

10 files changed

+191
-83
lines changed

10 files changed

+191
-83
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Added export of advanced metric information for QueryService calls
2+
13
## v3.104.0
24
* Added binding `ydb.WithWideTimeTypes()` which interprets `time.Time` and `time.Duration` as `Timestamp64` and `Interval64` YDB types
35

internal/query/client.go

+6
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func (c *Client) Do(ctx context.Context, op query.Operation, opts ...options.DoO
237237
settings = options.ParseDoOpts(c.config.Trace(), opts...)
238238
onDone = trace.QueryOnDo(settings.Trace(), &ctx,
239239
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Client).Do"),
240+
settings.Label(),
240241
)
241242
attempts = 0
242243
)
@@ -366,9 +367,11 @@ func (c *Client) Exec(ctx context.Context, q string, opts ...options.Execute) (f
366367
ctx, cancel := xcontext.WithDone(ctx, c.done)
367368
defer cancel()
368369

370+
settings := options.ExecuteSettings(opts...)
369371
onDone := trace.QueryOnExec(c.config.Trace(), &ctx,
370372
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Client).Exec"),
371373
q,
374+
settings.Label(),
372375
)
373376
defer func() {
374377
onDone(finalErr)
@@ -413,9 +416,11 @@ func (c *Client) Query(ctx context.Context, q string, opts ...options.Execute) (
413416
ctx, cancel := xcontext.WithDone(ctx, c.done)
414417
defer cancel()
415418

419+
settings := options.ExecuteSettings(opts...)
416420
onDone := trace.QueryOnQuery(c.config.Trace(), &ctx,
417421
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Client).Query"),
418422
q,
423+
settings.Label(),
419424
)
420425
defer func() {
421426
onDone(err)
@@ -486,6 +491,7 @@ func (c *Client) DoTx(ctx context.Context, op query.TxOperation, opts ...options
486491
settings = options.ParseDoTxOpts(c.config.Trace(), opts...)
487492
onDone = trace.QueryOnDoTx(settings.Trace(), &ctx,
488493
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Client).DoTx"),
494+
settings.Label(),
489495
)
490496
attempts = 0
491497
)

internal/query/options/execute.go

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type (
4646
txControl TxControl
4747
retryOptions []retry.Option
4848
responsePartLimitBytes int64
49+
label string
4950
}
5051

5152
// Execute is an interface for execute method options
@@ -164,6 +165,7 @@ func defaultExecuteSettings() executeSettings {
164165
statsMode: StatsModeNone,
165166
txControl: tx.DefaultTxControl(),
166167
params: &params.Params{},
168+
label: "undefined",
167169
}
168170
}
169171

@@ -211,6 +213,10 @@ func (s *executeSettings) ResponsePartLimitSizeBytes() int64 {
211213
return s.responsePartLimitBytes
212214
}
213215

216+
func (s *executeSettings) Label() string {
217+
return s.label
218+
}
219+
214220
func WithParameters(params params.Parameters) parametersOption {
215221
return parametersOption{
216222
params: params,

internal/query/options/retry.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type (
2424
doSettings struct {
2525
retryOpts []retry.Option
2626
trace *trace.Query
27+
label string
2728
}
2829

2930
DoTxOption interface {
@@ -44,6 +45,22 @@ type (
4445
}
4546
)
4647

48+
type LabelOption string
49+
50+
func (label LabelOption) applyDoOption(s *doSettings) {
51+
s.label = string(label)
52+
RetryOptionsOption{retry.WithLabel(s.label)}.applyDoOption(s)
53+
}
54+
55+
func (label LabelOption) applyDoTxOption(s *doTxSettings) {
56+
s.label = string(label)
57+
RetryOptionsOption{retry.WithLabel(s.label)}.applyDoTxOption(s)
58+
}
59+
60+
func (label LabelOption) applyExecuteOption(s *executeSettings) {
61+
s.label = string(label)
62+
}
63+
4764
func (opts RetryOptionsOption) applyExecuteOption(s *executeSettings) {
4865
s.retryOptions = append(s.retryOptions, opts...)
4966
}
@@ -56,6 +73,10 @@ func (s *doSettings) RetryOpts() []retry.Option {
5673
return s.retryOpts
5774
}
5875

76+
func (s *doSettings) Label() string {
77+
return s.label
78+
}
79+
5980
func (s *doTxSettings) TxSettings() tx.Settings {
6081
return s.txSettings
6182
}
@@ -88,8 +109,8 @@ func WithIdempotent() RetryOptionsOption {
88109
return []retry.Option{retry.WithIdempotent(true)}
89110
}
90111

91-
func WithLabel(lbl string) RetryOptionsOption {
92-
return []retry.Option{retry.WithLabel(lbl)}
112+
func WithLabel(lbl string) LabelOption {
113+
return LabelOption(lbl)
93114
}
94115

95116
func WithTrace(t *trace.Query) TraceOption {
@@ -103,6 +124,7 @@ func WithRetryBudget(b budget.Budget) RetryOptionsOption {
103124
func ParseDoOpts(t *trace.Query, opts ...DoOption) (s *doSettings) {
104125
s = &doSettings{
105126
trace: t,
127+
label: "undefined",
106128
}
107129

108130
for _, opt := range opts {

internal/query/session.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,14 @@ func (s *Session) execute(
152152
return r, nil
153153
}
154154

155-
func (s *Session) Exec(
156-
ctx context.Context, q string, opts ...options.Execute,
157-
) (finalErr error) {
155+
func (s *Session) Exec(ctx context.Context, q string, opts ...options.Execute) (finalErr error) {
156+
settings := options.ExecuteSettings(opts...)
158157
onDone := trace.QueryOnSessionExec(s.trace, &ctx,
159-
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Session).Exec"), s, q)
158+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Session).Exec"),
159+
s,
160+
q,
161+
settings.Label(),
162+
)
160163
defer func() {
161164
onDone(finalErr)
162165
}()
@@ -177,11 +180,14 @@ func (s *Session) Exec(
177180
return nil
178181
}
179182

180-
func (s *Session) Query(
181-
ctx context.Context, q string, opts ...options.Execute,
182-
) (_ query.Result, finalErr error) {
183+
func (s *Session) Query(ctx context.Context, q string, opts ...options.Execute) (_ query.Result, finalErr error) {
184+
settings := options.ExecuteSettings(opts...)
183185
onDone := trace.QueryOnSessionQuery(s.trace, &ctx,
184-
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Session).Query"), s, q)
186+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Session).Query"),
187+
s,
188+
q,
189+
settings.Label(),
190+
)
185191
defer func() {
186192
onDone(finalErr)
187193
}()

internal/query/transaction.go

+22-14
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,15 @@ func (tx *Transaction) txControl() *queryTx.Control {
191191
)
192192
}
193193

194-
func (tx *Transaction) Exec(ctx context.Context, q string, opts ...options.Execute) (
195-
finalErr error,
196-
) {
194+
func (tx *Transaction) Exec(ctx context.Context, q string, opts ...options.Execute) (finalErr error) {
195+
settings := options.ExecuteSettings(opts...)
197196
onDone := trace.QueryOnTxExec(tx.s.trace, &ctx,
198-
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Transaction).Exec"), tx.s, tx, q)
197+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Transaction).Exec"),
198+
tx.s,
199+
tx,
200+
q,
201+
settings.Label(),
202+
)
199203
defer func() {
200204
onDone(finalErr)
201205
}()
@@ -204,7 +208,7 @@ func (tx *Transaction) Exec(ctx context.Context, q string, opts ...options.Execu
204208
return xerrors.WithStackTrace(errExecuteOnCompletedTx)
205209
}
206210

207-
settings, err := tx.executeSettings(opts...)
211+
txSettings, err := tx.executeSettings(opts...)
208212
if err != nil {
209213
return xerrors.WithStackTrace(err)
210214
}
@@ -215,7 +219,7 @@ func (tx *Transaction) Exec(ctx context.Context, q string, opts ...options.Execu
215219
tx.SetTxID(txMeta.GetId())
216220
}),
217221
}
218-
if settings.TxControl().Commit() {
222+
if txSettings.TxControl().Commit() {
219223
err = tx.waitOnBeforeCommit(ctx)
220224
if err != nil {
221225
return err
@@ -230,7 +234,7 @@ func (tx *Transaction) Exec(ctx context.Context, q string, opts ...options.Execu
230234
)
231235
}
232236

233-
r, err := tx.s.execute(ctx, q, settings, resultOpts...)
237+
r, err := tx.s.execute(ctx, q, txSettings, resultOpts...)
234238
if err != nil {
235239
return xerrors.WithStackTrace(err)
236240
}
@@ -263,11 +267,15 @@ func (tx *Transaction) executeSettings(opts ...options.Execute) (_ executeSettin
263267
}, opts...)...), nil
264268
}
265269

266-
func (tx *Transaction) Query(ctx context.Context, q string, opts ...options.Execute) (
267-
_ query.Result, finalErr error,
268-
) {
270+
func (tx *Transaction) Query(ctx context.Context, q string, opts ...options.Execute) (_ query.Result, finalErr error) {
271+
settings := options.ExecuteSettings(opts...)
269272
onDone := trace.QueryOnTxQuery(tx.s.trace, &ctx,
270-
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Transaction).Query"), tx.s, tx, q)
273+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Transaction).Query"),
274+
tx.s,
275+
tx,
276+
q,
277+
settings.Label(),
278+
)
271279
defer func() {
272280
onDone(finalErr)
273281
}()
@@ -276,7 +284,7 @@ func (tx *Transaction) Query(ctx context.Context, q string, opts ...options.Exec
276284
return nil, xerrors.WithStackTrace(errExecuteOnCompletedTx)
277285
}
278286

279-
settings, err := tx.executeSettings(opts...)
287+
txSettings, err := tx.executeSettings(opts...)
280288
if err != nil {
281289
return nil, xerrors.WithStackTrace(err)
282290
}
@@ -287,7 +295,7 @@ func (tx *Transaction) Query(ctx context.Context, q string, opts ...options.Exec
287295
tx.SetTxID(txMeta.GetId())
288296
}),
289297
}
290-
if settings.TxControl().Commit() {
298+
if txSettings.TxControl().Commit() {
291299
err = tx.waitOnBeforeCommit(ctx)
292300
if err != nil {
293301
return nil, err
@@ -301,7 +309,7 @@ func (tx *Transaction) Query(ctx context.Context, q string, opts ...options.Exec
301309
}),
302310
)
303311
}
304-
r, err := tx.s.execute(ctx, q, settings, resultOpts...)
312+
r, err := tx.s.execute(ctx, q, txSettings, resultOpts...)
305313
if err != nil {
306314
return nil, xerrors.WithStackTrace(err)
307315
}

0 commit comments

Comments
 (0)