Skip to content

Commit

Permalink
Make relabel "split" separator configurable (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-helmich committed Oct 1, 2020
1 parent e8c479e commit 23afa93
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ namespace "app1" {
relabel "request_uri" {
from = "request"
split = 2
separator = " " // <1>

match "^/users/[0-9]+" {
replacement = "/users/:id"
Expand All @@ -502,6 +503,7 @@ namespace "app1" {
}
}
----
<1> The `separator` property is optional; if omitted, the space character (`" "`) will be assumed as separator.
If a match is found, the `replacement` replaces each occurrence of the corresponding match in the original value. Otherwise the processing continues to check the following match statements.
Expand All @@ -515,6 +517,7 @@ namespaces:
- target_label: request_uri
from: request
split: 2
separator: ' '
matches:
- regexp: "^/users/[0-9]+"
replacement: "/users/:id"
Expand Down
1 change: 1 addition & 0 deletions config/struct_relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type RelabelConfig struct {
Whitelist []string `hcl:"whitelist"`
Matches []RelabelValueMatch `hcl:"match"`
Split int `hcl:"split"`
Separator string `hcl:"separator"`

WhitelistExists bool
WhitelistMap map[string]interface{}
Expand Down
7 changes: 6 additions & 1 deletion relabeling/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
// config (matching against whitelists, regular expressions etc.)
func (r *Relabeling) Map(sourceValue string) (string, error) {
if r.Split > 0 {
values := strings.Split(sourceValue, " ")
separator := r.Separator
if separator == "" {
separator = " "
}

values := strings.Split(sourceValue, separator)

if len(values) >= r.Split {
sourceValue = values[r.Split-1]
Expand Down

0 comments on commit 23afa93

Please sign in to comment.