Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPromtool unit test rules support values as a range #5352
Comments
This comment has been minimized.
This comment has been minimized.
|
In prometheus/docs#1305 the potential bug is that the answer is .9991 rather than .999. This behaviour here is as expected. |
This comment has been minimized.
This comment has been minimized.
|
If the behaviour here is as expected how can I write a test that checks for 0.4, if it fails with 0.3999999999999991 ? Isn't this standard floating point inaccuracy? Other testing frameworks support deltas for situations like this, e.g. Junit: https://junit.org/junit4/javadoc/latest/org/junit/Assert.html#assertEquals(java.lang.String,%20double,%20double,%20double) |
This comment has been minimized.
This comment has been minimized.
|
You need to use 0.3999999999999991 in that case. |
This comment has been minimized.
This comment has been minimized.
|
Well, |
This comment has been minimized.
This comment has been minimized.
|
To be honest, I wouldn't even test this simple a rule. It's more for alerts, and non-trivial PromQL. |
This comment has been minimized.
This comment has been minimized.
|
But if I can't even declare a clear test for such a simple rule, where does that leave me for complex ones? |
This comment has been minimized.
This comment has been minimized.
|
Quoting prometheus/docs#1305 (comment): as PromQL is meant to be deterministic, if we want to check within a delta, I think it should be internal to promtool and not specified in the yaml. |
This comment has been minimized.
This comment has been minimized.
|
@codesome that would be fine with me too, as long as I can state |
This comment has been minimized.
This comment has been minimized.
|
@brian-brazil would check within a delta make sense for unit testing? Or the current way is the way it should be? |
This comment has been minimized.
This comment has been minimized.
|
It wouldn't make sense, as you'd silently be letting changes happen without the tests failing. We depend on this for some of our floating-point accuracy related tests for example. |
bosschaert commentedMar 13, 2019
Proposal
Promtool test cases don't always provide exact values, hence expected values with an allowable delta should be supported.
Bug Report
I am using the promtool unit testing support to test my alerts and recording rules. However, probably due to inaccuracies in floating point math, the test result of my rule is not precise.
And then I have the following test
However, the above test fails with:
In that case it would be good to be able to, instead of using 0.4 as expected value, be able to specify something like
0.4 ±3%or something like this.System information:
Darwin 18.2.0 x86_64
Prometheus version:
promtool, version 2.7.1 (branch: HEAD, revision: 62e591f)
build user: root@f9f82868fc43
build date: 20190131-11:16:59
go version: go1.11.5