Skip to content

Add support for default values of regex match groups in rules #905

@EconomicTouristsArmLate

Description

To properly consume some metrics, I need to set a default value on a label.
This label value is defined by an optional match group, example config (ref label version):

---
lowercaseOutputLabelNames: true
lowercaseOutputName: true
whitelistObjectNames: ["java.lang:type=OperatingSystem", "Catalina:*"]
blacklistObjectNames: []
rules:
  - pattern: 'Catalina<j2eeType=WebModule, name=//(?:localhost/)?([-a-zA-Z0-9+&@/%?=~_|!:.,;]*[-a-zA-Z0-9+&@/%=~_|])(?:##(.+))?, J2EEApplication=none, J2EEServer=none><>startTime:'
    name: tomcat_module_started_at
    labels:
      module: "$1"
      version: "$2"
    help: Tomcat WebModule startTime (unix time)
    type: GAUGE

Note that version is fed by an optional regex match.
I'd love to be able to write something along the lines of

    labels:
      module: "$1"
      version: "${2:-unversioned}"

though I don't care much about the specific syntax (using bash syntax here, which is also commonly used in ENV substitions, eg in docker compose files).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions