grok_exporter
grok_exporter copied to clipboard
to lowercase(or uppercase) is not available with the gsub command
The following config will result in an error.
labels:
label: '{{gsub .label "[[:lower:]]" "\\U\\0"}}'
Failed to load /etc/grok_exporter/grok.yml: invalid configuration: failed to read metric label test_metric error parsing label template: syntax error in gsub call: '\U\0' is not a valid replacement: invalid escape sequence: don't forget to put a . (dot) in front of grok fields, otherwise it will be interpreted as a function.
Could you tell me what \\U\\0 is? Tried to look it up on https://ruby-doc.org/core-2.1.4/String.html but didn't find it.
In the case of R, it seems that you can convert upper and lower case letters as follows: toLowecase: gsub(pattern = '([[:upper:]])', perl = TRUE, replacement = '\L\1', n) toUppercase: gsub(pattern = '([[:upper:]])', perl = TRUE, replacement = '\U\1', n) https://stackoverflow.com/questions/30664444/gsub-error-turning-upper-to-lower-case-in-r
I thought I could use the same syntax in grok-exporter.
I implemented gsub as in the official Ruby documentation, so extensions like \U are currently not supported. It would be nice to have that as an additional feature though, so I'll leave this ticket open and will get back to it once the other features like supporting multiple log files are done.