Skip to content

loki.process stage.regex autolabels #3146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dlucredativ opened this issue Mar 31, 2025 · 2 comments · May be fixed by #3458
Open

loki.process stage.regex autolabels #3146

dlucredativ opened this issue Mar 31, 2025 · 2 comments · May be fixed by #3458
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@dlucredativ
Copy link

Request

I have a stage.match block containing several stage.regex blocks, each of which has an expression containing one or more ?P<...> named capture groups. I want all of those as labels, and for that I need to repeat myself by explicitly defining a stage.labels block which lists all of those capture group names. Instead I propose to introduce namespacing for capture groups which themselves signal to be exported as a label.

Use case

For example:

stage.match {
  stage.regex {
    expression = "Hello (?P<english>\w+)"
  }
  stage.regex {
    expression = "Hallo (?P<german>\w+)"
  }
  stage.labels = {
    values = {
      english = "",
      german = "",
    }
  }
}

may become

stage.match {
  stage.regex {
    expression = "Hello (?P<autolabel:english>\w+)"
  }
  stage.regex {
    expression = "Hallo (?P<autolabel:german>\w+)"
  }
}

I would also be happy with some other mechanism which removes the burden to repeat oneself in a non-trivial way.

@dlucredativ dlucredativ added the enhancement New feature or request label Mar 31, 2025
@dehaansa
Copy link
Collaborator

Thanks for the feedback! That definitely sounds like a useful feature, I would personally lean towards adding an attribute to the regex stage that would add all capture groups as labels, but I'm open to other implementations. I can't offer a timeline right now on internal development of this feature, but you or any other community member are more than welcome to make a PR for the contribution as well!

@dehaansa dehaansa added the good first issue Good for newcomers label Apr 11, 2025
@harshrai654
Copy link
Contributor

harshrai654 commented Apr 24, 2025

Hey @dehaansa This does sound like a useful feature! I’m interested in taking a look at this over the weekend.

As mentioned, adding an attribute to the regex stage — maybe something like export_named_groups = true — could be a clean way to automatically promote all named capture groups as labels without needing to repeat them in stage.labels. That approach feels intuitive and backward-compatible.

I’m still fairly new to the Alloy codebase (just submitted my first PR recently), but I’d love to give this a shot if that sounds reasonable. Let me know if there's anything specific I should consider while exploring this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
3 participants