Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query editor adds single quote to variable when used in graphite function #11927

Closed
munokar opened this issue May 14, 2018 · 8 comments · Fixed by #12907
Closed

Query editor adds single quote to variable when used in graphite function #11927

munokar opened this issue May 14, 2018 · 8 comments · Fixed by #12907

Comments

@munokar
Copy link

munokar commented May 14, 2018

Hello,

we have some dashboards that use a variable to display the Top 5 / 10 / 15 entries of a series.
We have noticed that after modifying the query (originally created in Grafana 4) the query is not working anymore.

grafik

The error is an internal server errors with details:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 401, in render
    series_list = evaluateTarget(context, target, data_store)
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 496, in evaluateTarget
    result = evaluateTokens(requestContext, tokens, data_store)
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 506, in evaluateTokens
    return evaluateTokens(requestContext, tokens.expression, data_store)
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 514, in evaluateTokens
    arg, data_store) for arg in tokens.call.args]
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 506, in evaluateTokens
    return evaluateTokens(requestContext, tokens.expression, data_store)
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 520, in evaluateTokens
    ret = func(requestContext, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/graphite_api/functions.py", line 1575, in highestMax
    result_list = sorted(seriesList, key=lambda s: max(s))[-n:]
TypeError: bad operand type for unary -: 'unicode'


If I toggle the editor I can see that single quotes are added before and after the variable ($Top):

grafik

If I manually remove the single quotes. The query is performed successfully!
If I now toggle between the edit modes everything stays OK until I change the query in the dropdown editor mode.

Regards
Timo

Please include this information:

What Grafana version are you using?

5.1.2

What datasource are you using?

Graphite

What OS are you running grafana on?

Red Hat Enterprise Linux Server release 7.5 (Maipo)

What did you do?

Edit existing queries.

What was the expected result?

Query should display results.

What happened instead?

Query is showing Error:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 401, in render
    series_list = evaluateTarget(context, target, data_store)
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 496, in evaluateTarget
    result = evaluateTokens(requestContext, tokens, data_store)
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 506, in evaluateTokens
    return evaluateTokens(requestContext, tokens.expression, data_store)
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 514, in evaluateTokens
    arg, data_store) for arg in tokens.call.args]
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 506, in evaluateTokens
    return evaluateTokens(requestContext, tokens.expression, data_store)
  File "/usr/lib/python2.7/site-packages/graphite_api/app.py", line 520, in evaluateTokens
    ret = func(requestContext, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/graphite_api/functions.py", line 1575, in highestMax
    result_list = sorted(seriesList, key=lambda s: max(s))[-n:]
TypeError: bad operand type for unary -: 'unicode'

@daniellee daniellee added this to the 5.2 milestone May 14, 2018
@marefr marefr modified the milestones: 5.2, 5.3 May 28, 2018
@azhiltsov
Copy link
Contributor

We also observe this.

@torkelo
Copy link
Member

torkelo commented Jun 20, 2018

duplicate of #2078

@torkelo torkelo closed this as completed Jun 20, 2018
@azhiltsov
Copy link
Contributor

@torkelo I believe you closed it by mistake

@torkelo
Copy link
Member

torkelo commented Jun 20, 2018

not sure I did, as there already is an open issue for this (which I linked to)

@torkelo torkelo reopened this Jun 20, 2018
@torkelo
Copy link
Member

torkelo commented Jun 20, 2018

Ok, its a related but new issue introduced in 3a4e051#diff-2805d5a9f2c9a0e6e52590b65e8db820

int func params should not be required to be parsed to numbers, before that commit that test was only applied to parms of type int_or_interval (som functions can take both a number and string for same parameter).

So to fix this we need to restore render function to this

else if (paramType === 'int_or_interval' && $.isNumeric(value)) {

That is only apply the _.isFinite(+value) when paramType === 'int_or_interval'

@torkelo
Copy link
Member

torkelo commented Jun 20, 2018

The same change also introduced this bug, #12355

The _includes condition there should not be there. It seems the value sometimes is true/false (js boolean not string), and it will also make having a variable there not possible.

if (paramType === 'boolean' && _.includes(['true', 'false'], value)) {
return value;
}

@DanCech
Copy link
Collaborator

DanCech commented Jun 20, 2018

In the specific case of highest/lowest you can run the master build of graphite-web which handles numeric strings until this is fixed in Grafana.

graphite-project/graphite-web#2294

@torkelo torkelo modified the milestone: 5.3 Aug 13, 2018
torkelo added a commit that referenced this issue Aug 13, 2018
torkelo added a commit that referenced this issue Aug 14, 2018
* fix: graphite function parameters should never be quoted for boolean, node, int and float types, fixes #11927

* Update gfunc.ts
@marefr marefr modified the milestones: 5.3, 5.3.0-beta1 Sep 6, 2018
@Surfmobile
Copy link

I have the same problem, but for InfluxDB as the storage. I want to be able to do exclude entries that have a tag variable that is empty. I can do this with the manual editor:

WHERE "tag" != ''

But when I try to do this in the visual editor, it ends up as:

WHERE "tag" != ''''

So the quotes get re-quoted. This seems like a bug to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants