@@ -74,6 +74,16 @@ public class PrometheusNaming {
74
74
".total" , ".created" , ".bucket" , ".info"
75
75
};
76
76
77
+ static ValidationScheme initValidationScheme () {
78
+ if (PrometheusProperties .get () != null && PrometheusProperties .get ().getNamingProperties () != null ) {
79
+ String validationScheme = PrometheusProperties .get ().getNamingProperties ().getValidationScheme ();
80
+ if (validationScheme != null && validationScheme .equals ("utf-8" )) {
81
+ return ValidationScheme .UTF_8_VALIDATION ;
82
+ }
83
+ }
84
+ return ValidationScheme .LEGACY_VALIDATION ;
85
+ }
86
+
77
87
/**
78
88
* Test if a metric name is valid. Rules:
79
89
* <ul>
@@ -96,16 +106,6 @@ public static boolean isValidMetricName(String name) {
96
106
return validateMetricName (name ) == null ;
97
107
}
98
108
99
- static ValidationScheme initValidationScheme () {
100
- if (PrometheusProperties .get () != null && PrometheusProperties .get ().getNamingProperties () != null ) {
101
- String validationScheme = PrometheusProperties .get ().getNamingProperties ().getValidationScheme ();
102
- if (validationScheme != null && validationScheme .equals ("utf-8" )) {
103
- return ValidationScheme .UTF_8_VALIDATION ;
104
- }
105
- }
106
- return ValidationScheme .LEGACY_VALIDATION ;
107
- }
108
-
109
109
static String validateMetricName (String name ) {
110
110
switch (nameValidationScheme ) {
111
111
case LEGACY_VALIDATION :
@@ -151,8 +151,7 @@ public static boolean isValidLegacyMetricName(String name) {
151
151
public static boolean isValidLabelName (String name ) {
152
152
switch (nameValidationScheme ) {
153
153
case LEGACY_VALIDATION :
154
- return isValidLegacyLabelName (name ) &&
155
- !(name .startsWith ("__" ) || name .startsWith ("._" ) || name .startsWith (".." ) || name .startsWith ("_." ));
154
+ return isValidLegacyLabelName (name );
156
155
case UTF_8_VALIDATION :
157
156
return StandardCharsets .UTF_8 .newEncoder ().canEncode (name );
158
157
default :
@@ -161,14 +160,8 @@ public static boolean isValidLabelName(String name) {
161
160
}
162
161
163
162
public static boolean isValidLegacyLabelName (String name ) {
164
- switch (nameValidationScheme ) {
165
- case LEGACY_VALIDATION :
166
- return LEGACY_LABEL_NAME_PATTERN .matcher (name ).matches ();
167
- case UTF_8_VALIDATION :
168
- return LABEL_NAME_PATTERN .matcher (name ).matches ();
169
- default :
170
- throw new RuntimeException ("Invalid name validation scheme requested: " + nameValidationScheme );
171
- }
163
+ return LEGACY_LABEL_NAME_PATTERN .matcher (name ).matches () &&
164
+ !(name .startsWith ("__" ) || name .startsWith ("._" ) || name .startsWith (".." ) || name .startsWith ("_." ));
172
165
}
173
166
174
167
/**
0 commit comments