Skip to content

Commit 4ab4614

Browse files
committed
fix(driver,liner): after mr discussion
More generic way to pass dialfunc to driver. updateDialler -> Driver.Configure Explanations about the way dialfunc passed that way. pkg/driver package now have inverted dependency. Drivers should add themselves to driver dispatcher. Closes RNDSTROPPY-70
1 parent 10eec0c commit 4ab4614

16 files changed

Lines changed: 111 additions & 74 deletions

File tree

.golangci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ linters:
3636
- forcetypeassert
3737
- funlen
3838
- gocheckcompilerdirectives
39-
- gochecknoglobals
40-
- gochecknoinits
4139
- gochecksumtype
4240
- gocognit
4341
- goconst
@@ -150,7 +148,6 @@ linters:
150148
- gocognit
151149
- lll
152150
- mnd
153-
- gochecknoglobals
154151
- err113
155152
- ireturn
156153
allow-unused: true
@@ -226,7 +223,6 @@ linters:
226223
- wrapcheck
227224
path: _test\.go
228225
- linters:
229-
- gochecknoglobals
230226
- unused
231227
path: bind.go
232228
- linters:

cmd/stroppy/commands/gen/new.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
presetFlagName = "preset"
2323
)
2424

25-
var Cmd = &cobra.Command{ //nolint: gochecknoglobals
25+
var Cmd = &cobra.Command{
2626
Use: "gen",
2727
Short: "Generate stroppy development environment",
2828
Long: fmt.Sprintf(`
@@ -133,7 +133,7 @@ Examples:
133133
},
134134
}
135135

136-
func init() { //nolint: gochecknoinits // allow in cmd
136+
func init() {
137137
Cmd.PersistentFlags().String(
138138
workdirFlagName,
139139
".",

cmd/stroppy/commands/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/stroppy-io/stroppy/pkg/common/logger"
1313
)
1414

15-
var rootCmd = &cobra.Command{ //nolint: gochecknoglobals
15+
var rootCmd = &cobra.Command{
1616
Use: "stroppy",
1717
Short: "Tool to generate and run stress tests (e.g benchmarking) for databases",
1818
Long: `
@@ -26,7 +26,7 @@ For more information see https://github.com/stroppy-io/stroppy`,
2626
SilenceUsage: true,
2727
}
2828

29-
var versionCmd = &cobra.Command{ //nolint: gochecknoglobals
29+
var versionCmd = &cobra.Command{
3030
Use: "version",
3131
Short: "Print versions of stroppy components",
3232
Long: ``,
@@ -42,7 +42,7 @@ func Execute() {
4242
}
4343
}
4444

45-
func init() { //nolint: gochecknoinits // allow in cmd
45+
func init() {
4646
cobra.EnableCommandSorting = false
4747
rootCmd.CompletionOptions.HiddenDefaultCmd = true
4848
rootCmd.SetVersionTemplate(`{{with .Name}}{{printf "%s " .}}{{end}}{{printf "%s" .Version}}`)

cmd/stroppy/commands/run/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const (
1414
maxArgs = 2 // sql_file.sql is optional
1515
)
1616

17-
var Cmd = &cobra.Command{ //nolint: gochecknoglobals
17+
var Cmd = &cobra.Command{
1818
Use: "run <script.ts> [sql_file.sql]",
1919
Short: "Run benchmark script with k6",
2020
Long: `Run a TypeScript benchmark script with k6.

cmd/xk6air/driver_wrapper.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,35 @@ import (
1212
)
1313

1414
type DriverWrapper struct {
15-
vu modules.VU
16-
lg *zap.Logger
17-
drv driver.Driver
18-
onceUpdateDialler sync.Once
15+
vu modules.VU
16+
lg *zap.Logger
17+
drv driver.Driver
18+
19+
configureOnce sync.Once
1920
}
2021

21-
func (d *DriverWrapper) RunQuery(sql string, args map[string]any) any {
22-
d.onceUpdateDialler.Do(
23-
func() { d.drv.UpdateDialler(d.vu.Context(), d.vu.State().Dialer.DialContext) },
22+
// This is a custom "VU setup" hook.
23+
//
24+
// NOTE: k6 have no option to make per VU setup code execution by itself.
25+
// Check https://github.com/grafana/k6/issues/785
26+
// https://github.com/grafana/k6/issues/1638
27+
//
28+
// Unfortunatly it's impossible to pass DialFunc at [Instance.NewDriverByConfigBin]
29+
// because there is nil [modules.VU.State]. It may be fixed in the feature:
30+
// https://github.com/grafana/k6/issues?q=is%3Aopen+is%3Aissue+label%3Anew-http
31+
// https://github.com/grafana/k6/issues/2293
32+
func (d *DriverWrapper) configure() {
33+
d.configureOnce.Do(
34+
func() {
35+
d.drv.Configure(d.vu.Context(), driver.Options{
36+
DialFunc: d.vu.State().Dialer.DialContext,
37+
})
38+
},
2439
)
40+
}
2541

42+
func (d *DriverWrapper) RunQuery(sql string, args map[string]any) any {
43+
d.configure()
2644
stats, err := d.drv.RunQuery(d.vu.Context(), sql, args)
2745
if err != nil {
2846
return fmt.Errorf("error while executing sql query: %w", err)
@@ -31,13 +49,8 @@ func (d *DriverWrapper) RunQuery(sql string, args map[string]any) any {
3149
}
3250

3351
// InsertValuesBin starts bulk insert blocking operation on driver.
34-
func (d *DriverWrapper) InsertValuesBin(
35-
insertMsg []byte,
36-
count int64,
37-
) any {
38-
d.onceUpdateDialler.Do(
39-
func() { d.drv.UpdateDialler(d.vu.Context(), d.vu.State().Dialer.DialContext) },
40-
)
52+
func (d *DriverWrapper) InsertValuesBin(insertMsg []byte, count int64) any {
53+
d.configure()
4154
var descriptor stroppy.InsertDescriptor
4255
err := proto.Unmarshal(insertMsg, &descriptor)
4356
if err != nil {

cmd/xk6air/instance.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/stroppy-io/stroppy/pkg/common/logger"
88
"github.com/stroppy-io/stroppy/pkg/common/proto/stroppy"
99
"github.com/stroppy-io/stroppy/pkg/driver"
10+
_ "github.com/stroppy-io/stroppy/pkg/driver/postgres"
1011
"go.k6.io/k6/js/modules"
1112
"go.uber.org/zap"
1213
"google.golang.org/protobuf/proto"

cmd/xk6air/module.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var rootModule *RootModule
2020
var _ modules.Module = new(RootModule)
2121

2222
// rootModule initialization.
23-
func init() { //nolint:gochecknoinits // allow for xk6
23+
func init() {
2424
lg := logger.
2525
NewFromEnv().
2626
Named("k6-module").

internal/static/embed.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
)
3131

3232
// StaticFiles are copied to temp dir for k6 execution.
33-
var StaticFiles = []FileName{ //nolint: gochecknoglobals
33+
var StaticFiles = []FileName{
3434
ProtoJSFileName,
3535
K6PluginFileName,
3636
HelpersFileName,
@@ -40,14 +40,14 @@ var StaticFiles = []FileName{ //nolint: gochecknoglobals
4040
}
4141

4242
// DevStaticFiles are additional files for development environment.
43-
var DevStaticFiles = []FileName{ //nolint: gochecknoglobals
43+
var DevStaticFiles = []FileName{
4444
PackageJSONFileName,
4545
ParseSQLTSFileName,
4646
ProtoTSFileName,
4747
TSConfigFileName,
4848
}
4949

50-
var Binaries = []FileName{ //nolint: gochecknoglobals
50+
var Binaries = []FileName{
5151
K6PluginFileName,
5252
}
5353

internal/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package version
22

3-
var Version = "0.0.0" //nolint: gochecknoglobals
3+
var Version = "0.0.0"

pkg/common/generate/randstr/string.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func (sg *StringGenerator) Next() string {
1212
return sg.cutter.Cut()
1313
}
1414

15-
var DefaultEnglishAlphabet = [][2]int32{{65, 90}, {97, 122}} //nolint: gochecknoglobals
15+
var DefaultEnglishAlphabet = [][2]int32{{65, 90}, {97, 122}}
1616

1717
func NewStringGenerator(
1818
seed uint64,

0 commit comments

Comments
 (0)