Skip to content

Commit

Permalink
Make handleSummary func timeout configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Johnson <alex.kattathra.johnson@gmail.com>
  • Loading branch information
alex-kattathra-johnson committed Oct 3, 2024
1 parent baba871 commit e5db7b9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 23 deletions.
3 changes: 3 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ func applyDefault(conf Config) Config {
if !conf.TeardownTimeout.Valid {
conf.TeardownTimeout.Duration = types.Duration(60 * time.Second)
}
if !conf.HandleSummaryTimeout.Valid {
conf.HandleSummaryTimeout.Duration = types.Duration(2 * time.Minute)
}
return conf
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func TestExecutionTestOptionsDefaultValues(t *testing.T) {
loglines := ts.LoggerHook.Drain()
require.Len(t, loglines, 1)

expected := `{"paused":null,"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpDebug":null,"insecureSkipTLSVerify":null,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"throw":null,"thresholds":null,"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg", "min", "med", "max", "p(90)", "p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"scenarios":{"default":{"vus":null,"iterations":1,"executor":"shared-iterations","maxDuration":null,"startTime":null,"env":null,"tags":null,"gracefulStop":null,"exec":null}},"localIPs":null}`
expected := `{"paused":null,"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpDebug":null,"insecureSkipTLSVerify":null,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"throw":null,"thresholds":null,"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg", "min", "med", "max", "p(90)", "p(95)"],"summaryTimeUnit":null,"handleSummaryTimeout":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"scenarios":{"default":{"vus":null,"iterations":1,"executor":"shared-iterations","maxDuration":null,"startTime":null,"env":null,"tags":null,"gracefulStop":null,"exec":null}},"localIPs":null}`
assert.JSONEq(t, expected, loglines[0].Message)
}

Expand Down
11 changes: 6 additions & 5 deletions execution/scheduler_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,11 +1195,12 @@ func TestRealTimeAndSetupTeardownMetrics(t *testing.T) {
require.NoError(t, err)

options, err := executor.DeriveScenariosFromShortcuts(runner.GetOptions().Apply(lib.Options{
Iterations: null.IntFrom(2),
VUs: null.IntFrom(1),
SystemTags: &metrics.DefaultSystemTagSet,
SetupTimeout: types.NullDurationFrom(4 * time.Second),
TeardownTimeout: types.NullDurationFrom(4 * time.Second),
Iterations: null.IntFrom(2),
VUs: null.IntFrom(1),
SystemTags: &metrics.DefaultSystemTagSet,
SetupTimeout: types.NullDurationFrom(4 * time.Second),
TeardownTimeout: types.NullDurationFrom(4 * time.Second),
HandleSummaryTimeout: types.NullDurationFrom(4 * time.Second),
}), nil)
require.NoError(t, err)

Expand Down
7 changes: 4 additions & 3 deletions js/modules/k6/execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestAbortTest(t *testing.T) { //nolint:tparallel
func TestOptionsTestFull(t *testing.T) {
t.Parallel()

expected := `{"paused":true,"scenarios":{"const-vus":{"executor":"constant-vus","options":{"browser":{"someOption":true}},"startTime":"10s","gracefulStop":"30s","env":{"FOO":"bar"},"exec":"default","tags":{"tagkey":"tagvalue"},"vus":50,"duration":"10m0s"}},"executionSegment":"0:1/4","executionSegmentSequence":"0,1/4,1/2,1","noSetup":true,"setupTimeout":"1m0s","noTeardown":true,"teardownTimeout":"5m0s","rps":100,"dns":{"ttl":"1m","select":"roundRobin","policy":"any"},"maxRedirects":3,"userAgent":"k6-user-agent","batch":15,"batchPerHost":5,"httpDebug":"full","insecureSkipTLSVerify":true,"tlsCipherSuites":["TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"],"tlsVersion":{"min":"tls1.2","max":"tls1.3"},"tlsAuth":[{"domains":["example.com"],"cert":"mycert.pem","key":"mycert-key.pem","password":"mypwd"}],"throw":true,"thresholds":{"http_req_duration":[{"threshold":"rate>0.01","abortOnFail":true,"delayAbortEval":"10s"}]},"blacklistIPs":["192.0.2.0/24"],"blockHostnames":["test.k6.io","*.example.com"],"hosts":{"test.k6.io":"1.2.3.4:8443"},"noConnectionReuse":true,"noVUConnectionReuse":true,"minIterationDuration":"10s","ext":{"ext-one":{"rawkey":"rawvalue"}},"summaryTrendStats":["avg","min","max"],"summaryTimeUnit":"ms","systemTags":["iter","vu"],"tags":null,"metricSamplesBufferSize":8,"noCookiesReset":true,"discardResponseBodies":true,"consoleOutput":"loadtest.log","tags":{"runtag-key":"runtag-value"},"localIPs":"192.168.20.12-192.168.20.15,192.168.10.0/27"}`
expected := `{"paused":true,"scenarios":{"const-vus":{"executor":"constant-vus","options":{"browser":{"someOption":true}},"startTime":"10s","gracefulStop":"30s","env":{"FOO":"bar"},"exec":"default","tags":{"tagkey":"tagvalue"},"vus":50,"duration":"10m0s"}},"executionSegment":"0:1/4","executionSegmentSequence":"0,1/4,1/2,1","noSetup":true,"setupTimeout":"1m0s","noTeardown":true,"teardownTimeout":"5m0s","rps":100,"dns":{"ttl":"1m","select":"roundRobin","policy":"any"},"maxRedirects":3,"userAgent":"k6-user-agent","batch":15,"batchPerHost":5,"httpDebug":"full","insecureSkipTLSVerify":true,"tlsCipherSuites":["TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"],"tlsVersion":{"min":"tls1.2","max":"tls1.3"},"tlsAuth":[{"domains":["example.com"],"cert":"mycert.pem","key":"mycert-key.pem","password":"mypwd"}],"throw":true,"thresholds":{"http_req_duration":[{"threshold":"rate>0.01","abortOnFail":true,"delayAbortEval":"10s"}]},"blacklistIPs":["192.0.2.0/24"],"blockHostnames":["test.k6.io","*.example.com"],"hosts":{"test.k6.io":"1.2.3.4:8443"},"noConnectionReuse":true,"noVUConnectionReuse":true,"minIterationDuration":"10s","ext":{"ext-one":{"rawkey":"rawvalue"}},"summaryTrendStats":["avg","min","max"],"summaryTimeUnit":"ms","handleSummaryTimeout":"2m0s","systemTags":["iter","vu"],"tags":null,"metricSamplesBufferSize":8,"noCookiesReset":true,"discardResponseBodies":true,"consoleOutput":"loadtest.log","tags":{"runtag-key":"runtag-value"},"localIPs":"192.168.20.12-192.168.20.15,192.168.10.0/27"}`

var (
rt = sobek.New()
Expand Down Expand Up @@ -343,8 +343,9 @@ func TestOptionsTestFull(t *testing.T) {
External: map[string]json.RawMessage{
"ext-one": json.RawMessage(`{"rawkey":"rawvalue"}`),
},
SummaryTrendStats: []string{"avg", "min", "max"},
SummaryTimeUnit: null.StringFrom("ms"),
SummaryTrendStats: []string{"avg", "min", "max"},
SummaryTimeUnit: null.StringFrom("ms"),
HandleSummaryTimeout: types.NullDurationFrom(2 * time.Minute),
SystemTags: func() *metrics.SystemTagSet {
sysm := metrics.SystemTagSet(metrics.TagIter | metrics.TagVU)
return &sysm
Expand Down
13 changes: 7 additions & 6 deletions js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ func newTestCase(t testing.TB) *httpTestCase {
logger.AddHook(hook)

options := lib.Options{
MaxRedirects: null.IntFrom(10),
UserAgent: null.StringFrom("TestUserAgent"),
Throw: null.BoolFrom(true),
SystemTags: &metrics.DefaultSystemTagSet,
Batch: null.IntFrom(20),
BatchPerHost: null.IntFrom(20),
MaxRedirects: null.IntFrom(10),
UserAgent: null.StringFrom("TestUserAgent"),
Throw: null.BoolFrom(true),
SystemTags: &metrics.DefaultSystemTagSet,
Batch: null.IntFrom(20),
BatchPerHost: null.IntFrom(20),
HandleSummaryTimeout: types.NullDurationFrom(2 * time.Minute),
// HTTPDebug: null.StringFrom("full"),
}
samples := make(chan metrics.SampleContainer, 1000)
Expand Down
2 changes: 1 addition & 1 deletion js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func (r *Runner) getTimeoutFor(stage string) time.Duration {
case consts.TeardownFn:
return r.Bundle.Options.TeardownTimeout.TimeDuration()
case consts.HandleSummaryFn:
return 2 * time.Minute // TODO: make configurable
return r.Bundle.Options.HandleSummaryTimeout.TimeDuration()
}
return d
}
Expand Down
37 changes: 30 additions & 7 deletions js/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ func TestTextSummary(t *testing.T) {
runner, err := getSimpleRunner(
t, "/script.js",
fmt.Sprintf(`
exports.options = {summaryTrendStats: %s};
exports.options = {
summaryTrendStats: %s,
handleSummaryTimeout: '120s',
};
exports.default = function() {/* we don't run this, metrics are mocked */};
`, string(trendStats)),
lib.RuntimeOptions{CompatibilityMode: null.NewString("base", true)},
Expand Down Expand Up @@ -111,7 +114,12 @@ func TestTextSummaryWithSubMetrics(t *testing.T) {
runner, err := getSimpleRunner(
t,
"/script.js",
"exports.default = function() {/* we don't run this, metrics are mocked */};",
`
exports.options = {
handleSummaryTimeout: '120s',
};
exports.default = function() {/* we don't run this, metrics are mocked */};
`,
lib.RuntimeOptions{CompatibilityMode: null.NewString("base", true)},
)
require.NoError(t, err)
Expand Down Expand Up @@ -295,7 +303,10 @@ func TestOldJSONExport(t *testing.T) {
runner, err := getSimpleRunner(
t, "/script.js",
`
exports.options = {summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]};
exports.options = {
summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"],
handleSummaryTimeout: '120s',
};
exports.default = function() {/* we don't run this, metrics are mocked */};
`,
lib.RuntimeOptions{
Expand Down Expand Up @@ -561,7 +572,10 @@ func TestRawHandleSummaryData(t *testing.T) {
runner, err := getSimpleRunner(
t, "/script.js",
`
exports.options = {summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]};
exports.options = {
summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"],
handleSummaryTimeout: '120s',
};
exports.default = function() { /* we don't run this, metrics are mocked */ };
exports.handleSummary = function(data) {
return {'rawdata.json': JSON.stringify(data)};
Expand Down Expand Up @@ -598,7 +612,10 @@ func TestRawHandleSummaryDataWithSetupData(t *testing.T) {
runner, err := getSimpleRunner(
t, "/script.js",
`
exports.options = {summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]};
exports.options = {
summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"],
handleSummaryTimeout: '120s',
};
exports.default = function() { /* we don't run this, metrics are mocked */ };
exports.handleSummary = function(data) {
if(data.setup_data != 5) {
Expand All @@ -624,7 +641,10 @@ func TestRawHandleSummaryPromise(t *testing.T) {
runner, err := getSimpleRunner(
t, "/script.js",
`
exports.options = {summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]};
exports.options = {
summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"],
handleSummaryTimeout: '120s',
};
exports.default = function() { /* we don't run this, metrics are mocked */ };
exports.handleSummary = async function(data) {
return await Promise.resolve({'dataWithSetup.json': JSON.stringify(data)});
Expand Down Expand Up @@ -675,6 +695,9 @@ func TestExceptionInHandleSummaryFallsBackToTextSummary(t *testing.T) {
logger.AddHook(logHook)

runner, err := getSimpleRunner(t, "/script.js", `
exports.options = {
handleSummaryTimeout: '120s',
};
exports.default = function() {/* we don't run this, metrics are mocked */};
exports.handleSummary = function(data) {
throw new Error('intentional error');
Expand All @@ -698,6 +721,6 @@ func TestExceptionInHandleSummaryFallsBackToTextSummary(t *testing.T) {
assert.Equal(t, 1, len(logErrors))
errMsg, err := logErrors[0].String()
require.NoError(t, err)
assert.Contains(t, errMsg, "\"Error: intentional error\\n\\tat file:///script.js:4:11(3)\\n")
assert.Contains(t, errMsg, "\"Error: intentional error\\n\\tat file:///script.js:7:11(3)\\n")
assert.Equal(t, logErrors[0].Data, logrus.Fields{"hint": "script exception"})
}
6 changes: 6 additions & 0 deletions lib/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ type Options struct {
// Summary time unit for summary metrics (response times) in CLI output
SummaryTimeUnit null.String `json:"summaryTimeUnit" envconfig:"K6_SUMMARY_TIME_UNIT"`

// Timeout for the handleSummary function
HandleSummaryTimeout types.NullDuration `json:"handleSummaryTimeout" envconfig:"K6_HANDLE_SUMMARY_TIMEOUT"`

// Which system tags to include with metrics ("method", "vu" etc.)
// Use pointer for identifying whether user provide any tag or not.
SystemTags *metrics.SystemTagSet `json:"systemTags" envconfig:"K6_SYSTEM_TAGS"`
Expand Down Expand Up @@ -485,6 +488,9 @@ func (o Options) Apply(opts Options) Options {
if opts.SummaryTimeUnit.Valid {
o.SummaryTimeUnit = opts.SummaryTimeUnit
}
if opts.HandleSummaryTimeout.Valid {
o.HandleSummaryTimeout = opts.HandleSummaryTimeout
}
if opts.SystemTags != nil {
o.SystemTags = opts.SystemTags
}
Expand Down

0 comments on commit e5db7b9

Please sign in to comment.