xushiyan commented on code in PR #10068:
URL: https://github.com/apache/hudi/pull/10068#discussion_r1396218265
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metrics/prometheus/PrometheusReporter.java:
##########
@@ -18,42 +18,75 @@
package org.apache.hudi.metrics.prometheus;
+import org.apache.hudi.common.util.StringUtils;
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.metrics.MetricsReporter;
import com.codahale.metrics.MetricRegistry;
+import io.prometheus.client.Collector;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.dropwizard.DropwizardExports;
+import io.prometheus.client.dropwizard.samplebuilder.DefaultSampleBuilder;
+import io.prometheus.client.dropwizard.samplebuilder.SampleBuilder;
import io.prometheus.client.exporter.HTTPServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
/**
* Implementation of Prometheus reporter, which connects to the Http server,
and get metrics
* from that server.
*/
public class PrometheusReporter extends MetricsReporter {
+ private static final Pattern LABEL_PATTERN = Pattern.compile("\\s*,\\s*");
private static final Logger LOG =
LoggerFactory.getLogger(PrometheusReporter.class);
+ private static final Map<Integer, CollectorRegistry>
PORT_TO_COLLECTOR_REGISTRY = new HashMap<>();
+ private static final Map<Integer, HTTPServer> PORT_TO_SERVER = new
HashMap<>();
- private HTTPServer httpServer;
private final DropwizardExports metricExports;
private final CollectorRegistry collectorRegistry;
public PrometheusReporter(HoodieWriteConfig config, MetricRegistry registry)
{
int serverPort = config.getPrometheusPort();
- collectorRegistry = new CollectorRegistry();
- metricExports = new DropwizardExports(registry);
+ if (!PORT_TO_SERVER.containsKey(serverPort) ||
!PORT_TO_COLLECTOR_REGISTRY.containsKey(serverPort)) {
+ startHttpServer(serverPort);
+ }
+ List<String> labelNames = new ArrayList<>();
+ List<String> labelValues = new ArrayList<>();
+ if (!StringUtils.isNullOrEmpty(config.getPushGatewayLabels())) {
Review Comment:
nit: StringUtils.nonEmpty()
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metrics/prometheus/PrometheusReporter.java:
##########
@@ -18,42 +18,75 @@
package org.apache.hudi.metrics.prometheus;
+import org.apache.hudi.common.util.StringUtils;
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.metrics.MetricsReporter;
import com.codahale.metrics.MetricRegistry;
+import io.prometheus.client.Collector;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.dropwizard.DropwizardExports;
+import io.prometheus.client.dropwizard.samplebuilder.DefaultSampleBuilder;
+import io.prometheus.client.dropwizard.samplebuilder.SampleBuilder;
import io.prometheus.client.exporter.HTTPServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
/**
* Implementation of Prometheus reporter, which connects to the Http server,
and get metrics
* from that server.
*/
public class PrometheusReporter extends MetricsReporter {
+ private static final Pattern LABEL_PATTERN = Pattern.compile("\\s*,\\s*");
private static final Logger LOG =
LoggerFactory.getLogger(PrometheusReporter.class);
+ private static final Map<Integer, CollectorRegistry>
PORT_TO_COLLECTOR_REGISTRY = new HashMap<>();
+ private static final Map<Integer, HTTPServer> PORT_TO_SERVER = new
HashMap<>();
Review Comment:
no removal of the port upon reporter instance stop() ?
--
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]