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 12, 2025
1 parent ae0bb16 commit 518371b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
36 changes: 35 additions & 1 deletion analyze.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
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)

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

return deps, err
}

func newDepsOptions(args []string, opts *Options) *k6deps.Options {
Expand Down Expand Up @@ -58,3 +69,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
3 changes: 3 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,6 +21,8 @@ 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
Expand Down

0 comments on commit 518371b

Please sign in to comment.