grok_exporter icon indicating copy to clipboard operation
grok_exporter copied to clipboard

to lowercase(or uppercase) is not available with the gsub command

Open ohkik opened this issue 6 years ago • 3 comments
trafficstars

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.

ohkik avatar Mar 09 '19 05:03 ohkik

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.

fstab avatar Mar 13 '19 20:03 fstab

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.

ohkik avatar Mar 18 '19 09:03 ohkik

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.

fstab avatar Apr 02 '19 20:04 fstab