From 443528d4c8a7d95a35167de17261a10bf27d5e5a Mon Sep 17 00:00:00 2001 From: Oleg Bespalov Date: Thu, 4 Apr 2024 14:10:39 +0200 Subject: [PATCH] Completely remove experimental GRPC module (#3530) * Completely remove the experimental GRPC module --------- Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com> --- js/jsmodules.go | 21 ++++++++++++++++++++- js/modules/k6/grpc/grpc.go | 21 +-------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/js/jsmodules.go b/js/jsmodules.go index ea0da9a58c7..dffeb1f4f78 100644 --- a/js/jsmodules.go +++ b/js/jsmodules.go @@ -1,9 +1,11 @@ package js import ( + "errors" "sync" "go.k6.io/k6/ext" + "go.k6.io/k6/js/common" "go.k6.io/k6/js/modules" "go.k6.io/k6/js/modules/k6" "go.k6.io/k6/js/modules/k6/crypto" @@ -38,7 +40,6 @@ func getInternalJSModules() map[string]interface{} { "k6/experimental/redis": redis.New(), "k6/experimental/webcrypto": webcrypto.New(), "k6/experimental/websockets": &expws.RootModule{}, - "k6/experimental/grpc": grpc.NewExperimental(), "k6/experimental/timers": newWarnExperimentalModule(timers.New(), "k6/experimental/timers is now part of the k6 core, please change your imports to use k6/timers instead."+ " The k6/experimental/timers will be removed in k6 v0.52.0"), @@ -50,6 +51,10 @@ func getInternalJSModules() map[string]interface{} { "k6/http": http.New(), "k6/metrics": metrics.New(), "k6/ws": ws.New(), + "k6/experimental/grpc": newRemovedModule( + "k6/experimental/grpc has been graduated, please use k6/net/grpc instead." + + " See https://grafana.com/docs/k6/latest/javascript-api/k6-net-grpc/ for more information.", + ), } } @@ -83,3 +88,17 @@ func (w *warnExperimentalModule) NewModuleInstance(vu modules.VU) modules.Instan w.once.Do(func() { vu.InitEnv().Logger.Warn(w.msg) }) return w.base.NewModuleInstance(vu) } + +type removedModule struct { + errMsg string +} + +func newRemovedModule(errMsg string) modules.Module { + return &removedModule{errMsg: errMsg} +} + +func (rm *removedModule) NewModuleInstance(vu modules.VU) modules.Instance { + common.Throw(vu.Runtime(), errors.New(rm.errMsg)) + + return nil +} diff --git a/js/modules/k6/grpc/grpc.go b/js/modules/k6/grpc/grpc.go index b4d283347e4..8d9c4227509 100644 --- a/js/modules/k6/grpc/grpc.go +++ b/js/modules/k6/grpc/grpc.go @@ -4,7 +4,6 @@ package grpc import ( "errors" "fmt" - "sync" "github.com/dop251/goja" "github.com/mstoykov/k6-taskqueue-lib/taskqueue" @@ -16,9 +15,7 @@ import ( type ( // RootModule is the global module instance that will create module // instances for each VU. - RootModule struct { - warnAboutExperimental *sync.Once - } + RootModule struct{} // ModuleInstance represents an instance of the GRPC module for every VU. ModuleInstance struct { @@ -38,13 +35,6 @@ 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 (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance { @@ -53,15 +43,6 @@ func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance { 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{}),