[HUDI-1305] Added an API to shutdown and remove the metrics reporter. (#2132)
This helps in removing reporter once the test has complete. Prevents log pollution from un-necessary metric logs. - Added an API to shutdown the metrics reporter after tests.
This commit is contained in:
@@ -68,5 +68,8 @@ public class ConsoleMetricsReporter extends MetricsReporter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
if (consoleReporter != null) {
|
||||||
|
consoleReporter.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ public class Metrics {
|
|||||||
reporter.start();
|
reporter.start();
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
reportAndCloseReporter();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reportAndCloseReporter() {
|
||||||
try {
|
try {
|
||||||
registerHoodieCommonMetrics();
|
registerHoodieCommonMetrics();
|
||||||
reporter.report();
|
reporter.report();
|
||||||
@@ -61,7 +66,6 @@ public class Metrics {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Error while closing reporter", e);
|
LOG.warn("Error while closing reporter", e);
|
||||||
}
|
}
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerHoodieCommonMetrics() {
|
private void registerHoodieCommonMetrics() {
|
||||||
@@ -85,6 +89,14 @@ public class Metrics {
|
|||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static synchronized void shutdown() {
|
||||||
|
if (!initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
metrics.reportAndCloseReporter();
|
||||||
|
initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
public static void registerGauges(Map<String, Long> metricsMap, Option<String> prefix) {
|
public static void registerGauges(Map<String, Long> metricsMap, Option<String> prefix) {
|
||||||
String metricPrefix = prefix.isPresent() ? prefix.get() + "." : "";
|
String metricPrefix = prefix.isPresent() ? prefix.get() + "." : "";
|
||||||
metricsMap.forEach((k, v) -> registerGauge(metricPrefix + k, v));
|
metricsMap.forEach((k, v) -> registerGauge(metricPrefix + k, v));
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package org.apache.hudi.metrics;
|
package org.apache.hudi.metrics;
|
||||||
|
|
||||||
import org.apache.hudi.config.HoodieWriteConfig;
|
import org.apache.hudi.config.HoodieWriteConfig;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -38,6 +39,11 @@ public class TestHoodieConsoleMetrics {
|
|||||||
new HoodieMetrics(config, "raw_table");
|
new HoodieMetrics(config, "raw_table");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void stop() {
|
||||||
|
Metrics.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegisterGauge() {
|
public void testRegisterGauge() {
|
||||||
registerGauge("metric1", 123L);
|
registerGauge("metric1", 123L);
|
||||||
|
|||||||
Reference in New Issue
Block a user