thewooster
thewooster

Reputation: 847

Helm-Charts(yaml): Regex expression broken

I am working with https://github.com/prometheus-community/helm-charts and am running into some issues with a couple of regex queries are a part of our basic yaml deployments. The issue I'm having is specifically with the Node exporter part of the prometheus chart. I have configured this:

   nodeExporter:
      extraArgs: {
        collector.filesystem.ignored-fs-types="^(devpts|devtmpfs|mqueue|proc|securityfs|binfmt_misc|debugfs|overlay|pstore|selinuxfs|tmpfs|hugetlbfs|nfsd|cgroup|configfs|rpc_pipefs|sysfs|autofs|rootfs)$",
        collector.filesystem.ignored-mount-points="^/etc/.+$",
        collector.netstat.fields="*",
        collector.diskstats.ignored-devices="^(ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\d+n\d+p|dm-)\d+$", # BROKEN
        collector.netclass.ignored-devices=^(?:tun|kube|veth|dummy|docker).+$,                      # BROKEN
        collector.nfs
       }
      tolerations:
        - operator: Exists

As noted above, these two lines with regex are broken:

 collector.diskstats.ignored-devices="^(ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\d+n\d+p|dm-)\d+$", # BROKEN
 collector.netclass.ignored-devices=^(?:tun|kube|veth|dummy|docker).+$,                      # BROKEN

There seems to be a problem with the | character right be fore "nvme" in the first one, and with the ?: in the second. I believe it's something to do with regex/yaml format, but I'm not sure how to correct this.

Upvotes: 0

Views: 519

Answers (1)

flyx
flyx

Reputation: 39768

With {, you are beginning a YAML flow mapping. It typically contains comma-separated key-value pairs, though you can also, like in this example, give single values instead, which will make them a key with null value.

In YAML, as soon as you enter a flow-style collection, all special flow-indicators cannot be used in plain scalars anymore. Special flow indicators are {}[],. A plain scalar is a non-quoted textual value.

The first broken value is illegal because it contains [ and ]. The second broken value is actually legal according to the specification, but quite some YAML implementations choke on it because ? is also used as indicator for a mapping key.

You have several options:

  • Quote the scalars. since none of them contain single quotes, enclosing each with single quotes will do the trick. Generally you can also double-quote them, but then you need to escape all double-quote characters and all backslashes in there which does not help readability.
   nodeExporter:
      extraArgs: {
        collector.filesystem.ignored-fs-types="^(devpts|devtmpfs|mqueue|proc|securityfs|binfmt_misc|debugfs|overlay|pstore|selinuxfs|tmpfs|hugetlbfs|nfsd|cgroup|configfs|rpc_pipefs|sysfs|autofs|rootfs)$",
        collector.filesystem.ignored-mount-points="^/etc/.+$",
        collector.netstat.fields="*",
        'collector.diskstats.ignored-devices="^(ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\d+n\d+p|dm-)\d+$"',
        'collector.netclass.ignored-devices=^(?:tun|kube|veth|dummy|docker).+$',
        collector.nfs
       }
      tolerations:
        - operator: Exists
  • Use block scalars. Block scalars are generally the best way to enter scalars with lots of special characters because they are ended via indentation and therefore can contain any special character. Block scalars can only occur in other block structures, so you'd need to make extraArgs a block mapping:
   nodeExporter:
      extraArgs:
        ? collector.filesystem.ignored-fs-types="^(devpts|devtmpfs|mqueue|proc|securityfs|binfmt_misc|debugfs|overlay|pstore|selinuxfs|tmpfs|hugetlbfs|nfsd|cgroup|configfs|rpc_pipefs|sysfs|autofs|rootfs)$"
        ? collector.filesystem.ignored-mount-points="^/etc/.+$"
        ? collector.netstat.fields="*"
        ? |-
          collector.diskstats.ignored-devices="^(ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\d+n\d+p|dm-)\d+$"
        ? |-
          collector.netclass.ignored-devices=^(?:tun|kube|veth|dummy|docker).+$
        ? collector.nfs
      tolerations:
        - operator: Exists

As you can see, this is now using the previously mentioned ? as key indicator. Since it is a block sequence, you don't need the commas anymore. |- starts a literal block scalar from which the final linebreak is stripped.

Upvotes: 1

Related Questions