Skip to content

Commit 3be1b9c

Browse files
authored
Merge pull request #1449 from ydb-platform/slo-logs
fixed log output for SLO
2 parents a9b150e + eb4aa2d commit 3be1b9c

File tree

6 files changed

+33
-50
lines changed

6 files changed

+33
-50
lines changed

internal/query/client.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ func (c *Client) Do(ctx context.Context, op query.Operation, opts ...options.DoO
227227
defer cancel()
228228

229229
var (
230-
onDone = trace.QueryOnDo(c.config.Trace(), &ctx,
230+
settings = options.ParseDoOpts(c.config.Trace(), opts...)
231+
onDone = trace.QueryOnDo(settings.Trace(), &ctx,
231232
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Client).Do"),
232233
)
233234
attempts = 0
@@ -238,8 +239,6 @@ func (c *Client) Do(ctx context.Context, op query.Operation, opts ...options.DoO
238239

239240
err := do(ctx, c.pool,
240241
func(ctx context.Context, s *Session) error {
241-
attempts++
242-
243242
return op(ctx, s)
244243
},
245244
append([]retry.Option{
@@ -250,7 +249,7 @@ func (c *Client) Do(ctx context.Context, op query.Operation, opts ...options.DoO
250249
}
251250
},
252251
}),
253-
}, options.ParseDoOpts(c.config.Trace(), opts...).RetryOpts()...)...,
252+
}, settings.RetryOpts()...)...,
254253
)
255254

256255
return err
@@ -481,23 +480,18 @@ func (c *Client) DoTx(ctx context.Context, op query.TxOperation, opts ...options
481480
defer cancel()
482481

483482
var (
484-
onDone = trace.QueryOnDoTx(c.config.Trace(), &ctx,
483+
settings = options.ParseDoTxOpts(c.config.Trace(), opts...)
484+
onDone = trace.QueryOnDoTx(settings.Trace(), &ctx,
485485
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Client).DoTx"),
486486
)
487-
doTxOpts = options.ParseDoTxOpts(opts...)
488487
attempts = 0
489488
)
490489
defer func() {
491490
onDone(attempts, finalErr)
492491
}()
493492

494-
err := doTx(ctx, c.pool,
495-
func(ctx context.Context, tx query.TxActor) error {
496-
attempts++
497-
498-
return op(ctx, tx)
499-
},
500-
doTxOpts.TxSettings(),
493+
err := doTx(ctx, c.pool, op,
494+
settings.TxSettings(),
501495
append(
502496
[]retry.Option{
503497
retry.WithTrace(&trace.Retry{
@@ -508,7 +502,7 @@ func (c *Client) DoTx(ctx context.Context, op query.TxOperation, opts ...options
508502
},
509503
}),
510504
},
511-
doTxOpts.RetryOpts()...,
505+
settings.RetryOpts()...,
512506
)...,
513507
)
514508
if err != nil {

internal/query/options/retry.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,12 @@ func ParseDoOpts(t *trace.Query, opts ...DoOption) (s *doSettings) {
114114
return s
115115
}
116116

117-
func ParseDoTxOpts(opts ...DoTxOption) (s *doTxSettings) {
117+
func ParseDoTxOpts(t *trace.Query, opts ...DoTxOption) (s *doTxSettings) {
118118
s = &doTxSettings{
119119
txSettings: tx.NewSettings(tx.WithDefaultTxMode()),
120-
doSettings: doSettings{},
120+
doSettings: doSettings{
121+
trace: t,
122+
},
121123
}
122124

123125
for _, opt := range opts {

tests/slo/internal/metrics/metrics.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package metrics
22

33
import (
44
"fmt"
5-
"log"
65
"time"
76

87
"github.com/prometheus/client_golang/prometheus"
@@ -122,21 +121,11 @@ func (m *Metrics) Start(name SpanName) Span {
122121
return j
123122
}
124123

125-
func (j Span) Stop(err error, attempts int) {
124+
func (j Span) Finish(err error, attempts int) {
126125
j.m.inflight.WithLabelValues(j.name).Sub(1)
127126

128127
latency := time.Since(j.start)
129128

130-
if attempts > 1 {
131-
log.Printf("more than 1 attempt for request (request_type: %q, attempts: %d, start: %s, latency: %s, err: %v)",
132-
j.name,
133-
attempts,
134-
j.start.Format(time.DateTime),
135-
latency.String(),
136-
err,
137-
)
138-
}
139-
140129
var (
141130
successLabel = JobStatusOK
142131
successCounter = j.m.oks

tests/slo/internal/workers/read.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,17 @@ func (w *Workers) Read(ctx context.Context, wg *sync.WaitGroup, rl *rate.Limiter
2323
}
2424
}
2525

26-
func (w *Workers) read(ctx context.Context) (err error) {
26+
func (w *Workers) read(ctx context.Context) error {
2727
id := uint64(rand.Intn(int(w.cfg.InitialDataCount))) //nolint:gosec // speed more important
2828

29-
var attempts int
30-
3129
m := w.m.Start(metrics.JobRead)
32-
defer func() {
33-
m.Stop(err, attempts)
34-
if err != nil {
35-
log.Printf("get entry error: %v", err)
36-
}
37-
}()
3830

39-
_, attempts, err = w.s.Read(ctx, id)
31+
_, attempts, err := w.s.Read(ctx, id)
32+
if err != nil {
33+
log.Printf("read failed with %d attempts: %v", attempts, err)
34+
}
35+
36+
m.Finish(err, attempts)
4037

4138
return err
4239
}

tests/slo/internal/workers/write.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,22 @@ func (w *Workers) Write(ctx context.Context, wg *sync.WaitGroup, rl *rate.Limite
2323
}
2424
}
2525

26-
func (w *Workers) write(ctx context.Context, gen *generator.Generator) (err error) {
27-
var row generator.Row
28-
row, err = gen.Generate()
26+
func (w *Workers) write(ctx context.Context, gen *generator.Generator) error {
27+
row, err := gen.Generate()
2928
if err != nil {
3029
log.Printf("generate error: %v", err)
3130

3231
return err
3332
}
3433

35-
var attempts int
36-
3734
m := w.m.Start(metrics.JobWrite)
38-
defer func() {
39-
m.Stop(err, attempts)
40-
if err != nil {
41-
log.Printf("error when stop 'write' worker: %v", err)
42-
}
43-
}()
4435

45-
attempts, err = w.s.Write(ctx, row)
36+
attempts, err := w.s.Write(ctx, row)
37+
if err != nil {
38+
log.Printf("write failed with %d attempts: %v", attempts, err)
39+
}
40+
41+
m.Finish(err, attempts)
4642

4743
return err
4844
}

tests/slo/native/query/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ func main() {
3737
ctx, cancel = context.WithTimeout(ctx, time.Duration(cfg.Time)*time.Second)
3838
defer cancel()
3939

40+
go func() {
41+
<-ctx.Done()
42+
log.Println("exiting...")
43+
}()
44+
4045
s, err := NewStorage(ctx, cfg, cfg.ReadRPS+cfg.WriteRPS, label)
4146
if err != nil {
4247
panic(fmt.Errorf("create storage failed: %w", err))

0 commit comments

Comments
 (0)