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

Grafana frontend error with aggregate operator $toString #15

Open
yar2001 opened this issue Apr 14, 2023 · 4 comments
Open

Grafana frontend error with aggregate operator $toString #15

yar2001 opened this issue Apr 14, 2023 · 4 comments

Comments

@yar2001
Copy link

yar2001 commented Apr 14, 2023

I encountered an error when using some aggregate like this. The error occurred in Grafana frontend before sending any query to the backend.

{
    "$project": {
      "foo": {"$toString": "$_id"},
      "_id": 0
    }
}
PanelQueryRunner Error TypeError: Cannot read properties of undefined (reading 'value')
    at template_srv.ts:303:66
    at [Symbol.replace] (<anonymous>)
    at String.replace (<anonymous>)
    at Object.replace (template_srv.ts:278:19)
    at g.value (datasource.ts:25:52)
    at DataSourceWithBackend.ts:143:17
    at Array.map (<anonymous>)
    at g.query (DataSourceWithBackend.ts:120:29)
    at g.value (datasource.ts:33:7)
    at runRequest.ts:185:73

I’m using the v0.2.0+rc3 version and everything else works great except for this issue. It seems that the problem is related to the toString keyword. Whenever the field name contains the word toString, it will throw this error.

@meln5674
Copy link
Owner

Sorry for the delayed response. This appears to be related to the variable replacement syntax, which, normally will leave "variables" alone if no variable with that name is defined, but given that this happens in Javascript, everything has a toString. I don't have a good solution right now, and I've not had a whole lot of time to look into it.

Unfortunately, it seems that grafana doesn't support any sort of escaping: grafana/grafana#40603 . I'll likely need to add an option to disable variable replacements for these cases.

As crazy as it sounds, you could try actually making a variable named "toString", and setting it to "$toString" and see if the replacement works.

@meln5674
Copy link
Owner

After spending some time investigating, this appears to be a bug within Grafana itself. I've submitted a bug which github has so helpfully linked above this post. Once that is closed, this issue should be resolved. I'll leave this open until then in case there are further developments.

@mbaeuerle
Copy link

One admittedly rather unconventional workaround is to create a constant dollar=$ which is then prepended to toString: ${dollar}toString.
Source: https://community.grafana.com/t/escaping-a-dollar-sign-so-it-doesnt-get-treated-as-a-variable/67941/7

@gmazoni
Copy link

gmazoni commented Sep 21, 2023

I am using https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/

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

No branches or pull requests

4 participants