Search code examples
promtail

How do I apply two labels with the same value from regular expression


When using Promtail for log scraping, is there a way to configure two labels with the same value based on a single regular expression? So given something like this:

    - match:
        selector: '{app="my-app"}'
        stages:
        - regex:
          expression: '.*"(some-string)\":\s?"(?P<some_label>[0-9a-zA-Z-_;\.]*)".*'
          source: log
    - labels:
        some_label:

I would want to add a second label some_other_label with the same value. Is there a way to do this without having to re-parse the log just to give the capture group a different name?


Solution

  • I actually found it myself:

        - match:
            selector: '{app="my-app"}'
            stages:
            - regex:
              expression: '.*"(some-string)\":\s?"(?P<some_label>[0-9a-zA-Z-_;\.]*)".*'
              source: log
        - labels:
            some_label:
            some_other_label: some_label