Skip to content

Commit 3ea6bfe

Browse files
authored
Change to using sobek instead of goja (#297)
We are moving to a fork of goja under grafana org called sobek. More info in: - grafana/k6#3772 - grafana/k6#3773
1 parent 9fa0159 commit 3ea6bfe

16 files changed

+130
-158
lines changed

go.mod

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module github.com/mostafa/xk6-kafka
22

3-
go 1.22
3+
go 1.20
44

55
require (
66
github.com/aws/aws-sdk-go-v2/config v1.18.39
7-
github.com/dop251/goja v0.0.0-20240220182346-e401ed450204
7+
github.com/grafana/sobek v0.0.0-20240607083612-4f0cd64f4e78
88
github.com/linkedin/goavro/v2 v2.12.0
99
github.com/pavlo-v-chernykh/keystore-go/v4 v4.5.0
1010
github.com/riferrei/srclient v0.6.0
@@ -13,12 +13,11 @@ require (
1313
github.com/segmentio/kafka-go/sasl/aws_msk_iam_v2 v0.1.0
1414
github.com/sirupsen/logrus v1.9.3
1515
github.com/stretchr/testify v1.9.0
16-
go.k6.io/k6 v0.50.0
16+
go.k6.io/k6 v0.51.1-0.20240610082146-1f01a9bc2365
1717
gopkg.in/guregu/null.v3 v3.5.0
1818
)
1919

2020
require (
21-
github.com/andybalholm/brotli v1.1.0 // indirect
2221
github.com/aws/aws-sdk-go-v2 v1.24.0 // indirect
2322
github.com/aws/aws-sdk-go-v2/credentials v1.13.37 // indirect
2423
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11 // indirect
@@ -33,11 +32,12 @@ require (
3332
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
3433
github.com/davecgh/go-spew v1.1.1 // indirect
3534
github.com/dlclark/regexp2 v1.11.0 // indirect
35+
github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 // indirect
36+
github.com/evanw/esbuild v0.21.2 // indirect
3637
github.com/fatih/color v1.16.0 // indirect
3738
github.com/go-logr/logr v1.4.1 // indirect
3839
github.com/go-logr/stdr v1.2.2 // indirect
3940
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
40-
github.com/golang/protobuf v1.5.4 // indirect
4141
github.com/golang/snappy v0.0.4 // indirect
4242
github.com/google/pprof v0.0.0-20240402174815-29b9bb013b0f // indirect
4343
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
@@ -47,6 +47,7 @@ require (
4747
github.com/mattn/go-colorable v0.1.13 // indirect
4848
github.com/mattn/go-isatty v0.0.20 // indirect
4949
github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect
50+
github.com/mstoykov/k6-taskqueue-lib v0.1.0 // indirect
5051
github.com/onsi/ginkgo v1.16.5 // indirect
5152
github.com/onsi/gomega v1.20.2 // indirect
5253
github.com/pierrec/lz4/v4 v4.1.19 // indirect
@@ -64,15 +65,15 @@ require (
6465
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
6566
go.opentelemetry.io/otel/trace v1.24.0 // indirect
6667
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
67-
golang.org/x/crypto v0.21.0 // indirect
68-
golang.org/x/net v0.23.0 // indirect
69-
golang.org/x/sync v0.6.0 // indirect
70-
golang.org/x/sys v0.18.0 // indirect
71-
golang.org/x/text v0.14.0 // indirect
68+
golang.org/x/crypto v0.24.0 // indirect
69+
golang.org/x/net v0.26.0 // indirect
70+
golang.org/x/sync v0.7.0 // indirect
71+
golang.org/x/sys v0.21.0 // indirect
72+
golang.org/x/text v0.16.0 // indirect
7273
golang.org/x/time v0.5.0 // indirect
7374
google.golang.org/genproto/googleapis/api v0.0.0-20240401170217-c3f982113cda // indirect
7475
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
75-
google.golang.org/grpc v1.62.1 // indirect
76+
google.golang.org/grpc v1.63.2 // indirect
7677
google.golang.org/protobuf v1.33.0 // indirect
7778
gopkg.in/yaml.v3 v3.0.1 // indirect
7879
)

go.sum

Lines changed: 23 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jks.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"log"
88
"os"
99

10-
"github.com/dop251/goja"
10+
"github.com/grafana/sobek"
1111
"github.com/pavlo-v-chernykh/keystore-go/v4"
1212
"go.k6.io/k6/js/common"
1313
)
@@ -117,7 +117,7 @@ func (*Kafka) loadJKS(jksConfig *JKSConfig) (*JKS, *Xk6KafkaError) {
117117
}, nil
118118
}
119119

120-
func (k *Kafka) loadJKSFunction(call goja.FunctionCall) goja.Value {
120+
func (k *Kafka) loadJKSFunction(call sobek.FunctionCall) sobek.Value {
121121
runtime := k.vu.Runtime()
122122
var jksConfig *JKSConfig
123123

@@ -171,7 +171,7 @@ func saveServerCaFile(filename string, cert *keystore.TrustedCertificateEntry) *
171171
Bytes: cert.Certificate.Content,
172172
})
173173

174-
if err := os.WriteFile(filename, certPem, 0644); err != nil {
174+
if err := os.WriteFile(filename, certPem, 0o644); err != nil {
175175
return NewXk6KafkaError(
176176
failedWriteServerCaFile, "Failed to write CA file", err)
177177
}
@@ -186,7 +186,7 @@ func saveClientKeyFile(filename string, key *keystore.PrivateKeyEntry) *Xk6Kafka
186186
Bytes: key.PrivateKey,
187187
})
188188

189-
if err := os.WriteFile(filename, keyPem, 0644); err != nil {
189+
if err := os.WriteFile(filename, keyPem, 0o644); err != nil {
190190
return NewXk6KafkaError(
191191
failedWriteKeyFile, "Failed to write key file", err)
192192
}
@@ -200,7 +200,7 @@ func saveClientCertFile(filename string, cert *keystore.Certificate) *Xk6KafkaEr
200200
Type: "CERTIFICATE",
201201
Bytes: cert.Content,
202202
})
203-
if err := os.WriteFile(filename, clientCertPem, 0644); err != nil {
203+
if err := os.WriteFile(filename, clientCertPem, 0o644); err != nil {
204204
return NewXk6KafkaError(
205205
failedWriteCertFile, "Failed to write cert file", err)
206206
}

jks_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55
"testing"
66

7-
"github.com/dop251/goja"
7+
"github.com/grafana/sobek"
88
"github.com/stretchr/testify/assert"
99
)
1010

@@ -118,8 +118,8 @@ func TestJKS(t *testing.T) {
118118
func TestLoadJKS_Function(t *testing.T) {
119119
test := getTestModuleInstance(t)
120120

121-
jks := test.module.Kafka.loadJKSFunction(goja.FunctionCall{
122-
Arguments: []goja.Value{
121+
jks := test.module.Kafka.loadJKSFunction(sobek.FunctionCall{
122+
Arguments: []sobek.Value{
123123
test.module.vu.Runtime().ToValue(
124124
map[string]interface{}{
125125
"path": "fixtures/kafka-keystore.jks",

kafka_helpers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/dop251/goja"
7+
"github.com/grafana/sobek"
88
kafkago "github.com/segmentio/kafka-go"
99
"github.com/stretchr/testify/require"
1010
"go.k6.io/k6/js/common"
@@ -20,7 +20,7 @@ const (
2020

2121
// struct to keep all the things test need in one place.
2222
type kafkaTest struct {
23-
rt *goja.Runtime
23+
rt *sobek.Runtime
2424
module *Module
2525
vu *modulestest.VU
2626
samples chan metrics.SampleContainer
@@ -31,7 +31,7 @@ type kafkaTest struct {
3131
// nolint: golint,revive
3232
func getTestModuleInstance(tb testing.TB) *kafkaTest {
3333
tb.Helper()
34-
runtime := goja.New()
34+
runtime := sobek.New()
3535
runtime.SetFieldNameMapper(common.FieldNameMapper{})
3636

3737
ctx, cancel := context.WithCancel(context.Background())

module.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"crypto/tls"
55
"time"
66

7-
"github.com/dop251/goja"
7+
"github.com/grafana/sobek"
88
"github.com/riferrei/srclient"
99
kafkago "github.com/segmentio/kafka-go"
1010
"github.com/segmentio/kafka-go/compress"
@@ -74,7 +74,7 @@ type (
7474
Kafka struct {
7575
vu modules.VU
7676
metrics kafkaMetrics
77-
exports *goja.Object
77+
exports *sobek.Object
7878
schemaCache map[string]*Schema
7979
}
8080
RootModule struct{}
@@ -151,7 +151,7 @@ func (m *Module) defineConstants() {
151151
runtime := m.vu.Runtime()
152152
mustAddProp := func(name string, val interface{}) {
153153
err := m.exports.DefineDataProperty(
154-
name, runtime.ToValue(val), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE,
154+
name, runtime.ToValue(val), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE,
155155
)
156156
if err != nil {
157157
common.Throw(runtime, err)

reader.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"io"
88
"time"
99

10-
"github.com/dop251/goja"
10+
"github.com/grafana/sobek"
1111
kafkago "github.com/segmentio/kafka-go"
1212
"go.k6.io/k6/js/common"
1313
"go.k6.io/k6/metrics"
@@ -109,7 +109,7 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
109109
// readerClass is a wrapper around kafkago.reader and acts as a JS constructor
110110
// for this extension, thus it must be called with new operator, e.g. new Reader(...).
111111
// nolint: funlen
112-
func (k *Kafka) readerClass(call goja.ConstructorCall) *goja.Object {
112+
func (k *Kafka) readerClass(call sobek.ConstructorCall) *sobek.Object {
113113
runtime := k.vu.Runtime()
114114
var readerConfig *ReaderConfig
115115
if len(call.Arguments) == 0 {
@@ -134,7 +134,7 @@ func (k *Kafka) readerClass(call goja.ConstructorCall) *goja.Object {
134134
common.Throw(runtime, err)
135135
}
136136

137-
err := readerObject.Set("consume", func(call goja.FunctionCall) goja.Value {
137+
err := readerObject.Set("consume", func(call sobek.FunctionCall) sobek.Value {
138138
var consumeConfig *ConsumeConfig
139139
if len(call.Arguments) == 0 {
140140
common.Throw(runtime, ErrNotEnoughArguments)
@@ -157,12 +157,12 @@ func (k *Kafka) readerClass(call goja.ConstructorCall) *goja.Object {
157157
}
158158

159159
// This is unnecessary, but it's here for reference purposes
160-
err = readerObject.Set("close", func(call goja.FunctionCall) goja.Value {
160+
err = readerObject.Set("close", func(call sobek.FunctionCall) sobek.Value {
161161
if err := reader.Close(); err != nil {
162162
common.Throw(runtime, err)
163163
}
164164

165-
return goja.Undefined()
165+
return sobek.Undefined()
166166
})
167167
if err != nil {
168168
common.Throw(runtime, err)

reader_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/dop251/goja"
8+
"github.com/grafana/sobek"
99
"github.com/riferrei/srclient"
1010
kafkago "github.com/segmentio/kafka-go"
1111
"github.com/stretchr/testify/assert"
@@ -329,8 +329,8 @@ func TestReaderClass(t *testing.T) {
329329
})
330330

331331
assert.NotPanics(t, func() {
332-
reader := test.module.readerClass(goja.ConstructorCall{
333-
Arguments: []goja.Value{
332+
reader := test.module.readerClass(sobek.ConstructorCall{
333+
Arguments: []sobek.Value{
334334
test.module.vu.Runtime().ToValue(
335335
map[string]interface{}{
336336
"brokers": []string{"localhost:9092"},
@@ -347,9 +347,9 @@ func TestReaderClass(t *testing.T) {
347347
assert.Equal(t, this.Config().Topic, "test-reader-class")
348348
assert.Equal(t, this.Config().MaxWait, time.Second*3)
349349

350-
consume := reader.Get("consume").Export().(func(goja.FunctionCall) goja.Value)
351-
messages := consume(goja.FunctionCall{
352-
Arguments: []goja.Value{
350+
consume := reader.Get("consume").Export().(func(sobek.FunctionCall) sobek.Value)
351+
messages := consume(sobek.FunctionCall{
352+
Arguments: []sobek.Value{
353353
test.module.vu.Runtime().ToValue(
354354
map[string]interface{}{
355355
"limit": 1,
@@ -370,9 +370,9 @@ func TestReaderClass(t *testing.T) {
370370
assert.Equal(t, "value", deserializedValue)
371371

372372
// Close the reader.
373-
close := reader.Get("close").Export().(func(goja.FunctionCall) goja.Value)
373+
close := reader.Get("close").Export().(func(sobek.FunctionCall) sobek.Value)
374374
assert.NotNil(t, close)
375-
result := close(goja.FunctionCall{}).Export()
375+
result := close(sobek.FunctionCall{}).Export()
376376
assert.Nil(t, result)
377377

378378
// Check if one message was consumed.

schema_registry.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77
"net/http"
88

9-
"github.com/dop251/goja"
9+
"github.com/grafana/sobek"
1010
"github.com/linkedin/goavro/v2"
1111
"github.com/riferrei/srclient"
1212
"github.com/santhosh-tekuri/jsonschema/v5"
@@ -92,7 +92,7 @@ func (s *Schema) JsonSchema() *jsonschema.Schema {
9292
return s.jsonSchema
9393
}
9494

95-
func (k *Kafka) schemaRegistryClientClass(call goja.ConstructorCall) *goja.Object {
95+
func (k *Kafka) schemaRegistryClientClass(call sobek.ConstructorCall) *sobek.Object {
9696
runtime := k.vu.Runtime()
9797
var configuration *SchemaRegistryConfig
9898
var schemaRegistryClient *srclient.SchemaRegistryClient
@@ -117,7 +117,7 @@ func (k *Kafka) schemaRegistryClientClass(call goja.ConstructorCall) *goja.Objec
117117
common.Throw(runtime, err)
118118
}
119119

120-
err := schemaRegistryClientObject.Set("getSchema", func(call goja.FunctionCall) goja.Value {
120+
err := schemaRegistryClientObject.Set("getSchema", func(call sobek.FunctionCall) sobek.Value {
121121
if len(call.Arguments) == 0 {
122122
common.Throw(runtime, ErrNotEnoughArguments)
123123
}
@@ -143,7 +143,7 @@ func (k *Kafka) schemaRegistryClientClass(call goja.ConstructorCall) *goja.Objec
143143
common.Throw(runtime, err)
144144
}
145145

146-
err = schemaRegistryClientObject.Set("createSchema", func(call goja.FunctionCall) goja.Value {
146+
err = schemaRegistryClientObject.Set("createSchema", func(call sobek.FunctionCall) sobek.Value {
147147
if len(call.Arguments) == 0 {
148148
common.Throw(runtime, ErrNotEnoughArguments)
149149
}
@@ -170,7 +170,7 @@ func (k *Kafka) schemaRegistryClientClass(call goja.ConstructorCall) *goja.Objec
170170
}
171171

172172
var subjectNameConfig *SubjectNameConfig
173-
err = schemaRegistryClientObject.Set("getSubjectName", func(call goja.FunctionCall) goja.Value {
173+
err = schemaRegistryClientObject.Set("getSubjectName", func(call sobek.FunctionCall) sobek.Value {
174174
if len(call.Arguments) == 0 {
175175
common.Throw(runtime, ErrNotEnoughArguments)
176176
}
@@ -191,7 +191,7 @@ func (k *Kafka) schemaRegistryClientClass(call goja.ConstructorCall) *goja.Objec
191191
common.Throw(runtime, err)
192192
}
193193

194-
err = schemaRegistryClientObject.Set("serialize", func(call goja.FunctionCall) goja.Value {
194+
err = schemaRegistryClientObject.Set("serialize", func(call sobek.FunctionCall) sobek.Value {
195195
if len(call.Arguments) == 0 {
196196
common.Throw(runtime, ErrNotEnoughArguments)
197197
}
@@ -213,7 +213,7 @@ func (k *Kafka) schemaRegistryClientClass(call goja.ConstructorCall) *goja.Objec
213213
common.Throw(runtime, err)
214214
}
215215

216-
err = schemaRegistryClientObject.Set("deserialize", func(call goja.FunctionCall) goja.Value {
216+
err = schemaRegistryClientObject.Set("deserialize", func(call sobek.FunctionCall) sobek.Value {
217217
if len(call.Arguments) == 0 {
218218
common.Throw(runtime, ErrNotEnoughArguments)
219219
}

0 commit comments

Comments
 (0)