-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Parse and validate thresholds before starting the execution #2330
Comments
This may be implicitly understood but probably still worth pointing out as a part of the scope - thresholds on metrics that don't exist should also be invalid. We've seen multiple cases where a typo in a metric or threshold name silently made someone's script useless, since its threshold would never trigger and signal a discrepancy in the SUT. |
I realized (or, rather, remembered) that there is a slight problem which will complicate the implementation of this feature... 😞 With plain .js test scripts, we will run the init context once to get the exported JS Lines 113 to 115 in 13b2372
However, with .tar archive bundles, we are not actually executing the init context even once, we're getting the
Or maybe some other solution? Maybe emit warnings if we have thresholds on unknown metrics, instead of errors? 🤔 🤷♂️ Not sure what the best and most user-friendly way to tackle this issue is, just wanted to explicitly mention it so we design and implement the solution with it in mind. |
Actually it does since #1040 - I also checked it manually ;) |
That doesn't necessarily solve the issue, given that we do some of the validation early on in the cloud process and based solely on the |
This commit makes some minor modifications to the `stats` package API. Namely, it makes `stats.token*` symbols public. It also makes `stats.Threshold.parsed` public. These changes are made in order to facilitate validation of thresholds from outside the `stats` package. Having access to both the parsed Threshold, and the aggregation methods symbols will allow comparing them and asserting their meaningfulness in a context where we have typed metrics available. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`. This function validates that any thresholds defined in the config apply to existing metrics, and use methods that are valid for the metrics they apply to. As a side effect, this commit adds both a `Get` and `Has` methods to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. Note that the `validateThresholdConfig` function makes the assumption that the passed in `metrics.Registry` has been loaded with builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit makes some minor modifications to the `stats` package API. Namely, it makes `stats.token*` symbols public. It also makes `stats.Threshold.parsed` public. These changes are made in order to facilitate validation of thresholds from outside the `stats` package. Having access to both the parsed Threshold, and the aggregation methods symbols will allow comparing them and asserting their meaningfulness in a context where we have typed metrics available. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`. This function validates that any thresholds defined in the config apply to existing metrics, and use methods that are valid for the metrics they apply to. As a side effect, this commit adds both a `Get` and `Has` methods to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. Note that the `validateThresholdConfig` function makes the assumption that the passed in `metrics.Registry` has been loaded with builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit makes some minor modifications to the `stats` package API. Namely, it makes `stats.token*` symbols public. It also makes `stats.Threshold.parsed` public. These changes are made in order to facilitate validation of thresholds from outside the `stats` package. Having access to both the parsed Threshold, and the aggregation methods symbols will allow comparing them and asserting their meaningfulness in a context where we have typed metrics available. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`. This function validates that any thresholds defined in the config apply to existing metrics, and use methods that are valid for the metrics they apply to. As a side effect, this commit adds both a `Get` and `Has` methods to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. Note that the `validateThresholdConfig` function makes the assumption that the passed in `metrics.Registry` has been loaded with builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit makes some minor modifications to the `stats` package API. Namely, it makes `stats.token*` symbols public. It also makes `stats.Threshold.parsed` public. These changes are made in order to facilitate validation of thresholds from outside the `stats` package. Having access to both the parsed Threshold, and the aggregation methods symbols will allow comparing them and asserting their meaningfulness in a context where we have typed metrics available. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`. This function validates that any thresholds defined in the config apply to existing metrics, and use methods that are valid for the metrics they apply to. As a side effect, this commit adds both a `Get` and `Has` methods to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. Note that the `validateThresholdConfig` function makes the assumption that the passed in `metrics.Registry` has been loaded with builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`. This function validates that any thresholds defined in the config apply to existing metrics, and use methods that are valid for the metrics they apply to. As a side effect, this commit adds both a `Get` and `Has` methods to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. Note that the `validateThresholdConfig` function makes the assumption that the passed in `metrics.Registry` has been loaded with builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`. This function validates that any thresholds defined in the config apply to existing metrics, and use methods that are valid for the metrics they apply to. As a side effect, this commit adds both a `Get` and `Has` methods to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. Note that the `validateThresholdConfig` function makes the assumption that the passed in `metrics.Registry` has been loaded with builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`. This function validates that any thresholds defined in the config apply to existing metrics, and use methods that are valid for the metrics they apply to. As a side effect, this commit adds both a `Get` and `Has` methods to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. Note that the `validateThresholdConfig` function makes the assumption that the passed in `metrics.Registry` has been loaded with builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit makes some minor modifications to the `stats` package API. Namely, it makes `stats.ThresholdExpression` and `stats.token*` symbols public. It also makes `stats.Threshold.parsed` public. These changes are made in order to facilitate validation of thresholds from outside the `stats` package. Having access to both the parsed Threshold, and the aggregation methods symbols will allow comparing them and asserting their meaningfulness in a context where we have typed metrics available. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`, and integrates it as part of the `validateConfig` operations. From now on, `validateConfig` takes a `metrics.Registry` as input, and validates that thresholds defined in the config apply to existing metrics, and use methods that are valid for the metric they apply to. As a side effect, this commit adds a `Get` method to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit makes some minor modifications to the `stats` package API. Namely, it makes `stats.ThresholdExpression` and `stats.token*` symbols public. It also makes `stats.Threshold.parsed` public. These changes are made in order to facilitate validation of thresholds from outside the `stats` package. Having access to both the parsed Threshold, and the aggregation methods symbols will allow comparing them and asserting their meaningfulness in a context where we have typed metrics available. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`, and integrates it as part of the `validateConfig` operations. From now on, `validateConfig` takes a `metrics.Registry` as input, and validates that thresholds defined in the config apply to existing metrics, and use methods that are valid for the metric they apply to. As a side effect, this commit adds a `Get` method to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`, and integrates it as part of the `validateConfig` operations. From now on, `validateConfig` takes a `metrics.Registry` as input, and validates that thresholds defined in the config apply to existing metrics, and use methods that are valid for the metric they apply to. As a side effect, this commit adds a `Get` method to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit makes some minor modifications to the `stats` package API. Namely, it makes `stats.ThresholdExpression` and `stats.token*` symbols public. It also makes `stats.Threshold.parsed` public. These changes are made in order to facilitate validation of thresholds from outside the `stats` package. Having access to both the parsed Threshold, and the aggregation methods symbols will allow comparing them and asserting their meaningfulness in a context where we have typed metrics available. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`, and integrates it as part of the `validateConfig` operations. From now on, `validateConfig` takes a `metrics.Registry` as input, and validates that thresholds defined in the config apply to existing metrics, and use methods that are valid for the metric they apply to. As a side effect, this commit adds a `Get` method to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
This commit makes some minor modifications to the `stats` package API. Namely, it makes `stats.ThresholdExpression` and `stats.token*` symbols public. It also makes `stats.Threshold.parsed` public. These changes are made in order to facilitate validation of thresholds from outside the `stats` package. Having access to both the parsed Threshold, and the aggregation methods symbols will allow comparing them and asserting their meaningfulness in a context where we have typed metrics available. ref #2330
This commit adds a `validateThresholdConfig` function to `cmd/config`, and integrates it as part of the `validateConfig` operations. From now on, `validateConfig` takes a `metrics.Registry` as input, and validates that thresholds defined in the config apply to existing metrics, and use methods that are valid for the metric they apply to. As a side effect, this commit adds a `Get` method to `metrics.Registry` in order to be able to query registered metrics, regardless of whether they are custom or builtin metrics. As another side effect, this commit introduces a `lib.Contains` helper function allowing to check if a slice of strings contains a given string. This is used to simplify the matching of supported aggregation methods on metrics in the `validateThresholdConfig` function. ref #2330
This commit makes sure that the threshold configuration (as passed in the script exported options for instance) is valid, before starting the execution. A valid threshold must pass the following assertion: - Its expression is syntaxically correct and is parsable - It applies to a metrics that's known to k6, either builtin or custom - Its expression's aggregation method is valid for the metric it applies to Threshold validation will be made in the context of the `run`, `cloud`, `archive`, `inspect`, and `archive` commands. If a threshold definition is invalid, the k6 program will exit with a status code of 104. ref #2330
Problem statement
We would like to parse and validate threshold expressions at the end of the init context's evaluation, in order to have invalid thresholds make K6 fail early.
Context
As of #2251 (addressing #1443), thresholds are parsed and executed in Go, as opposed to prior to that, when the operation was done in JS. Still, threshold evaluation happens during the running phase of K6. During the review of #2251, @na-- mentioned that as a follow-up, we probably should move the parsing and validation of thresholds right after the initial evaluation of the init context. That way, if thresholds expression don't parse, or parse into a case we know to be an error (see Scope), we may stop right at the end of the initialization phase and have K6 fail early.
As of today, parsing a threshold expression is done using the
stats.parseThresholdExpression
function. Parsing is made instats.newThreshold
. Executing the threshold, and comparing using it against the actual numbers we've collected (sinks
) is done instats.Threshold.runNoTaint
.Scope
The goal would then be for our changes to halt the execution of K6, right after the evaluation of the init context, in the following scenarios.
Invalid threshold expression
Invalid aggregation method for metric
Threshold on non-existing metric
Requirements
k6
should exit with the code104
InvalidConfigProposed change
Although it's still unclear to me at this point exactly what the concrete solution should look like, the rationale would be to find the right place in the evaluation of the init context (somewhere where the metrics registry is available), to use
stats.parseThresholdExpression
.Open questions
While we believe this change's scope shouldn't be very big, and don't expect complications, the following questions remain were raised or remain open until implementation:
--no-thresholds
option is passed tok6
Connected issue
Format
method ofstats.Sink
#2320Edits
--no-thresholds
optionThe text was updated successfully, but these errors were encountered: