Skip to content
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

add debugg logs #104

Merged
merged 7 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("fetching 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("fetching binary", "build service URL: ", opts.BuildServiceURL)

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

slog.Debug("binary fetched", "Path: ", binary.Path, "dependencies", deps.String(), "checksum", binary.Checksum)

return binary.Path, nil
}
Loading