The current comparison for configured threshold values is not type-safe and thus ignores the not so un-common threshold of 0. Attached patch fixes the issue.

Comments

a.milkovsky created an issue. See original summary.

a.milkovsky’s picture

Assigned: a.milkovsky » Unassigned
Status: Active » Needs review
StatusFileSize
new4.22 KB
fago’s picture

Status: Needs review » Reviewed & tested by the community

This should mention it's a straight port of #2684191: [Needs tests] Sensors ignore thresholds of 0. Anyway, code is fine!

alecsmrekar’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.74 KB
new6.96 KB

I have added some tests to make sure the exceeds and falls methods use type safe threshold values.

Note that test_only.patch contains only my changes.

The last submitted patch, 4: test_only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: patch_2704061_with_test.patch, failed testing.

berdir’s picture

Don't worry about the other test fails, I think we have some head test fails there, you can ignore those.

tduong’s picture

Cool! :) I'm currently working on #2775173: getEntityQueryAggregate() gets unneeded parameters that might fix the failing tests...

In the meantime, just some nitpicks for you:

  1. +++ b/src/Tests/MonitoringUITest.php
    @@ -1290,6 +1291,56 @@ class MonitoringUITest extends MonitoringTestBase {
    +   * Tests if the threshold value checks are type safe, especially for zero values.
    

    Too long, should be in max 80 chars. Maybe something like "Tests if thresholds checks are type safe, especially for zero values." (?)

  2. +++ b/src/Tests/MonitoringUITest.php
    @@ -1290,6 +1291,56 @@ class MonitoringUITest extends MonitoringTestBase {
    +    $thresholds = array(
    ...
    +    $test_sensor_result_data = array('sensor_value' => 7);
    ...
    +    $thresholds = array(
    ...
    +    $test_sensor_result_data = array('sensor_value' => 7);
    ...
    +    $thresholds = array(
    ...
    +    $test_sensor_result_data = array('sensor_value' => -7);
    ...
    +    $thresholds = array(
    ...
    +    $test_sensor_result_data = array('sensor_value' => -7);
    

    Use the new array syntax where you add them, according to the array std coding ;)

I'm wondering if it's better to extend the existing 4 test methods for these 4 thresholds method check cases instead to have a specific test... If we want to keep this new test method, then maybe we should also add the last two cases (inner/outer intervals) as well .. ?

And please assign this issue to yourself since you are working on it, @alecsmrekar ;)

alecsmrekar’s picture

Assigned: Unassigned » alecsmrekar

I think it's not really possible to test the inner and outer intervals as their thresholds can not be set to 0 (fails validation).

alecsmrekar’s picture

Status: Needs work » Needs review
StatusFileSize
new6.75 KB

Here is the code with arrays reformatted and the code moved back to the existing methods.

Status: Needs review » Needs work

The last submitted patch, 10: patch_2704061_with_test_2.patch, failed testing.

The last submitted patch, 10: patch_2704061_with_test_2.patch, failed testing.

berdir’s picture

And already new test fails :( (still not your problem)

Test looks good, nice work so far. Lets add one more example in each test for a boundary scenario, meaning, when the value is 0 so that we are sure that it works as expected.

alecsmrekar’s picture

Status: Needs work » Needs review
StatusFileSize
new7.71 KB

Added exceeds and falls test with value 0 and thresholds 0.

tduong’s picture

Status: Needs review » Needs work

Great job! :)
One last thing, can you upload also an interdiff between your patchs please ?

alecsmrekar’s picture

StatusFileSize
new2.67 KB

Interdiff attached.

tduong’s picture

Status: Needs work » Needs review

Alright, looks nice :)

Status: Needs review » Needs work

The last submitted patch, 14: zero_thresholds.patch, failed testing.

berdir’s picture

Status: Needs work » Fixed

Agreed, thanks!

  • Berdir committed 909c18e on 8.x-1.x authored by alecsmrekar
    Issue #2704061 by alecsmrekar, a.milkovsky: Sensors ignore thresholds of...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.