diff --git a/js/jsmodules.go b/js/jsmodules.go index b5328b05ea5f..3e0b1e33b808 100644 --- a/js/jsmodules.go +++ b/js/jsmodules.go @@ -34,7 +34,7 @@ func getInternalJSModules() map[string]interface{} { "k6/experimental/redis": redis.New(), "k6/experimental/webcrypto": webcrypto.New(), "k6/experimental/websockets": &expws.RootModule{}, - "k6/experimental/grpc": grpc.New(), // TODO: make warning + "k6/experimental/grpc": grpc.NewExperimental(), "k6/experimental/timers": timers.New(), "k6/experimental/tracing": tracing.New(), "k6/experimental/browser": browser.New(), diff --git a/js/modules/k6/grpc/grpc.go b/js/modules/k6/grpc/grpc.go index fdf2a8f42ec4..b4d283347e44 100644 --- a/js/modules/k6/grpc/grpc.go +++ b/js/modules/k6/grpc/grpc.go @@ -4,6 +4,7 @@ package grpc import ( "errors" "fmt" + "sync" "github.com/dop251/goja" "github.com/mstoykov/k6-taskqueue-lib/taskqueue" @@ -15,7 +16,9 @@ import ( type ( // RootModule is the global module instance that will create module // instances for each VU. - RootModule struct{} + RootModule struct { + warnAboutExperimental *sync.Once + } // ModuleInstance represents an instance of the GRPC module for every VU. ModuleInstance struct { @@ -35,14 +38,30 @@ func New() *RootModule { return &RootModule{} } +// NewExperimental returns a pointer to a new RootModule instance. +func NewExperimental() *RootModule { + return &RootModule{ + warnAboutExperimental: &sync.Once{}, + } +} + // NewModuleInstance implements the modules.Module interface to return // a new instance for each VU. -func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance { +func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance { metrics, err := registerMetrics(vu.InitEnv().Registry) if err != nil { common.Throw(vu.Runtime(), fmt.Errorf("failed to register GRPC module metrics: %w", err)) } + if r.warnAboutExperimental != nil { + r.warnAboutExperimental.Do(func() { + vu.InitEnv().Logger.Warn( + "k6/experimental/grpc is now part of the k6 core, please change your imports to use k6/net/grpc instead." + + " The k6/experimental/grpc will be removed in k6 v0.51.0", + ) + }) + } + mi := &ModuleInstance{ vu: vu, exports: make(map[string]interface{}),