Skip to content

Commit 7c6e748

Browse files
committed
Fix style, invalid regex in name formatting, and remove duplicates in reference.
1 parent 935c07e commit 7c6e748

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

spark-operator/src/main/java/org/apache/spark/k8s/operator/config/SparkOperatorConf.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public final class SparkOperatorConf {
334334
.defaultValue(19090)
335335
.build();
336336

337-
public static final ConfigOption<Boolean> EnablePrometheusTextBasedFormat =
337+
public static final ConfigOption<Boolean> ENABLE_PROMETHEUS_TEXT_BASED_FORMAT =
338338
ConfigOption.<Boolean>builder()
339339
.key("spark.kubernetes.operator.enablePrometheusTextBasedFormat")
340340
.enableDynamicOverride(false)
@@ -346,7 +346,7 @@ public final class SparkOperatorConf {
346346
.defaultValue(true)
347347
.build();
348348

349-
public static final ConfigOption<Boolean> EnableSanitizePrometheusMetricsName =
349+
public static final ConfigOption<Boolean> ENABLE_SANITIZED_PROMETHEUS_METRICS_NAME =
350350
ConfigOption.<Boolean>builder()
351351
.key("spark.kubernetes.operator.enableSanitizePrometheusMetricsName")
352352
.enableDynamicOverride(false)

spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/PrometheusPullModelHandler.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public PrometheusPullModelHandler(Properties properties, MetricRegistry registry
5858
super(properties, registry);
5959
this.registry = registry;
6060
this.enablePrometheusTextBasedFormat =
61-
SparkOperatorConf.EnablePrometheusTextBasedFormat.getValue();
61+
SparkOperatorConf.ENABLE_PROMETHEUS_TEXT_BASED_FORMAT.getValue();
6262
this.enableSanitizePrometheusMetricsName =
63-
SparkOperatorConf.EnableSanitizePrometheusMetricsName.getValue();
63+
SparkOperatorConf.ENABLE_SANITIZED_PROMETHEUS_METRICS_NAME.getValue();
6464
}
6565

6666
@Override
@@ -75,7 +75,7 @@ public void stop() {
7575

7676
@Override
7777
public void handle(HttpExchange exchange) throws IOException {
78-
if (SparkOperatorConf.EnablePrometheusTextBasedFormat.getValue()) {
78+
if (enablePrometheusTextBasedFormat) {
7979
sendMessage(
8080
exchange,
8181
HTTP_OK,
@@ -163,7 +163,7 @@ protected String formatGauge(String name, Gauge gauge) {
163163
+ "# TYPE "
164164
+ formattedName
165165
+ " gauge\n"
166-
+ sanitize(formattedName)
166+
+ formattedName
167167
+ ' '
168168
+ gauge.getValue()
169169
+ "\n\n";
@@ -173,13 +173,14 @@ protected String formatGauge(String name, Gauge gauge) {
173173

174174
protected String formatCounter(String name, Counter counter) {
175175
if (counter != null) {
176+
String formattedName = sanitize(name);
176177
return "# HELP "
177-
+ name
178+
+ formattedName
178179
+ " Counter metric\n"
179180
+ "# TYPE "
180-
+ name
181+
+ formattedName
181182
+ " counter\n"
182-
+ name
183+
+ formattedName
183184
+ " "
184185
+ counter.getCount()
185186
+ "\n\n";
@@ -351,7 +352,7 @@ protected double nanosToSeconds(double nanos) {
351352

352353
protected String sanitize(String name) {
353354
if (enableSanitizePrometheusMetricsName) {
354-
return name.replaceAll("[^a-zA-Z0-9_:]", "_").toLowerCase();
355+
return name.replaceAll("[^a-zA-Z0-9_]", "_").toLowerCase();
355356
}
356357
return name;
357358
}

0 commit comments

Comments
 (0)