8000 Binary provisioning/use loadsource by pablochacin · Pull Request #4811 · grafana/k6 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Binary provisioning/use loadsource #4811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: binary-provisioning/integrate-root-cmd
Choose a base branch
from

Conversation

pablochacin
Copy link
Contributor
@pablochacin pablochacin commented May 23, 2025

What?

Use the loadsource function for dependency analysis

Why?

Presently, binary provisioning uses its own logic for loading the input for dependency analysis. This logic has some shortcomings like not handling input for stdin or limiting the processing of scripts with spe 10000 cific extensions.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

Depens on #4801

Closes #4727
Closes #4696

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@pablochacin pablochacin changed the base branch from master to binary-provisioning/integrate-root-cmd May 23, 2025 07:47
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@pablochacin pablochacin force-pushed the binary-provisioning/use-loadsource branch from e6edf2e to 9066d48 Compare May 23, 2025 07:52
@pablochacin pablochacin marked this pull request as ready for review May 23, 2025 11:04
@pablochacin pablochacin requested a review from a team as a code owner May 23, 2025 11:04
@pablochacin pablochacin requested review from oleiade and codebien and removed request for a team May 23, 2025 11:04
Debug("The command did not receive an input script.")
return nil, errScriptNotFound
if len(args) < 1 {
return nil, fmt.Errorf("k6 needs at least one argument to load the test")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("k6 needs at least one argument to load the test")
return nil, fmt.Errorf("the invoked command needs a file path or pass the test via Stdin")

This message sounds too vague. What argument do we expect? I guess we can replace k6 with something clarifies better where is the issue. I suggested invoked command but probably there is some better.

@@ -277,37 +276,37 @@ func extractToken(gs *state.GlobalState) (string, error) {
// Presently, only the k6 input script or archive (if any) is passed to k6deps for scanning.
// TODO: if k6 receives the input from stdin, it is not used for scanning because we don't know
// if it is a script or an archive
func analyze(gs *state.GlobalState, args []string) (k6deps.Dependencies, error) {
func analyze(gs *state.GlobalState, _ *cobra.Command, args []string) (k6deps.Dependencies, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func analyze(gs *state.GlobalState, _ *cobra.Command, args []string) (k6deps.Dependencies, error) {
func analyze(gs *state.GlobalState, args []string) (k6deps.Dependencies, error) {

I don't like the fact we are passing Cobra primitives around. Is it really required to have this dependency? Can we break it in Go/k6 primitives and more scoped for the function?

Copy link
Contributor Author
@pablochacin pablochacin Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the problem is with using Cobra types, as we are within the execution of a Cobra command. Can you elaborate on what problems you see?

And, I'm not sure what you mean by "break it in Go/k6 primitives". Create abstractions around Cobra?

Debug("Test script provided by Stdin is not yet supported from Binary provisioning feature.")
return nil, errUnsupportedFeature
sourceRootPath := args[0]
gs.Logger.Debugf("Resolving and reading test '%s'...", sourceRootPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gs.Logger.Debugf("Resolving and reading test '%s'...", sourceRootPath)
gs.Logger.WithField("source", "sourceRootPath).Debug("Launcher is resolving and reading the test")

Now we have multiple components doing this reading operation, could be useful to explicit Who / Where the operation is executed.

gs.Logger.Debugf("Resolving and reading test '%s'...", sourceRootPath)
src, _, pwd, err := readSource(gs, sourceRootPath)
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, err
return nil, fmt.Errorf(err

We need to wrap this error and make it clear the error's path.

ts.CmdArgs = k6Args

// k6deps uses os package to access files. So we need to use it in the global state
ts.FS = afero.NewOsFs()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ts.FS = afero.NewOsFs()
ts.FS = fsext.NewMemMapFS()

Is the afero dependency really needed?

return nil, errUnsupportedFeature
sourceRootPath := args[0]
gs.Logger.Debugf("Resolving and reading test '%s'...", sourceRootPath)
src, _, pwd, err := readSource(gs, sourceRootPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the idea to have this function called twice. Can we move this function as early as possible to be good for the entire k6 program? Independently if Binary Provisioning is enabled or not. In this way, the part after can assume it is always already loaded.

I don't know if it is really possible, but I want to make sure that we thought about it and we have reasons if we have to call it twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will open another PR trying to address this particular issue as it probably will touch many places in the code inderectly.

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@oleiade
Copy link
Contributor
oleiade commented Jun 17, 2025

👀

Comment on lines 124 to 125
// is we are here, it is possible that the analyze function read the stdin to analyse it
// and restored the content into gs.Stdin, so we pass it to the command
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs a re-arrangement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you refer to, but the initial "is" should be "if".

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants
0