Skip to content

Commit

Permalink
add debugg logs
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <[email protected]>
  • Loading branch information
pablochacin committed Feb 13, 2025
1 parent ae0bb16 commit 96df1c2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
37 changes: 36 additions & 1 deletion analyze.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package k6exec

import (
"log/slog"
"os"
"strings"

"github.com/grafana/k6deps"
)

func analyze(args []string, opts *Options) (k6deps.Dependencies, error) {
return k6deps.Analyze(newDepsOptions(args, opts))
depsOpts := newDepsOptions(args, opts)

// we call Analyze before logging because it will return the name of the manifest, in any
deps, err := k6deps.Analyze(depsOpts)

slog.Debug("analyzing sources", depsOptsAttrs(depsOpts)...)

if err == nil && len(deps) > 0 {
slog.Debug("found dependencies", "deps", deps.String())
}

return deps, err
}

func newDepsOptions(args []string, opts *Options) *k6deps.Options {
Expand Down Expand Up @@ -58,3 +70,26 @@ func scriptArg(args []string) (string, bool) {

return last, true
}

func depsOptsAttrs(opts *k6deps.Options) []any {
attrs := []any{}

if opts.Manifest.Name != "" {
attrs = append(attrs, "Manifest", opts.Manifest.Name)
}

if opts.Archive.Name != "" {
attrs = append(attrs, "Archive", opts.Archive.Name)
}

// ignore script if archive is present
if opts.Archive.Name == "" && opts.Script.Name != "" {
attrs = append(attrs, "Script", opts.Script.Name)
}

if opts.Env.Name != "" {
attrs = append(attrs, "Env", opts.Env.Name)
}

return attrs
}
1 change: 1 addition & 0 deletions cmd/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (s *state) runE(_ *cobra.Command, _ []string) error {
}
}()

slog.Debug("running", "k6 binary", s.cmd.Path, "args", s.cmd.Args[1:])
err = s.cmd.Run()

return err
Expand Down
6 changes: 6 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package k6exec

import (
"context"
"log/slog"
"os/exec"
)

Expand All @@ -17,11 +18,16 @@ func Command(ctx context.Context, args []string, opts *Options) (*exec.Cmd, func
return nil, nil, err
}

slog.Info("provisioning k6 binary")

exe, err := provision(ctx, deps, opts)
if err != nil {
return nil, nil, err
}

// FIXME: can we leak sensitive information in arguments here? (pablochacin)
slog.Debug("running k6", "path", exe, "args", args)

cmd := exec.CommandContext(ctx, exe, args...) //nolint:gosec

// TODO: once k6provider implements the cleanup of binary return the proper cleanup function (pablochacin)
Expand Down
5 changes: 5 additions & 0 deletions provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package k6exec

import (
"context"
"log/slog"

"github.com/grafana/k6deps"
"github.com/grafana/k6provider"
Expand All @@ -20,10 +21,14 @@ func provision(ctx context.Context, deps k6deps.Dependencies, opts *Options) (st
return "", err
}

slog.Debug("downloading binary", "build service URL: ", opts.BuildServiceURL)

binary, err := provider.GetBinary(ctx, deps)
if err != nil {
return "", err
}

slog.Debug("binary downloaded", "Path: ", binary.Path, "dependencies", deps.String())

return binary.Path, nil
}

0 comments on commit 96df1c2

Please sign in to comment.