grafana / xk6

Build k6 with extensions
Apache License 2.0
184 stars 18 forks source link

xk6 cannot run k6 if there is a k6 directory #45

Open inancgumus opened 2 years ago

inancgumus commented 2 years ago

xk6 cannot run the k6 command if there is a k6 directory (or a non-executable file, I guess) in the extension folder: fork/exec ./k6: permission denied.

Reproduce:

Output:

2022/05/20 15:01:55 [INFO] Temporary folder: /Users/inanc/grafana/xk6-browser/buildenv_2022-05-20-1501.2156919550
2022/05/20 15:01:55 [INFO] Writing main module: /Users/inanc/grafana/xk6-browser/buildenv_2022-05-20-1501.2156919550/main.go
2022/05/20 15:01:55 [INFO] Initializing Go module
2022/05/20 15:01:55 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init k6 
go: creating new go.mod: module k6
go: to add module requirements and sums:
        go mod tidy
2022/05/20 15:01:55 [INFO] Replace github.com/grafana/xk6-browser => /Users/inanc/grafana/xk6-browser
2022/05/20 15:01:55 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod edit -replace github.com/grafana/xk6-browser=/Users/inanc/grafana/xk6-browser 
2022/05/20 15:01:55 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
go: finding module for package go.k6.io/k6/cmd
go: found go.k6.io/k6/cmd in go.k6.io/k6 v0.38.3
go: finding module for package github.com/nxadm/tail
go: found github.com/nxadm/tail in github.com/nxadm/tail v1.4.8
2022/05/20 15:01:56 [INFO] Pinning versions
2022/05/20 15:01:56 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod edit -require go.k6.io/k6@latest 
2022/05/20 15:01:56 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
2022/05/20 15:01:56 [INFO] Build environment ready
2022/05/20 15:01:56 [INFO] Building k6
2022/05/20 15:01:56 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
go: found github.com/grafana/xk6-browser in github.com/grafana/xk6-browser v0.0.0-00010101000000-000000000000
2022/05/20 15:01:56 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /Users/inanc/grafana/xk6-browser/k6 -ldflags -w -s -trimpath 
2022/05/20 15:01:57 [INFO] Build complete: ./k6
2022/05/20 15:01:57 [INFO] Cleaning up temporary folder: /Users/inanc/grafana/xk6-browser/buildenv_2022-05-20-1501.2156919550
2022/05/20 15:01:57 [INFO] Running [./k6 run -q examples/browser_args.js]

2022/05/20 15:01:57 [ERROR] fork/exec ./k6: permission denied
mstoykov commented 2 years ago

This seems like another facet of #3 to me :thinking:

I think that apart from printing a better and earlier warning there isn't much we can do for the other case.

For xk6 run I feel like that needs a lot of work. Currently, it won't reuse a directory which means the build takes ... a while, although in reality it should be instantaneous if there are no changes or very few ones.

So I feel more like xk6 run needs to either be deprecated and users to be told to replicate what xk6 does - which is pretty simple to do either way. Or we need spend some more time to make it less slow and as this issue shows ... broken.

I don't know how common k6 directory in extensions are though ... seems rare as only you and I have hit it and I hit really early on in a really "w/e I have experimental" directory.

inancgumus commented 2 years ago

Oh, I missed #3 🤦

Would it be better to document that there should not be a k6 directory or file in the same directory while running xk6?

Currently, it won't reuse a directory which means the build takes ... a while, although in reality, it should be instantaneous if there are no changes or very few ones.

Yup, this is another problem. Not a biggie but it makes developing with an extension slower.

I don't know how common k6 directory in extensions is though

We've created a package named k6 for communicating with the k6 core. We could have named it core too, but making it k6 kept it concise.

In the meantime, I found a dummy solution and it works for me for now:

Update (a better version—only for zsh, though):

kbr () {
  set -o err_return
  trap "unsetopt err_return && rm -f k6x" EXIT
  xk6 build --output k6x --with github.com/grafana/xk6-browser=.
  [[ -f ./k6x ]] && ./k6x run -q "$@"
}