@@ -54,6 +54,10 @@ const (
5454 LabelDrop Action = "labeldrop"
5555 // LabelKeep drops any label not matching the regex.
5656 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"
5761)
5862
5963// UnmarshalYAML implements the yaml.Unmarshaler interface.
@@ -63,7 +67,7 @@ func (a *Action) UnmarshalYAML(unmarshal func(interface{}) error) error {
6367 return err
6468 }
6569 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 :
6771 * a = act
6872 return nil
6973 }
@@ -106,12 +110,15 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
106110 if c .Modulus == 0 && c .Action == HashMod {
107111 return errors .Errorf ("relabel configuration for hashmod requires non-zero modulus" )
108112 }
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 == "" {
110114 return errors .Errorf ("relabel configuration for %s action requires 'target_label' value" , c .Action )
111115 }
112- if c .Action == Replace && ! relabelTarget .MatchString (c .TargetLabel ) {
116+ if ( c .Action == Replace || c . Action == Lowercase || c . Action == Uppercase ) && ! relabelTarget .MatchString (c .TargetLabel ) {
113117 return errors .Errorf ("%q is invalid 'target_label' for %s action" , c .TargetLabel , c .Action )
114118 }
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+ }
115122 if c .Action == LabelMap && ! relabelTarget .MatchString (c .Replacement ) {
116123 return errors .Errorf ("%q is invalid 'replacement' for %s action" , c .Replacement , c .Action )
117124 }
@@ -228,6 +235,10 @@ func relabel(lset labels.Labels, cfg *Config) labels.Labels {
228235 break
229236 }
230237 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 ))
231242 case HashMod :
232243 mod := sum64 (md5 .Sum ([]byte (val ))) % cfg .Modulus
233244 lb .Set (cfg .TargetLabel , fmt .Sprintf ("%d" , mod ))
0 commit comments