Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit ab668f5

Browse files
authored
add debugg logs (#104)
add debugg logs Signed-off-by: Pablo Chacin <[email protected]>
1 parent ae0bb16 commit ab668f5

File tree

7 files changed

+63
-6
lines changed

7 files changed

+63
-6
lines changed

analyze.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
package k6exec
22

33
import (
4+
"log/slog"
45
"os"
56
"strings"
67

78
"github.com/grafana/k6deps"
89
)
910

1011
func analyze(args []string, opts *Options) (k6deps.Dependencies, error) {
11-
return k6deps.Analyze(newDepsOptions(args, opts))
12+
depsOpts := newDepsOptions(args, opts)
13+
14+
// we call Analyze before logging because it will return the name of the manifest, in any
15+
deps, err := k6deps.Analyze(depsOpts)
16+
17+
slog.Debug("analyzing sources", depsOptsAttrs(depsOpts)...)
18+
19+
if err == nil && len(deps) > 0 {
20+
slog.Debug("found dependencies", "deps", deps.String())
21+
}
22+
23+
return deps, err
1224
}
1325

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

5971
return last, true
6072
}
73+
74+
func depsOptsAttrs(opts *k6deps.Options) []any {
75+
attrs := []any{}
76+
77+
if opts.Manifest.Name != "" {
78+
attrs = append(attrs, "Manifest", opts.Manifest.Name)
79+
}
80+
81+
if opts.Archive.Name != "" {
82+
attrs = append(attrs, "Archive", opts.Archive.Name)
83+
}
84+
85+
// ignore script if archive is present
86+
if opts.Archive.Name == "" && opts.Script.Name != "" {
87+
attrs = append(attrs, "Script", opts.Script.Name)
88+
}
89+
90+
if opts.Env.Name != "" {
91+
attrs = append(attrs, "Env", opts.Env.Name)
92+
}
93+
94+
return attrs
95+
}

cmd/state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func (s *state) runE(_ *cobra.Command, _ []string) error {
142142
}
143143
}()
144144

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

147148
return err

cmd/state_internal_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import (
1414
"github.com/stretchr/testify/require"
1515
)
1616

17-
func Test_interal_state(t *testing.T) { //nolint:tparallel
18-
t.Parallel()
17+
func Test_interal_state(t *testing.T) {
18+
t.Setenv("K6_BUILD_SERVICE_URL", "")
19+
t.Setenv("K6_CLOUD_TOKEN", "")
1920

2021
env, err := testutils.NewTestEnv(testutils.TestEnvConfig{
2122
WorkDir: t.TempDir(),

command.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package k6exec
22

33
import (
44
"context"
5+
"log/slog"
56
"os/exec"
67
)
78

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

21+
slog.Info("fetching k6 binary")
22+
2023
exe, err := provision(ctx, deps, opts)
2124
if err != nil {
2225
return nil, nil, err
2326
}
2427

28+
// FIXME: can we leak sensitive information in arguments here? (pablochacin)
29+
slog.Debug("running k6", "path", exe, "args", args)
30+
2531
cmd := exec.CommandContext(ctx, exe, args...) //nolint:gosec
2632

2733
// TODO: once k6provider implements the cleanup of binary return the proper cleanup function (pablochacin)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/grafana/clireadme v0.1.0
77
github.com/grafana/k6build v0.5.4
88
github.com/grafana/k6deps v0.2.1
9+
github.com/grafana/k6provider v0.1.9
910
github.com/samber/slog-logrus/v2 v2.5.2
1011
github.com/sirupsen/logrus v1.9.3
1112
github.com/spf13/cobra v1.8.1
@@ -30,7 +31,6 @@ require (
3031
github.com/evanw/esbuild v0.24.2 // indirect
3132
github.com/grafana/k6foundry v0.3.1 // indirect
3233
github.com/grafana/k6pack v0.2.4 // indirect
33-
github.com/grafana/k6provider v0.1.7
3434
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3535
github.com/pmezard/go-difflib v1.0.0 // indirect
3636
github.com/samber/lo v1.47.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ github.com/grafana/k6foundry v0.3.1 h1:nv4BqlJfNXrVMk7ps7mlGiPgegR73ogTvisn1y0bY
2222
github.com/grafana/k6foundry v0.3.1/go.mod h1:4Hw0ll6ZsKN8f3cgp7I4N6EkhXafZ6CBC6fDJWkW7/Q=
2323
github.com/grafana/k6pack v0.2.4 h1:JzbaO/NnLBaM2Shbn59WynaGAYL+jMvnjsoj/VTr3es=
2424
github.com/grafana/k6pack v0.2.4/go.mod h1:JTG8lQRU4U4WNKkznSL6zYokviiFVIp1I9W7z7NmrLA=
25-
github.com/grafana/k6provider v0.1.7 h1:vBHzm80u7vAa2xIocxtq/rK4fy1d0kaVR9arrGNc1n0=
26-
github.com/grafana/k6provider v0.1.7/go.mod h1:Uvqmgg/16Dc4vm70EwRxx2teA9NMZtSPm1v9qnobtbY=
25+
github.com/grafana/k6provider v0.1.9 h1:N9yoauRIb4JtDPBB+z3mrIdFHvo5h7S6UA9pfKdjVZg=
26+
github.com/grafana/k6provider v0.1.9/go.mod h1:voN3IOPdqODBp7RGGawYeHNHTxdwYHb6LW/9dYtBtHw=
2727
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
2828
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
2929
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=

provision.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package k6exec
22

33
import (
44
"context"
5+
"log/slog"
6+
"strings"
57

68
"github.com/grafana/k6deps"
79
"github.com/grafana/k6provider"
@@ -20,10 +22,22 @@ func provision(ctx context.Context, deps k6deps.Dependencies, opts *Options) (st
2022
return "", err
2123
}
2224

25+
slog.Debug("fetching binary", "build service URL: ", opts.BuildServiceURL)
26+
2327
binary, err := provider.GetBinary(ctx, deps)
2428
if err != nil {
2529
return "", err
2630
}
2731

32+
// Cut the query string from the download URL to reduce noise in the logs
33+
downloadURL, _, _ := strings.Cut(binary.DownloadURL, "?")
34+
slog.Debug("binary fetched",
35+
"Path: ", binary.Path,
36+
"dependencies", deps.String(),
37+
"checksum", binary.Checksum,
38+
"cached", binary.Cached,
39+
"download URL", downloadURL,
40+
)
41+
2842
return binary.Path, nil
2943
}

0 commit comments

Comments
 (0)