Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unobserved parent metric when its submetric is in a threshold #2519

Merged
merged 1 commit into from May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmd/integration_test.go
Expand Up @@ -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`)
}
2 changes: 1 addition & 1 deletion metrics/engine/engine.go
Expand Up @@ -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)
}
}

Expand Down