[ZBX-10429] Unary minus preceeding negative value causes calculated item to become not supported Created: 2016 Feb 22  Updated: 2017 May 30  Resolved: 2016 Mar 01

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 2.4.7, 3.0.0
Fix Version/s: 2.4.8rc1, 3.0.2rc1, 3.2.0alpha1

Type: Incident report Priority: Major
Reporter: Glebs Ivanovskis (Inactive) Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: calculation, expressions
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 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.



 Comments   
Comment by Alexander Vladishev [ 2016 Feb 23 ]

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

I confirm the issue.

Comment by Aleksandrs Saveljevs [ 2016 Feb 23 ]

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.

Comment by Glebs Ivanovskis (Inactive) [ 2016 Feb 24 ]

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.
Comment by Sandis Neilands (Inactive) [ 2016 Feb 24 ]

(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?

asaveljevs

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 sasha, 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

asaveljevs Documented at the following locations:

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

sandis.neilands CLOSED.

asaveljevs 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.

Comment by Glebs Ivanovskis (Inactive) [ 2016 Feb 24 ]

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

Comment by Sandis Neilands (Inactive) [ 2016 Feb 24 ]

Successfully tested.

Please answer the questions in (1).

Comment by Aleksandrs Saveljevs [ 2016 Feb 29 ]

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

Comment by Aleksandrs Saveljevs [ 2016 Feb 29 ]

(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.

Generated at Tue Mar 19 12:26:21 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.