[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:
Wikipedia gives the following definition:
I see two ways out:
|
Comment by Sandis Neilands (Inactive) [ 2016 Feb 24 ] |
(1) Documentation. 1. Why is 2.2 not affected? Which changes introduced the current behaviour? - -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? 1. The current behavior was introduced with 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. |