Skip to content

Commit f15e075

Browse files
authored
Merge pull request #747 from ydb-platform/calcattemptsinslo
test(slo): calc attempts for requests
2 parents de39d21 + bf0b0bf commit f15e075

File tree

14 files changed

+285
-93
lines changed

14 files changed

+285
-93
lines changed

.github/workflows/slo.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ on:
88
workflow_dispatch:
99
jobs:
1010
native:
11-
needs: [gorm]
1211
concurrency:
1312
group: slo-native-${{ github.ref }}
14-
if: github.event.pull_request.head.repo.full_name == 'ydb-platform/ydb-go-sdk' &&
15-
!contains(github.event.pull_request.labels.*.name, 'no slo')
13+
if: (!contains(github.event.pull_request.labels.*.name, 'no slo'))
1614
uses: ydb-platform/slo-tests/.github/workflows/slo.yml@main
1715
secrets: inherit
1816
with:
@@ -25,8 +23,7 @@ jobs:
2523
needs: [native]
2624
concurrency:
2725
group: slo-database-sql-${{ github.ref }}
28-
if: github.event.pull_request.head.repo.full_name == 'ydb-platform/ydb-go-sdk' &&
29-
!contains(github.event.pull_request.labels.*.name, 'no slo')
26+
if: always() && !contains(github.event.pull_request.labels.*.name, 'no slo')
3027
uses: ydb-platform/slo-tests/.github/workflows/slo.yml@main
3128
secrets: inherit
3229
with:
@@ -36,10 +33,10 @@ jobs:
3633
workload_build_options: -f Dockerfile --build-arg SRC_PATH=database/sql
3734
workload_build_context: ../..
3835
gorm:
36+
needs: [database_sql]
3937
concurrency:
4038
group: slo-gorm-${{ github.ref }}
41-
if: github.event.pull_request.head.repo.full_name == 'ydb-platform/ydb-go-sdk' &&
42-
!contains(github.event.pull_request.labels.*.name, 'no slo')
39+
if: always() && !contains(github.event.pull_request.labels.*.name, 'no slo')
4340
uses: ydb-platform/slo-tests/.github/workflows/slo.yml@main
4441
secrets: inherit
4542
with:

tests/slo/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM golang:1.20 as build
22
ARG SRC_PATH
33
COPY . /src
44
WORKDIR /src/tests/slo/${SRC_PATH}
5-
RUN CGO_ENABLED=0 go build -o /build/slo-go-workload .
5+
RUN CGO_ENABLED=0 go build -o /build/slo-go-workload -ldflags "-X \"main.label=${SRC_PATH}\"" .
66

77
FROM scratch
88
COPY --from=build /build /

tests/slo/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ Primary key: `("hash", "id")`
123123
- `not_oks` - amount of not OK requests
124124
- `inflight` - amount of requests in flight
125125
- `latency` - summary of latencies in ms
126+
- `attempts` - summary of amount for request
126127

127128
> You must reset metrics to keep them `0` in prometheus and grafana before beginning and after ending of jobs
128129
@@ -140,6 +141,8 @@ func (m *Metrics) Reset() error {
140141

141142
m.latencies.Reset()
142143

144+
m.attempts.Reset()
145+
143146
return m.Push()
144147
}
145148
```

tests/slo/database/sql/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020

2121
var logger *zap.Logger
2222

23+
var label string
24+
2325
func init() {
2426
var err error
2527
logger, err = zap.NewProduction(zap.AddStacktrace(zapcore.PanicLevel))
@@ -78,7 +80,7 @@ func main() {
7880
return err
7981
}
8082

81-
err = s.Write(ctx, e)
83+
_, err = s.Write(ctx, e)
8284
if err != nil {
8385
return err
8486
}
@@ -103,7 +105,7 @@ func main() {
103105
case config.RunMode:
104106
gen := generator.New(cfg.InitialDataCount)
105107

106-
w, err := workers.New(cfg, s, logger)
108+
w, err := workers.New(cfg, s, logger, label)
107109
if err != nil {
108110
panic(fmt.Errorf("create workers failed: %w", err))
109111
}

tests/slo/database/sql/storage.go

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"database/sql"
66
"fmt"
7+
"path"
78
"time"
89

910
env "github.com/ydb-platform/ydb-go-sdk-auth-environ"
@@ -104,6 +105,7 @@ func NewStorage(ctx context.Context, cfg *config.Config, poolSize int) (s *Stora
104105

105106
s.c, err = ydb.Connector(s.cc,
106107
ydb.WithAutoDeclare(),
108+
ydb.WithTablePathPrefix(path.Join(s.cc.Name(), label)),
107109
)
108110
if err != nil {
109111
return nil, fmt.Errorf("ydb.Connector error: %w", err)
@@ -118,45 +120,84 @@ func NewStorage(ctx context.Context, cfg *config.Config, poolSize int) (s *Stora
118120
return s, nil
119121
}
120122

121-
func (s *Storage) Read(ctx context.Context, entryID generator.RowID) (res generator.Row, err error) {
123+
func (s *Storage) Read(ctx context.Context, entryID generator.RowID) (res generator.Row, attempts int, err error) {
122124
if err = ctx.Err(); err != nil {
123-
return generator.Row{}, err
125+
return generator.Row{}, attempts, err
124126
}
125127

126128
ctx, cancel := context.WithTimeout(ctx, time.Duration(s.cfg.ReadTimeout)*time.Millisecond)
127129
defer cancel()
128130

129131
err = retry.Do(ydb.WithTxControl(ctx, readTx), s.db,
130132
func(ctx context.Context, cc *sql.Conn) (err error) {
133+
if err = ctx.Err(); err != nil {
134+
return err
135+
}
136+
131137
row := cc.QueryRowContext(ydb.WithQueryMode(ctx, ydb.DataQueryMode), s.selectQuery,
132138
sql.Named("id", &entryID),
133139
)
140+
134141
var hash *uint64
142+
135143
return row.Scan(&res.ID, &res.PayloadStr, &res.PayloadDouble, &res.PayloadTimestamp, &hash)
136-
}, retry.WithDoRetryOptions(retry.WithIdempotent(true)),
144+
},
145+
retry.WithDoRetryOptions(
146+
retry.WithIdempotent(true),
147+
retry.WithTrace(
148+
trace.Retry{
149+
OnRetry: func(info trace.RetryLoopStartInfo) func(trace.RetryLoopIntermediateInfo) func(trace.RetryLoopDoneInfo) {
150+
return func(info trace.RetryLoopIntermediateInfo) func(trace.RetryLoopDoneInfo) {
151+
return func(info trace.RetryLoopDoneInfo) {
152+
attempts = info.Attempts
153+
}
154+
}
155+
},
156+
},
157+
),
158+
),
137159
)
138160

139-
return res, err
161+
return res, attempts, err
140162
}
141163

142-
func (s *Storage) Write(ctx context.Context, e generator.Row) error {
143-
if err := ctx.Err(); err != nil {
144-
return err
164+
func (s *Storage) Write(ctx context.Context, e generator.Row) (attempts int, err error) {
165+
if err = ctx.Err(); err != nil {
166+
return attempts, err
145167
}
146168

147169
ctx, cancel := context.WithTimeout(ctx, time.Duration(s.cfg.WriteTimeout)*time.Millisecond)
148170
defer cancel()
149171

150-
return retry.Do(ydb.WithTxControl(ctx, writeTx), s.db,
151-
func(ctx context.Context, cc *sql.Conn) error {
152-
_, err := cc.ExecContext(ydb.WithQueryMode(ctx, ydb.DataQueryMode), s.upsertQuery,
172+
return attempts, retry.Do(ydb.WithTxControl(ctx, writeTx), s.db,
173+
func(ctx context.Context, cc *sql.Conn) (err error) {
174+
if err = ctx.Err(); err != nil {
175+
return err
176+
}
177+
178+
_, err = cc.ExecContext(ydb.WithQueryMode(ctx, ydb.DataQueryMode), s.upsertQuery,
153179
sql.Named("id", e.ID),
154180
sql.Named("payload_str", *e.PayloadStr),
155181
sql.Named("payload_double", *e.PayloadDouble),
156182
sql.Named("payload_timestamp", *e.PayloadTimestamp),
157183
)
184+
158185
return err
159-
}, retry.WithDoRetryOptions(retry.WithIdempotent(true)),
186+
},
187+
retry.WithDoRetryOptions(
188+
retry.WithIdempotent(true),
189+
retry.WithTrace(
190+
trace.Retry{
191+
OnRetry: func(info trace.RetryLoopStartInfo) func(trace.RetryLoopIntermediateInfo) func(trace.RetryLoopDoneInfo) {
192+
return func(info trace.RetryLoopIntermediateInfo) func(trace.RetryLoopDoneInfo) {
193+
return func(info trace.RetryLoopDoneInfo) {
194+
attempts = info.Attempts
195+
}
196+
}
197+
},
198+
},
199+
),
200+
),
160201
)
161202
}
162203

tests/slo/gorm/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020

2121
var logger *zap.Logger
2222

23+
var label string
24+
2325
func init() {
2426
var err error
2527
logger, err = zap.NewProduction(zap.AddStacktrace(zapcore.PanicLevel))
@@ -78,7 +80,7 @@ func main() {
7880
return err
7981
}
8082

81-
err = s.Write(ctx, e)
83+
_, err = s.Write(ctx, e)
8284
if err != nil {
8385
return err
8486
}
@@ -103,7 +105,7 @@ func main() {
103105
case config.RunMode:
104106
gen := generator.New(cfg.InitialDataCount)
105107

106-
w, err := workers.New(cfg, s, logger)
108+
w, err := workers.New(cfg, s, logger, label)
107109
if err != nil {
108110
panic(fmt.Errorf("create workers failed: %w", err))
109111
}

0 commit comments

Comments
 (0)