I’ve found a regexp escaping issue when using Grafana + a MySQL datasource. Let’s assume a simple dashboard including a variable location that can take one or more values: madrid, london or whatever(42). Using that value we can build the name of the metrics to be retrieved from the metrics table (i.e. foo.madrid.value, foo.london.value, foo.whatever(42).value, etc.). We want to do that using the REGEXP SQL operator:
...
WHERE
metrics.name REGEXP '^foo\\.${location:regex}\\.value$'
...
If madrid and london are selected that SQL string will be expanded to ^foo\\.(madrid|london)\\.value$. No problem with that. But if the value including the parentheses is selected, the SQL string will be expanded to ^foo\\.whatever\(42\)\\.value$, which is not ok because in MySQL strings backslashes need to be double-escaped. In other words, a metric named foo.whatever42.value would match the generated regexp string, but not foo.whatever(42).value.
We’ve considered adding NO_BACKSLASH_ESCAPES to sql_mode before the query is executed and restore it to previous value just after that, but it’s ugly and I don’t think is even doable. Any tricks to workaround this?