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

Validate thresholds at init #2463

Merged
merged 3 commits into from
Apr 12, 2022
Merged

Conversation

oleiade
Copy link
Member

@oleiade oleiade commented Mar 25, 2022

What this PR does

We merged Go-based thresholds parsing in v0.37.0. This Pull Request builds upon that and implements thresholds validation at init. As of this PR, unless the --no-thresholds flag is passed, thresholds will be checked before the execution of k6 commands. Specifically, if a threshold applies to a non-existing metric, or if it uses an aggregation method that's not supported by the former, k6 will immediately produce an error; the execution won't even start.

This addresses #2330 to the extent of the internally agreed upon scope.

@oleiade oleiade requested review from mstoykov and codebien and removed request for na-- March 25, 2022 11:06
@oleiade oleiade added this to the v0.38.0 milestone Mar 25, 2022
@oleiade oleiade self-assigned this Mar 25, 2022
@oleiade oleiade force-pushed the refactor/move_stats_to_metrics branch 8 times, most recently from 8ea9ce4 to 766afc4 Compare March 29, 2022 16:27
Base automatically changed from refactor/move_stats_to_metrics to master March 30, 2022 11:43
@oleiade oleiade force-pushed the feature/2330_validate_thresholds_at_init branch 2 times, most recently from 8950690 to 1605cfa Compare April 1, 2022 16:28
metrics/metric.go Outdated Show resolved Hide resolved
@oleiade oleiade force-pushed the feature/2330_validate_thresholds_at_init branch 4 times, most recently from a2010e7 to b5192d0 Compare April 6, 2022 08:16
@mstoykov
Copy link
Contributor

mstoykov commented Apr 6, 2022

The PR descriptions still talks about submetric checking

Specifically, if a threshold applies to a non-existing metric, or submetric (including groups), or if it uses an aggregation method that's not supported by the former, k6 will immediately produce an error; the execution won't even start.

@oleiade
Copy link
Member Author

oleiade commented Apr 6, 2022

@mstoykov Good catch 👍🏻 Edited out 🙇🏻

@oleiade oleiade force-pushed the feature/2330_validate_thresholds_at_init branch from b5192d0 to 052e2d4 Compare April 6, 2022 08:42
@oleiade
Copy link
Member Author

oleiade commented Apr 6, 2022

For your information: I've updated the code of the ParseMetricName function to cater for the cases where tags definition curly braces are either unmatched, or in the wrong order 👍🏻

cmd/archive_test.go Show resolved Hide resolved
cmd/run_test.go Show resolved Hide resolved
metrics/metric_test.go Show resolved Hide resolved
metrics/thresholds.go Show resolved Hide resolved
@mstoykov
Copy link
Contributor

mstoykov commented Apr 6, 2022

As a general nitpick: I think you are adding why too many assert/require custom messages which quickly add up to the size of each test, but ... I would argue most of them (definitely not all) have very little to add to the readability of the test. And the rare cases the test fail I would argue will require someone to go read the code either way.

And in that later case, each assert/require not being on 4 lines will be more beneficial IMO.

@oleiade oleiade force-pushed the feature/2330_validate_thresholds_at_init branch 2 times, most recently from 46e8a7b to 43e29c1 Compare April 6, 2022 11:31
olegbespalov
olegbespalov previously approved these changes Apr 11, 2022
Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

metrics/thresholds_parser.go Outdated Show resolved Hide resolved
metrics/metric.go Outdated Show resolved Hide resolved
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great comments, and for making errors with high dev experience for k6 users. 🙏

I left some comments, some of them could be applied in multiple places but I didn't spot all of them because I expect some could require some discussions before.

metrics/metric.go Outdated Show resolved Hide resolved
metrics/metric_type.go Outdated Show resolved Hide resolved
metrics/thresholds.go Outdated Show resolved Hide resolved
metrics/thresholds.go Show resolved Hide resolved
metrics/thresholds_parser.go Outdated Show resolved Hide resolved
metrics/thresholds_test.go Outdated Show resolved Hide resolved
metrics/thresholds_test.go Outdated Show resolved Hide resolved
@oleiade oleiade force-pushed the feature/2330_validate_thresholds_at_init branch 4 times, most recently from bc07116 to 0dc981a Compare April 11, 2022 13:11
@oleiade
Copy link
Member Author

oleiade commented Apr 11, 2022

@mstoykov I've removed most assert/require custom error messages indeed. I kept them in table tests where I do them, find them helpful in figuring out which tests are failing when they do.

@olegbespalov @codebien I've addressed your comments 👍🏻

Let me know if you have other comments and suggestions. Otherwise, I'll be looking forward to the approval 🚅 🎉

codebien
codebien previously approved these changes Apr 11, 2022
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👏 Just one minor thing

metrics/metric_test.go Outdated Show resolved Hide resolved
olegbespalov
olegbespalov previously approved these changes Apr 11, 2022
mstoykov
mstoykov previously approved these changes Apr 12, 2022
Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉 👏

@oleiade oleiade dismissed stale reviews from mstoykov, olegbespalov, and codebien via 924fcf7 April 12, 2022 08:38
@oleiade oleiade force-pushed the feature/2330_validate_thresholds_at_init branch from 0dc981a to 924fcf7 Compare April 12, 2022 08:38
The newly introduced ParseMetricName function takes a metric name
expression of the form `name{tag_key:value,...}` and splits into
its name, and tags.

This function proves useful when needing to address metrics, and their
submetrics.
The newly introduced Validate method ensures that for a given
collection of Thresholds, they apply to existing metrics/submetrics,
and apply methods that are supported by the former.
This commit ensures that impacted commands (run, archive, cloud)
validate thresholds before running.
@oleiade oleiade force-pushed the feature/2330_validate_thresholds_at_init branch from 924fcf7 to 130e61d Compare April 12, 2022 08:57
@oleiade oleiade merged commit 8298ee4 into master Apr 12, 2022
@oleiade oleiade deleted the feature/2330_validate_thresholds_at_init branch April 12, 2022 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants