File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -931,7 +931,9 @@ func resolveLabels() map[string]interface{} {
931931 result [trimmedKey ] = parseJSON (trimmedValue )
932932
933933 default : // String
934- result [trimmedKey ] = trimmedValue
934+ if validateLabel (trimmedValue ) {
935+ result [trimmedKey ] = trimmedValue
936+ }
935937 }
936938 }
937939
@@ -940,6 +942,17 @@ func resolveLabels() map[string]interface{} {
940942 return result
941943}
942944
945+ func validateLabel (labelValue string ) bool {
946+ const maxLength = 256
947+ labelPattern := regexp .MustCompile ("^[a-zA-Z0-9]([a-zA-Z0-9-_]{0,254}[a-zA-Z0-9])?$" )
948+ if len (labelValue ) > maxLength || ! labelPattern .MatchString (labelValue ) {
949+ slog .Warn ("Label value contains unsupported character " , "label_value" , labelValue )
950+ return false
951+ }
952+
953+ return true
954+ }
955+
943956func resolveEnvironmentVariableLabels () map [string ]string {
944957 envLabels := make (map [string ]string )
945958 envInput := viperInstance .GetString (LabelsRootKey )
Original file line number Diff line number Diff line change @@ -1234,7 +1234,7 @@ func createConfig() *Config {
12341234 {
12351235 Action : "insert" ,
12361236 Key : "label1" ,
1237- Value : "label 1" ,
1237+ Value : "label- 1" ,
12381238 },
12391239 {
12401240 Action : "insert" ,
@@ -1314,7 +1314,7 @@ func createConfig() *Config {
13141314 },
13151315 },
13161316 Labels : map [string ]any {
1317- "label1" : "label 1" ,
1317+ "label1" : "label- 1" ,
13181318 "label2" : "new-value" ,
13191319 "label3" : 123 ,
13201320 },
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ watchers:
1313 - \.*log$
1414
1515labels:
16- label1: label 1
16+ label1: label- 1
1717 label2: new-value
1818 label3: 123
1919
You can’t perform that action at this time.
0 commit comments