Skip to content

Commit 9558374

Browse files
test(slo): add table path prefixes
1 parent c2f3d9e commit 9558374

File tree

5 files changed

+35
-38
lines changed

5 files changed

+35
-38
lines changed

.github/workflows/slo.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ jobs:
1010
native:
1111
concurrency:
1212
group: slo-native-${{ github.ref }}
13-
if: github.event.pull_request.head.repo.full_name == 'ydb-platform/ydb-go-sdk' &&
14-
!contains(github.event.pull_request.labels.*.name, 'no slo')
13+
if: (!contains(github.event.pull_request.labels.*.name, 'no slo'))
1514
uses: ydb-platform/slo-tests/.github/workflows/slo.yml@main
1615
secrets: inherit
1716
with:
@@ -24,8 +23,7 @@ jobs:
2423
needs: [native]
2524
concurrency:
2625
group: slo-database-sql-${{ github.ref }}
27-
if: github.event.pull_request.head.repo.full_name == 'ydb-platform/ydb-go-sdk' &&
28-
!contains(github.event.pull_request.labels.*.name, 'no slo')
26+
if: always() && !contains(github.event.pull_request.labels.*.name, 'no slo')
2927
uses: ydb-platform/slo-tests/.github/workflows/slo.yml@main
3028
secrets: inherit
3129
with:
@@ -38,8 +36,7 @@ jobs:
3836
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/database/sql/storage.go

Lines changed: 2 additions & 0 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)

tests/slo/gorm/storage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ func NewStorage(ctx context.Context, cfg *config.Config, poolSize int) (*Storage
8080
),
8181
ydb.WithMaxOpenConns(poolSize),
8282
ydb.WithMaxIdleConns(poolSize),
83+
ydb.WithTablePathPrefix(label),
8384
),
8485
&gorm.Config{
85-
Logger: gormLogger.Default.LogMode(gormLogger.Info),
86+
Logger: gormLogger.Default.LogMode(gormLogger.Warn),
8687
},
8788
)
8889
if err != nil {

tests/slo/internal/metrics/metrics.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ const (
1818

1919
type (
2020
Metrics struct {
21-
oks *prometheus.GaugeVec
22-
notOks *prometheus.GaugeVec
23-
inflight *prometheus.GaugeVec
24-
latencies *prometheus.SummaryVec
25-
latenciesH *prometheus.HistogramVec
26-
attempts *prometheus.HistogramVec
21+
oks *prometheus.GaugeVec
22+
notOks *prometheus.GaugeVec
23+
inflight *prometheus.GaugeVec
24+
latencies *prometheus.SummaryVec
25+
attempts *prometheus.HistogramVec
2726

2827
p *push.Pusher
2928

@@ -66,22 +65,14 @@ func New(logger *zap.Logger, url, label string) (*Metrics, error) {
6665
Name: "latency",
6766
Help: "summary of latencies in ms",
6867
Objectives: map[float64]float64{
69-
0.5: 0.05,
70-
0.99: 0.001,
71-
1.0: 0.0,
68+
0.5: 0,
69+
0.99: 0,
70+
1.0: 0,
7271
},
7372
MaxAge: 15 * time.Second,
7473
},
7574
[]string{"status", "jobName"},
7675
)
77-
m.latenciesH = prometheus.NewHistogramVec(
78-
prometheus.HistogramOpts{
79-
Name: "latencyH",
80-
Help: "latencies in ms",
81-
Buckets: []float64{1, 2, 5, 10, 20, 50, 100, 200, 400, 800, 1600, 3200, 6400},
82-
},
83-
[]string{"status", "jobName"},
84-
)
8576
m.attempts = prometheus.NewHistogramVec(
8677
prometheus.HistogramOpts{
8778
Name: "attempts",
@@ -98,7 +89,6 @@ func New(logger *zap.Logger, url, label string) (*Metrics, error) {
9889
Collector(m.notOks).
9990
Collector(m.inflight).
10091
Collector(m.latencies).
101-
Collector(m.latenciesH).
10292
Collector(m.attempts)
10393

10494
return m, m.Reset() //nolint:gocritic
@@ -119,7 +109,6 @@ func (m *Metrics) Reset() error {
119109
m.inflight.WithLabelValues(JobWrite).Set(0)
120110

121111
m.latencies.Reset()
122-
m.latenciesH.Reset()
123112

124113
m.attempts.Reset()
125114

@@ -158,13 +147,11 @@ func (j Span) Stop(err error, attempts int) {
158147
if err != nil {
159148
j.m.notOks.WithLabelValues(j.name).Add(1)
160149
j.m.latencies.WithLabelValues(JobStatusErr, j.name).Observe(latency)
161-
j.m.latenciesH.WithLabelValues(JobStatusErr, j.name).Observe(latency)
162150
j.m.attempts.WithLabelValues(JobStatusErr, j.name).Observe(float64(attempts))
163151
return
164152
}
165153

166154
j.m.oks.WithLabelValues(j.name).Add(1)
167155
j.m.latencies.WithLabelValues(JobStatusOK, j.name).Observe(latency)
168-
j.m.latenciesH.WithLabelValues(JobStatusOK, j.name).Observe(latency)
169156
j.m.attempts.WithLabelValues(JobStatusOK, j.name).Observe(float64(attempts))
170157
}

tests/slo/native/storage.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,22 @@ import (
2222

2323
const (
2424
upsertTemplate = `
25+
PRAGMA TablePathPrefix("%s");
26+
2527
DECLARE $id AS Uint64;
2628
DECLARE $payload_str AS Utf8;
2729
DECLARE $payload_double AS Double;
2830
DECLARE $payload_timestamp AS Timestamp;
31+
2932
UPSERT INTO %s (
3033
id, hash, payload_str, payload_double, payload_timestamp
3134
) VALUES (
3235
$id, Digest::NumericHash($id), $payload_str, $payload_double, $payload_timestamp
3336
);
3437
`
3538
selectTemplate = `
39+
PRAGMA TablePathPrefix("%s");
40+
3641
DECLARE $id AS Uint64;
3742
SELECT id, payload_str, payload_double, payload_timestamp, payload_hash
3843
FROM %s WHERE id = $id AND hash = Digest::NumericHash($id);
@@ -55,6 +60,7 @@ var (
5560
type Storage struct {
5661
db *ydb.Driver
5762
cfg *config.Config
63+
prefix string
5864
upsertQuery string
5965
selectQuery string
6066
}
@@ -63,15 +69,9 @@ func NewStorage(ctx context.Context, cfg *config.Config, poolSize int) (*Storage
6369
ctx, cancel := context.WithTimeout(ctx, time.Minute*5)
6470
defer cancel()
6571

66-
s := &Storage{
67-
cfg: cfg,
68-
upsertQuery: fmt.Sprintf(upsertTemplate, cfg.Table),
69-
selectQuery: fmt.Sprintf(selectTemplate, cfg.Table),
70-
}
71-
var err error
72-
s.db, err = ydb.Open(
72+
db, err := ydb.Open(
7373
ctx,
74-
s.cfg.Endpoint+s.cfg.DB,
74+
cfg.Endpoint+cfg.DB,
7575
env.WithEnvironCredentials(ctx),
7676
ydbZap.WithTraces(
7777
logger,
@@ -83,6 +83,16 @@ func NewStorage(ctx context.Context, cfg *config.Config, poolSize int) (*Storage
8383
return nil, err
8484
}
8585

86+
prefix := path.Join(db.Name(), label)
87+
88+
s := &Storage{
89+
db: db,
90+
cfg: cfg,
91+
prefix: prefix,
92+
upsertQuery: fmt.Sprintf(upsertTemplate, prefix, cfg.Table),
93+
selectQuery: fmt.Sprintf(selectTemplate, prefix, cfg.Table),
94+
}
95+
8696
return s, nil
8797
}
8898

@@ -201,7 +211,7 @@ func (s *Storage) createTable(ctx context.Context) error {
201211

202212
return s.db.Table().Do(ctx,
203213
func(ctx context.Context, session table.Session) error {
204-
return session.CreateTable(ctx, path.Join(s.db.Name(), s.cfg.Table),
214+
return session.CreateTable(ctx, path.Join(s.prefix, s.cfg.Table),
205215
options.WithColumn("hash", types.Optional(types.TypeUint64)),
206216
options.WithColumn("id", types.Optional(types.TypeUint64)),
207217
options.WithColumn("payload_str", types.Optional(types.TypeUTF8)),
@@ -234,7 +244,7 @@ func (s *Storage) dropTable(ctx context.Context) error {
234244

235245
return s.db.Table().Do(ctx,
236246
func(ctx context.Context, session table.Session) (err error) {
237-
return session.DropTable(ctx, path.Join(s.db.Name(), s.cfg.Table))
247+
return session.DropTable(ctx, path.Join(s.prefix, s.cfg.Table))
238248
},
239249
table.WithIdempotent(),
240250
)

0 commit comments

Comments
 (0)