Skip to content

Commit

Permalink
very WIP implementation of #587 to enable getting test run id
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Feb 22, 2024
1 parent b5a6feb commit af1b5d5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
stopOutputs(err)
}()

conf.Outputs = outputManager.JSONConfig()
test.initRunner.SetOptions(conf.Options)

if !testRunState.RuntimeOptions.NoThresholds.Bool {
finalizeThresholds := metricsEngine.StartThresholdCalculations(
metricsIngester, runAbort, executionState.GetCurrentTestRunDuration,
Expand Down
5 changes: 5 additions & 0 deletions lib/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ type Options struct {

// Specify client IP ranges and/or CIDR from which VUs will make requests
LocalIPs types.NullIPPool `json:"-" envconfig:"K6_LOCAL_IPS"`

Outputs map[string]json.RawMessage `json:"outputs"`
}

// Apply returns the result of overwriting any fields with any that are set on the argument.
Expand Down Expand Up @@ -511,6 +513,9 @@ func (o Options) Apply(opts Options) Options {
if opts.DNS.Policy.Valid {
o.DNS.Policy = opts.DNS.Policy
}
if opts.Outputs != nil {
o.Outputs = opts.Outputs
}

return o
}
Expand Down
10 changes: 10 additions & 0 deletions output/cloud/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cloud

import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
Expand Down Expand Up @@ -186,6 +187,7 @@ func (out *Output) Start() error {
return err
}
out.testRunID = response.ReferenceID
out.config.PushRefID = null.StringFrom(out.testRunID)

if response.ConfigOverride != nil {
out.logger.WithFields(logrus.Fields{
Expand All @@ -208,6 +210,14 @@ func (out *Output) Start() error {
return nil
}

func (out *Output) JSONConfig() json.RawMessage {
res, err := json.Marshal(out.config)
if err != nil {
panic(err) // TODO FIX
}
return res
}

// Description returns the URL with the test run results.
func (out *Output) Description() string {
return fmt.Sprintf("cloud (%s)", cloudapi.URLForResults(out.testRunID, out.config))
Expand Down
13 changes: 13 additions & 0 deletions output/manager.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package output

import (
"encoding/json"
"sync"
"time"

Expand Down Expand Up @@ -82,6 +83,18 @@ func (om *Manager) Start(samplesChan chan metrics.SampleContainer) (wait func(),
return wait, finish, nil
}

func (om *Manager) JSONConfig() map[string]json.RawMessage {
result := make(map[string]json.RawMessage)
for _, output := range om.outputs {
o, ok := output.(interface{ JSONConfig() json.RawMessage })
if !ok {
continue
}
result["cloud"] = o.JSONConfig() // TODO fix
}
return result
}

// startOutputs spins up all configured outputs. If some output fails to start,
// it stops the already started ones. This may take some time, since some
// outputs make initial network requests to set up whatever remote services are
Expand Down

0 comments on commit af1b5d5

Please sign in to comment.