Autocomplete of InfluxDB measurements does not escape search string properly #11503
Labels
area/datasource
datasource/InfluxDB
prio/low
It's a good idea, but not scheduled for any release
type/bug
Milestone
Symtom
Autocomplete of InfluxDB measurement does not work if measurement contains a slash (/) and user enters a slash in the input field. This has been reproduced with Grafana 5.0.4.
Expected behavior
The user may enter the series name and should get autocomplete even if the series name contains a slash.
Analysis
Grafana uses SHOW MEASUREMENTS WITH MEASUREMENT to implement autocomplete. WITH MEASUREMENT takes a regular expression as argument. The user input is taken as argument but not escaped properly.
Example
If the user enters the following input in the measurement box:
mvc.GET /
Grafana issues the following query
http://grafana:3000/api/datasources/proxy/8/query?db=test&q=SHOW%20MEASUREMENTS%20WITH%20MEASUREMENT%20%3D~%20%2Fmvc.GET%20%2F%2F%20LIMIT%20100&epoch=ms
Influx DB returns HTTP status 400, because it interprets the slash as the end-sign of the regular expression. Also note, that the dot character (.) is not escaped as well.
The correct request would be:
http://grafana:3000/api/datasources/proxy/8/query?db=test&q=SHOW%20MEASUREMENTS%20WITH%20MEASUREMENT%20%3D~%20%2Fmvc%5C.GET%20%5C%2F%2F%20LIMIT%20100&epoch=ms
Workaround
It is possible for the user to manually escape those characters. Unfortunately, if the users enter a backslash character (), the query fails again, because the backslash escapes the actual regular expression separator:
http://grafana:3000/api/datasources/proxy/8/query?db=test&q=SHOW%20MEASUREMENTS%20WITH%20MEASUREMENT%20%3D~%20%2Fmvc.GET%20%5C%2F%20LIMIT%20100&epoch=ms
The autocomplete box closes in this case, which is very unexpected. Only if the user enters another character, the query is valid again and the autocomplete reappears.
The text was updated successfully, but these errors were encountered: