From aa30c382db191f19fcfe4b2879d6d25807d711a5 Mon Sep 17 00:00:00 2001 From: Nedyalko Andreev Date: Fri, 6 May 2022 15:36:55 +0300 Subject: [PATCH] Fix unobserved parent metric when its submetric is in a threshold --- cmd/integration_test.go | 31 +++++++++++++++++++++++++++++++ metrics/engine/engine.go | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cmd/integration_test.go b/cmd/integration_test.go index 90c9405ba63..d5b845d1a4d 100644 --- a/cmd/integration_test.go +++ b/cmd/integration_test.go @@ -311,3 +311,34 @@ func TestExecutionTestOptionsDefaultValues(t *testing.T) { 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}` assert.JSONEq(t, expected, loglines[0].Message) } + +func TestSubMetricThresholdNoData(t *testing.T) { + t.Parallel() + script := ` + import { Counter } from 'k6/metrics'; + + const counter1 = new Counter("one"); + const counter2 = new Counter("two"); + + export const options = { + thresholds: { + 'one{tag:xyz}': [], + }, + }; + + export default function () { + counter2.add(42); + } + ` + ts := newGlobalTestState(t) + require.NoError(t, afero.WriteFile(ts.fs, filepath.Join(ts.cwd, "test.js"), []byte(script), 0o644)) + ts.args = []string{"k6", "run", "--quiet", "test.js"} + + newRootCommand(ts.globalState).execute() + + require.Len(t, ts.loggerHook.Drain(), 0) + require.Contains(t, ts.stdOut.String(), ` + one..................: 0 0/s + { tag:xyz }........: 0 0/s + two..................: 42`) +} diff --git a/metrics/engine/engine.go b/metrics/engine/engine.go index 3c64e11b074..45833bdf05b 100644 --- a/metrics/engine/engine.go +++ b/metrics/engine/engine.go @@ -123,7 +123,7 @@ func (me *MetricsEngine) initSubMetricsAndThresholds() error { // even if they don't have any metric samples during the test run me.markObserved(metric) if metric.Sub != nil { - me.markObserved(metric.Sub.Metric) + me.markObserved(metric.Sub.Parent) } }