Skip to content

Commit

Permalink
Warning about experimental GRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbespalov committed Dec 5, 2023
1 parent f36f517 commit 890cd90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/jsmodules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
23 changes: 21 additions & 2 deletions js/modules/k6/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package grpc
import (
"errors"
"fmt"
"sync"

"github.com/dop251/goja"
"github.com/mstoykov/k6-taskqueue-lib/taskqueue"
Expand All @@ -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 {
Expand All @@ -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{}),
Expand Down

0 comments on commit 890cd90

Please sign in to comment.