advancedxy commented on code in PR #1991:
URL:
https://github.com/apache/incubator-uniffle/pull/1991#discussion_r1710614947
##########
common/src/main/java/org/apache/uniffle/common/metrics/MetricsManager.java:
##########
@@ -74,11 +78,37 @@ public Gauge addGauge(String name, String help, String[]
labels) {
return
Gauge.build().name(name).labelNames(labels).help(help).register(collectorRegistry);
}
+ public SupplierGauge addGauge(
Review Comment:
I think we can remove this method for now, as it's barely used.
##########
common/src/main/java/org/apache/uniffle/common/metrics/MetricsManager.java:
##########
@@ -33,6 +35,7 @@ public class MetricsManager {
private final String[] defaultLabelValues;
private static final double[] QUANTILES = {0.50, 0.75, 0.90, 0.95, 0.99};
private static final double QUANTILE_ERROR = 0.01;
+ private Map<String, SupplierGauge> gaugeMap;
Review Comment:
let's call it `supplierGauggeMap`?
##########
server/src/main/java/org/apache/uniffle/server/DefaultFlushEventHandler.java:
##########
@@ -178,6 +176,8 @@ protected void initFlushEventExecutor() {
hadoopThreadPoolExecutor = createFlushEventExecutor(poolSize,
"HadoopFlushEventThreadPool");
}
fallbackThreadPoolExecutor = createFlushEventExecutor(5,
"FallBackFlushEventThreadPool");
+ ShuffleServerMetrics.gaugeEventQueueSize =
+ ShuffleServerMetrics.addLabeledGauge(EVENT_QUEUE_SIZE, () -> (double)
flushQueue.size());
Review Comment:
It could be:
```
ShuffleServerMetrics.addLabeledGauge(EVENT_QUEUE_SIZE, () -> (double)
flushQueue.size());
```
##########
common/src/main/java/org/apache/uniffle/common/metrics/MetricsManager.java:
##########
@@ -47,6 +50,7 @@ public MetricsManager(CollectorRegistry collectorRegistry,
Map<String, String> d
this.defaultLabelNames = defaultLabels.keySet().toArray(new String[0]);
this.defaultLabelValues =
Arrays.stream(defaultLabelNames).map(defaultLabels::get).toArray(String[]::new);
+ this.gaugeMap = new ConcurrentHashMap<>();
Review Comment:
Use `this.gaugeMap = JavaUtils.newConcurrentMap();`
This is a performance issue in JDK8 for concurrent hash map, so we have to
wrap it with a special one.
##########
common/src/main/java/org/apache/uniffle/common/metrics/MetricsManager.java:
##########
@@ -74,11 +78,37 @@ public Gauge addGauge(String name, String help, String[]
labels) {
return
Gauge.build().name(name).labelNames(labels).help(help).register(collectorRegistry);
}
+ public SupplierGauge addGauge(
+ String name,
+ String help,
+ Supplier<Double> supplier,
+ String[] labelNames,
+ String[] labelValues) {
+ return gaugeMap.computeIfAbsent(
+ name,
+ metricName ->
+ new SupplierGauge(name, help, supplier, labelNames, labelValues)
+ .register(collectorRegistry));
+ }
+
public Gauge.Child addLabeledGauge(String name) {
Gauge c = addGauge(name, this.defaultLabelNames);
return c.labels(this.defaultLabelValues);
}
+ public SupplierGauge addLabeledGauge(String name, Supplier<Double> supplier)
{
Review Comment:
I'm prefer to not exposed SupplierGauge to outside. In other words, this
method should return void, and changed to something like:
```java
public void registerLabeledGauge(String name, Supplier<Double> supplier)
{...}
// or
public void addLabeledGauge(String name, Supplier<Double> supplier) {...}
```
##########
common/src/main/java/org/apache/uniffle/common/metrics/MetricsManager.java:
##########
@@ -112,4 +142,10 @@ public Summary.Child addLabeledSummary(String name) {
}
return builder.register(collectorRegistry).labels(defaultLabelValues);
}
+
+ public void unRegister() {
Review Comment:
hmm. This signature doesn't seem right.
It should be something like:
```java
public void unregisterSupplierGauge(String name)
```
?
##########
common/src/main/java/org/apache/uniffle/common/metrics/SupplierGauge.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.uniffle.common.metrics;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Supplier;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.GaugeMetricFamily;
+
+public class SupplierGauge extends Collector implements Collector.Describable {
Review Comment:
Like other comment pointed out, it can be package private, not public.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]