Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions internal/adhoc/adhoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ func (timeoutBackoff) Duration() time.Duration {

func (timeoutBackoff) Reset() {}

type grpcTestConn struct {
}
type grpcTestConn struct{}

func (grpcTestConn) GetState() connectivity.State {
return connectivity.Ready
Expand Down Expand Up @@ -708,3 +707,7 @@ func (r *testK6Runner) WithLogger(logger *zerolog.Logger) k6runner.Runner {
func (r *testK6Runner) Run(ctx context.Context, script k6runner.Script, secretStore k6runner.SecretStore) (*k6runner.RunResponse, error) {
return &k6runner.RunResponse{}, nil
}

func (*testK6Runner) Versions(_ context.Context) <-chan []string {
return nil // Blocks forever if read.
}
4 changes: 4 additions & 0 deletions internal/checks/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ func (noopRunner) Run(ctx context.Context, script k6runner.Script, secretStore k
return &k6runner.RunResponse{}, nil
}

func (noopRunner) Versions(_ context.Context) <-chan []string {
return nil // Blocks forever if read.
}

type testBackoff time.Duration

func (b *testBackoff) Reset() {
Expand Down
7 changes: 7 additions & 0 deletions internal/k6runner/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ func (r HttpRunner) request(ctx context.Context, script Script, secretStore Secr
return &response, nil
}

func (r HttpRunner) Versions(_ context.Context) <-chan []string {
ch := make(chan []string)
close(ch)

return ch
}

type HTTPMetrics struct {
Requests *prometheus.CounterVec
RequestsPerRun *prometheus.HistogramVec
Expand Down
7 changes: 7 additions & 0 deletions internal/k6runner/k6runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ func (ci *CheckInfo) MarshalZerologObject(e *zerolog.Event) {
var ErrNoTimeout = errors.New("check has no timeout")

type Runner interface {
// WithLogger returns a copy of the runner configured to use the specified logger.
WithLogger(logger *zerolog.Logger) Runner
// Run makes the runner run the script.
Run(ctx context.Context, script Script, secretStore SecretStore) (*RunResponse, error)
// Versions returns a channel to which the list of versions supported by this runner are pushed. Runner
// implementations that have a predictable list of versions over time may push a single list to the channel and then
// close it, while others may push lists of versions regularly as a result of polling a decoupled system.
// Cancelling the context stops this background polling, if any.
Versions(context.Context) <-chan []string
}

type RunnerOpts struct {
Expand Down
4 changes: 4 additions & 0 deletions internal/k6runner/k6runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func (r *testRunner) WithLogger(logger *zerolog.Logger) Runner {
return r
}

func (*testRunner) Versions(_ context.Context) <-chan []string {
return nil // Blocks forever if read.
}

func TestTextToRegistry(t *testing.T) {
data := testhelper.MustReadFile(t, "testdata/test.out")

Expand Down
34 changes: 34 additions & 0 deletions internal/k6runner/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,40 @@ func (r Local) Run(ctx context.Context, script Script, secretStore SecretStore)
return rr, nil
}

func (r Local) Versions(ctx context.Context) <-chan []string {
ch := make(chan []string)

go func() {
// The list of k6 versions in the local repository is static: We will push to the channel at most once.
defer close(ch)

entries, err := r.repository.Entries()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this error on a transient issue? Should we consider retrying in case of error?

if err != nil {
r.logger.Error().
Err(err).
Str("k6Repository", r.repository.Root).
Str("k6RepositoryOverride", r.repository.Override).
Msg("Could not retrieve k6 versions from repository")

return
}

versions := make([]string, 0, len(entries))
for _, e := range entries {
versions = append(versions, e.Version.String())
}

select {
case <-ctx.Done():
r.logger.Error().Err(err).Msg("Aborting k6 version reporting")

case ch <- versions:
}
}()

return ch
}

func (r Local) buildK6Args(script Script, metricsFn, logsFn, scriptFn, configFile string) ([]string, error) {
args := []string{
"run",
Expand Down
4 changes: 4 additions & 0 deletions internal/prober/browser/browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ func (noopRunner) WithLogger(logger *zerolog.Logger) k6runner.Runner {
func (noopRunner) Run(ctx context.Context, script k6runner.Script, secretStore k6runner.SecretStore) (*k6runner.RunResponse, error) {
return &k6runner.RunResponse{}, nil
}

func (noopRunner) Versions(_ context.Context) <-chan []string {
return nil // Blocks forever if read.
}
4 changes: 4 additions & 0 deletions internal/prober/multihttp/multihttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,7 @@ func (noopRunner) WithLogger(logger *zerolog.Logger) k6runner.Runner {
func (noopRunner) Run(ctx context.Context, script k6runner.Script, secretStore k6runner.SecretStore) (*k6runner.RunResponse, error) {
return &k6runner.RunResponse{}, nil
}

func (noopRunner) Versions(_ context.Context) <-chan []string {
return nil // Blocks forever if read.
}
4 changes: 4 additions & 0 deletions internal/prober/scripted/scripted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (noopRunner) Run(ctx context.Context, script k6runner.Script, secretStore k
return &k6runner.RunResponse{}, nil
}

func (noopRunner) Versions(_ context.Context) <-chan []string {
return nil // Blocks forever if read.
}

func testContext(t *testing.T) (context.Context, func()) {
if deadline, ok := t.Deadline(); ok {
return context.WithDeadline(context.Background(), deadline)
Expand Down
4 changes: 4 additions & 0 deletions internal/scraper/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,10 @@ func (r *testRunner) WithLogger(logger *zerolog.Logger) k6runner.Runner {
return r
}

func (*testRunner) Versions(_ context.Context) <-chan []string {
return nil // Blocks forever if read.
}

type testCounter struct {
count atomic.Int32
}
Expand Down
Loading