[HUDI-3148] Create pushgateway client based on port (#4497)
Co-authored-by: anoop narang <anoop.narang@navi.com> Co-authored-by: sivabalan narayanan <n.siva.b@gmail.com>
This commit is contained in:
@@ -50,7 +50,8 @@ public class PushGatewayMetricsReporter extends MetricsReporter {
|
|||||||
TimeUnit.SECONDS,
|
TimeUnit.SECONDS,
|
||||||
TimeUnit.SECONDS,
|
TimeUnit.SECONDS,
|
||||||
getJobName(),
|
getJobName(),
|
||||||
serverHost + ":" + serverPort,
|
serverHost,
|
||||||
|
serverPort,
|
||||||
deleteShutdown);
|
deleteShutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import com.codahale.metrics.ScheduledReporter;
|
|||||||
import io.prometheus.client.CollectorRegistry;
|
import io.prometheus.client.CollectorRegistry;
|
||||||
import io.prometheus.client.dropwizard.DropwizardExports;
|
import io.prometheus.client.dropwizard.DropwizardExports;
|
||||||
import io.prometheus.client.exporter.PushGateway;
|
import io.prometheus.client.exporter.PushGateway;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import org.apache.log4j.LogManager;
|
import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
@@ -51,17 +53,30 @@ public class PushGatewayReporter extends ScheduledReporter {
|
|||||||
TimeUnit rateUnit,
|
TimeUnit rateUnit,
|
||||||
TimeUnit durationUnit,
|
TimeUnit durationUnit,
|
||||||
String jobName,
|
String jobName,
|
||||||
String address,
|
String serverHost,
|
||||||
|
int serverPort,
|
||||||
boolean deleteShutdown) {
|
boolean deleteShutdown) {
|
||||||
super(registry, "hudi-push-gateway-reporter", filter, rateUnit, durationUnit);
|
super(registry, "hudi-push-gateway-reporter", filter, rateUnit, durationUnit);
|
||||||
this.jobName = jobName;
|
this.jobName = jobName;
|
||||||
this.deleteShutdown = deleteShutdown;
|
this.deleteShutdown = deleteShutdown;
|
||||||
collectorRegistry = new CollectorRegistry();
|
collectorRegistry = new CollectorRegistry();
|
||||||
metricExports = new DropwizardExports(registry);
|
metricExports = new DropwizardExports(registry);
|
||||||
pushGateway = new PushGateway(address);
|
pushGateway = createPushGatewayClient(serverHost, serverPort);
|
||||||
metricExports.register(collectorRegistry);
|
metricExports.register(collectorRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PushGateway createPushGatewayClient(String serverHost, int serverPort) {
|
||||||
|
if (serverPort == 443) {
|
||||||
|
try {
|
||||||
|
return new PushGateway(new URL("https://" + serverHost + ":" + serverPort));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new IllegalArgumentException("Malformed pushgateway host: " + serverHost);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new PushGateway(serverHost + ":" + serverPort);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void report(SortedMap<String, Gauge> gauges,
|
public void report(SortedMap<String, Gauge> gauges,
|
||||||
SortedMap<String, Counter> counters,
|
SortedMap<String, Counter> counters,
|
||||||
|
|||||||
Reference in New Issue
Block a user