@@ -54,6 +54,10 @@ const (
54
54
LabelDrop Action = "labeldrop"
55
55
// LabelKeep drops any label not matching the regex.
56
56
LabelKeep Action = "labelkeep"
57
+ // Lowercase maps input letters to their lower case.
58
+ Lowercase Action = "lowercase"
59
+ // Uppercase maps input letters to their upper case.
60
+ Uppercase Action = "uppercase"
57
61
)
58
62
59
63
// UnmarshalYAML implements the yaml.Unmarshaler interface.
@@ -63,7 +67,7 @@ func (a *Action) UnmarshalYAML(unmarshal func(interface{}) error) error {
63
67
return err
64
68
}
65
69
switch act := Action (strings .ToLower (s )); act {
66
- case Replace , Keep , Drop , HashMod , LabelMap , LabelDrop , LabelKeep :
70
+ case Replace , Keep , Drop , HashMod , LabelMap , LabelDrop , LabelKeep , Lowercase , Uppercase :
67
71
* a = act
68
72
return nil
69
73
}
@@ -106,12 +110,15 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
106
110
if c .Modulus == 0 && c .Action == HashMod {
107
111
return errors .Errorf ("relabel configuration for hashmod requires non-zero modulus" )
108
112
}
109
- if (c .Action == Replace || c .Action == HashMod ) && c .TargetLabel == "" {
113
+ if (c .Action == Replace || c .Action == HashMod || c . Action == Lowercase || c . Action == Uppercase ) && c .TargetLabel == "" {
110
114
return errors .Errorf ("relabel configuration for %s action requires 'target_label' value" , c .Action )
111
115
}
112
- if c .Action == Replace && ! relabelTarget .MatchString (c .TargetLabel ) {
116
+ if ( c .Action == Replace || c . Action == Lowercase || c . Action == Uppercase ) && ! relabelTarget .MatchString (c .TargetLabel ) {
113
117
return errors .Errorf ("%q is invalid 'target_label' for %s action" , c .TargetLabel , c .Action )
114
118
}
119
+ if (c .Action == Lowercase || c .Action == Uppercase ) && c .Replacement != DefaultRelabelConfig .Replacement {
120
+ return errors .Errorf ("'replacement' can not be set for %s action" , c .Action )
121
+ }
115
122
if c .Action == LabelMap && ! relabelTarget .MatchString (c .Replacement ) {
116
123
return errors .Errorf ("%q is invalid 'replacement' for %s action" , c .Replacement , c .Action )
117
124
}
@@ -228,6 +235,10 @@ func relabel(lset labels.Labels, cfg *Config) labels.Labels {
228
235
break
229
236
}
230
237
lb .Set (string (target ), string (res ))
238
+ case Lowercase :
239
+ lb .Set (cfg .TargetLabel , strings .ToLower (val ))
240
+ case Uppercase :
241
+ lb .Set (cfg .TargetLabel , strings .ToUpper (val ))
231
242
case HashMod :
232
243
mod := sum64 (md5 .Sum ([]byte (val ))) % cfg .Modulus
233
244
lb .Set (cfg .TargetLabel , fmt .Sprintf ("%d" , mod ))
0 commit comments