Skip to content

Commit e7c2aee

Browse files
committed
Add a warning for thresholds on tags we'll make non-indexable
1 parent be4fcb8 commit e7c2aee

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

cmd/integration_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,42 @@ func TestSSLKEYLOGFILE(t *testing.T) {
282282
require.Regexp(t, "^CLIENT_[A-Z_]+ [0-9a-f]+ [0-9a-f]+\n", string(sslloglines))
283283
}
284284

285+
func TestThresholdDeprecationWarnings(t *testing.T) {
286+
t.Parallel()
287+
288+
// TODO: adjust this test after we actually make url, error, iter and vu non-indexable
289+
290+
ts := newGlobalTestState(t)
291+
ts.args = []string{"k6", "run", "--system-tags", "url,error,vu,iter", "-"}
292+
ts.stdIn = bytes.NewReader([]byte(`
293+
export const options = {
294+
thresholds: {
295+
'http_req_duration{url:https://test.k6.io}': ['p(95)<500', 'p(99)<1000'],
296+
'http_req_duration{error:foo}': ['p(99)<1000'],
297+
'iterations{vu:1,iter:0}': ['count == 1'],
298+
},
299+
};
300+
301+
export default function () { }`,
302+
))
303+
304+
newRootCommand(ts.globalState).execute()
305+
306+
logs := ts.loggerHook.Drain()
307+
assert.True(t, testutils.LogContains(logs, logrus.WarnLevel,
308+
"Thresholds like 'http_req_duration{url:https://test.k6.io}', based on the high-cardinality 'url' metric tag, are deprecated",
309+
))
310+
assert.True(t, testutils.LogContains(logs, logrus.WarnLevel,
311+
"Thresholds like 'http_req_duration{error:foo}', based on the high-cardinality 'error' metric tag, are deprecated",
312+
))
313+
assert.True(t, testutils.LogContains(logs, logrus.WarnLevel,
314+
"Thresholds like 'iterations{vu:1,iter:0}', based on the high-cardinality 'vu' metric tag, are deprecated",
315+
))
316+
assert.True(t, testutils.LogContains(logs, logrus.WarnLevel,
317+
"Thresholds like 'iterations{vu:1,iter:0}', based on the high-cardinality 'iter' metric tag, are deprecated",
318+
))
319+
}
320+
285321
// TODO: add a hell of a lot more integration tests, including some that spin up
286322
// a test HTTP server and actually check if k6 hits it
287323

metrics/engine/engine.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,41 @@ func (me *MetricsEngine) getThresholdMetricOrSubmetric(name string) (*metrics.Me
9090
if err != nil {
9191
return nil, err
9292
}
93+
94+
if sm.Metric.Observed {
95+
// Do not repeat warnings for the same sub-metrics
96+
return sm.Metric, nil
97+
}
98+
99+
// TODO: reword these from "will be deprecated" to "were deprecated" and
100+
// maybe make them errors, not warnings, when we introduce un-indexable tags
101+
102+
if _, ok := sm.Tags.Get("url"); ok {
103+
me.logger.Warnf("Thresholds like '%s', based on the high-cardinality 'url' metric tag, "+
104+
"are deprecated and will not be supported in future k6 releases. "+
105+
"To prevent breaking changes and reduce bugs, use the 'name' metric tag instead, see"+
106+
"URL grouping (https://k6.io/docs/using-k6/http-requests/#url-grouping) for more information.", name,
107+
)
108+
}
109+
110+
if _, ok := sm.Tags.Get("error"); ok {
111+
me.logger.Warnf("Thresholds like '%s', based on the high-cardinality 'error' metric tag, "+
112+
"are deprecated and will not be supported in future k6 releases. "+
113+
"To prevent breaking changes and reduce bugs, use the 'error_code' metric tag instead", name,
114+
)
115+
}
116+
if _, ok := sm.Tags.Get("vu"); ok {
117+
me.logger.Warnf("Thresholds like '%s', based on the high-cardinality 'vu' metric tag, "+
118+
"are deprecated and will not be supported in future k6 releases.", name,
119+
)
120+
}
121+
122+
if _, ok := sm.Tags.Get("iter"); ok {
123+
me.logger.Warnf("Thresholds like '%s', based on the high-cardinality 'iter' metric tag, "+
124+
"are deprecated and will not be supported in future k6 releases.", name,
125+
)
126+
}
127+
93128
return sm.Metric, nil
94129
}
95130

0 commit comments

Comments
 (0)