From 518371b2f761b7e337db996678957793eecdb4ea Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Wed, 12 Feb 2025 21:07:52 +0100 Subject: [PATCH] add debugg logs Signed-off-by: Pablo Chacin --- analyze.go | 36 +++++++++++++++++++++++++++++++++++- cmd/state.go | 1 + provision.go | 3 +++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/analyze.go b/analyze.go index fb22b3e..7aa7f52 100644 --- a/analyze.go +++ b/analyze.go @@ -1,6 +1,7 @@ package k6exec import ( + "log/slog" "os" "strings" @@ -8,7 +9,17 @@ import ( ) 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 { @@ -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 +} diff --git a/cmd/state.go b/cmd/state.go index dca6e24..b58ad5f 100644 --- a/cmd/state.go +++ b/cmd/state.go @@ -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 diff --git a/provision.go b/provision.go index 49afda6..2e9d84b 100644 --- a/provision.go +++ b/provision.go @@ -2,6 +2,7 @@ package k6exec import ( "context" + "log/slog" "github.com/grafana/k6deps" "github.com/grafana/k6provider" @@ -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