I've encountered an odd interaction in my Grafana dashboard where I'm storing a specific string in a variable called errorMsg. The string is: ERROR: DoorBoard: SetErrorClass[Uart]: Open /dev/ttyUSB2 Exception: Access to the port '/dev/ttyUSB2' is denied.
When I insert this string directly into my query, it works as expected and returns data. Note that for demonstration purposes, I put $errorMsg in the title of the dashboard to show that it is getting interpreted correctly. However, the characters ' seem to be problematic when inserting into the regex:
When I copy the exact same variable (as shown in the Dashboard Title) in place of the $errorMsg, I get the expected output:
As explained above, the difference seems to be in the characters '. When I try the same with messages without these characters, I don't have any issues.
I've attempted to escape the special characters in the errorMsg variable, but still encounter the "no data" output. I expected the query to work the same way whether the error message string is inserted directly or referenced through the variable.
{job="systemd-journal"} |~ ${errorMsg:raw}
works as markalex suggested