ZABBIX BUGS AND ISSUES
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-10429

Unary minus preceeding negative value causes calculated item to become not supported

    Details

      Description

      Create two calculated items. The first one will have expression like:

      -1
      

      and the second one will reference the first item like:

      -last(host:key1)
      

      Type of information: Numeric (float) for both of them.

      The second item becomes unsupported with the following error:

      Cannot evaluate expression: expected numeric token at "-1".
      

      In the process of expression evaluation server simply substitutes trigger functions with their value without putting them in parentheses, which can sometimes produce invalid expressions (like "--1" in our example) for further evaluation stages.

        Activity

        Hide
        Alexander Vladishev added a comment -

        Thank you for a report. It help us making the product better!

        I confirm the issue.

        Show
        Alexander Vladishev added a comment - Thank you for a report. It help us making the product better! I confirm the issue.
        Hide
        Aleksandrs Saveljevs added a comment - - edited

        Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-10429 .

        Now, if a macro is required to yield a numeric value or a function is substituted in an expression, then that value is wrapped in parentheses if it is either a negative value or a complex expression (like "asdf" or "1+2+3").

        Note that this results in the change of behavior. Suppose we have a function "last(expression)" with a value of "1+2+3". If used in expression like "-last(expression)", it would previously evaluate to 4. Now it evaluates to -6.

        Show
        Aleksandrs Saveljevs added a comment - - edited Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-10429 . Now, if a macro is required to yield a numeric value or a function is substituted in an expression, then that value is wrapped in parentheses if it is either a negative value or a complex expression (like "asdf" or "1+2+3"). Note that this results in the change of behavior. Suppose we have a function "last(expression)" with a value of "1+2+3". If used in expression like "-last(expression)", it would previously evaluate to 4. Now it evaluates to -6.
        Hide
        Glebs Ivanovskis added a comment -

        A quick recap of today's discussion regarding multiple unary minuses without parentheses.

        Our documentation says:

        All operators, except unary - and not, have left-to-right associativity.

        Wikipedia gives the following definition:


        In programming languages, the associativity (or fixity) of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses.

        I see two ways out:

        • leave documentation as it is, add support for "---...-expr" and "not not ... not expr" constructions in expressions (for consistency "+++...+expr" should be supported as well);
        • use non-associative term for unary minus and logical NOT in documentation, but this will contradict common understanding of unary minus and logical NOT.
        Show
        Glebs Ivanovskis added a comment - A quick recap of today's discussion regarding multiple unary minuses without parentheses. Our documentation says: All operators, except unary - and not, have left-to-right associativity . Wikipedia gives the following definition: In programming languages, the associativity (or fixity) of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses . I see two ways out: leave documentation as it is, add support for "---...-expr" and "not not ... not expr" constructions in expressions (for consistency "+++...+expr" should be supported as well); use non-associative term for unary minus and logical NOT in documentation, but this will contradict common understanding of unary minus and logical NOT.
        Hide
        Sandis Neilands (Inactive) added a comment - - edited

        (1) Documentation.

        1. Why is 2.2 not affected? Which changes introduced the current behaviour?
        2. Is there a workaround (putting function, macro producing -1 in parentheses?)?
        3. As Glebs Ivanovskis pointed out above

        - -1

        is not necessarily an invalid expression. The problem is that the syntax of our expression language is not defined in a formal way thus the correctness of such expression is ambiguous. Since we do not have prefix

        --

        operator and since unary

        -

        groups operand on the right - one could potentially interpret this expression as

        -(-(1))

        . The question is - how do we document the changes?

        Aleksandrs Saveljevs

        1. The current behavior was introduced with ZBXNEXT-1782. Version 2.2 is not affected (probably), because "--+-+5" is treated as "-5" (see functions evaluate(), evaluate_simple() and compress_signs()).
        2. Yes, put the macro or function in parentheses.
        3. Expression "--1" can be considered either valid or invalid, depending on the expression syntax. We do not have a formal definition of the syntax, but the informal definition, as governed by Alexander Vladishev, is meant to disallow "--1" and "not not 1". Do you mean that we should document in upgrade notes that we allowed "--1" before, but not anymore? RESOLVED.

        Sandis Neilands Thanks for your answers. CLOSED points 1 and 2.

        As for point 3 - currently the associativity/grouping rules and limitations of unary operators are not documented.

        https://www.zabbix.com/documentation/3.0/manual/config/triggers/expression?s[]=operators

        Aleksandrs Saveljevs Documented at the following locations:

        Will copy the first change to 3.0 and 3.2 if OK. RESOLVED.

        Sandis Neilands CLOSED.

        Aleksandrs Saveljevs Also copied to https://www.zabbix.com/documentation/3.0/manual/config/triggers/expression#operators and https://www.zabbix.com/documentation/3.2/manual/config/triggers/expression#operators . Now really CLOSED.

        Show
        Sandis Neilands (Inactive) added a comment - - edited (1) Documentation. 1. Why is 2.2 not affected? Which changes introduced the current behaviour? 2. Is there a workaround (putting function, macro producing -1 in parentheses?)? 3. As Glebs Ivanovskis pointed out above - -1 is not necessarily an invalid expression. The problem is that the syntax of our expression language is not defined in a formal way thus the correctness of such expression is ambiguous. Since we do not have prefix -- operator and since unary - groups operand on the right - one could potentially interpret this expression as -(-(1)) . The question is - how do we document the changes? Aleksandrs Saveljevs 1. The current behavior was introduced with ZBXNEXT-1782 . Version 2.2 is not affected (probably), because "--+-+5" is treated as "-5" (see functions evaluate(), evaluate_simple() and compress_signs()). 2. Yes, put the macro or function in parentheses. 3. Expression "--1" can be considered either valid or invalid, depending on the expression syntax. We do not have a formal definition of the syntax, but the informal definition, as governed by Alexander Vladishev , is meant to disallow "--1" and "not not 1". Do you mean that we should document in upgrade notes that we allowed "--1" before, but not anymore? RESOLVED. Sandis Neilands Thanks for your answers. CLOSED points 1 and 2. As for point 3 - currently the associativity/grouping rules and limitations of unary operators are not documented. https://www.zabbix.com/documentation/3.0/manual/config/triggers/expression?s[]=operators Aleksandrs Saveljevs Documented at the following locations: https://www.zabbix.com/documentation/2.4/manual/config/triggers/expression#operators https://www.zabbix.com/documentation/2.4/manual/installation/upgrade_notes_240#converting_triggers_to_the_new_syntax Will copy the first change to 3.0 and 3.2 if OK. RESOLVED. Sandis Neilands CLOSED. Aleksandrs Saveljevs Also copied to https://www.zabbix.com/documentation/3.0/manual/config/triggers/expression#operators and https://www.zabbix.com/documentation/3.2/manual/config/triggers/expression#operators . Now really CLOSED.
        Hide
        Glebs Ivanovskis added a comment -

        Putting every single macro in parentheses is a workaround. But what's the point of curly braces then?

        Show
        Glebs Ivanovskis added a comment - Putting every single macro in parentheses is a workaround. But what's the point of curly braces then?
        Hide
        Sandis Neilands (Inactive) added a comment -

        Successfully tested.

        Please answer the questions in (1).

        Show
        Sandis Neilands (Inactive) added a comment - Successfully tested. Please answer the questions in (1) .
        Hide
        Aleksandrs Saveljevs added a comment - - edited

        Fixed in pre-2.4.8rc1 r58767, pre-3.0.2rc1 58768 and pre-3.1.0 (trunk) r58769.

        Show
        Aleksandrs Saveljevs added a comment - - edited Fixed in pre-2.4.8rc1 r58767, pre-3.0.2rc1 58768 and pre-3.1.0 (trunk) r58769.
        Hide
        Aleksandrs Saveljevs added a comment - - edited

        (2) There was a conflict in src/libs/zbxserver/expression.c when merging from 2.4 to 3.0. Please take a look.

        Sandis Neilands CLOSED.

        Show
        Aleksandrs Saveljevs added a comment - - edited (2) There was a conflict in src/libs/zbxserver/expression.c when merging from 2.4 to 3.0. Please take a look. Sandis Neilands CLOSED.

          People

          • Assignee:
            Unassigned
            Reporter:
            Glebs Ivanovskis
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: