Skip to content

Commit

Permalink
Fix unobserved parent metric when its submetric is in a threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- committed May 6, 2022
1 parent 44cc995 commit 7ab41a1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions cmd/integration_test.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 7ab41a1

Please sign in to comment.