diff --git a/README.adoc b/README.adoc index 3831c53..1656eff 100644 --- a/README.adoc +++ b/README.adoc @@ -491,6 +491,7 @@ namespace "app1" { relabel "request_uri" { from = "request" split = 2 + separator = " " // <1> match "^/users/[0-9]+" { replacement = "/users/:id" @@ -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. @@ -515,6 +517,7 @@ namespaces: - target_label: request_uri from: request split: 2 + separator: ' ' matches: - regexp: "^/users/[0-9]+" replacement: "/users/:id" diff --git a/config/struct_relabel.go b/config/struct_relabel.go index 5bafaa6..13737aa 100644 --- a/config/struct_relabel.go +++ b/config/struct_relabel.go @@ -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{} diff --git a/relabeling/mapping.go b/relabeling/mapping.go index 957c80d..e836ea6 100644 --- a/relabeling/mapping.go +++ b/relabeling/mapping.go @@ -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]