[HUDI-2213] Remove unnecessary parameter for HoodieMetrics constructor and fix NPE in UT (#3333)
This commit is contained in:
@@ -130,7 +130,7 @@ public abstract class AbstractHoodieWriteClient<T extends HoodieRecordPayload, I
|
||||
public AbstractHoodieWriteClient(HoodieEngineContext context, HoodieWriteConfig writeConfig,
|
||||
Option<EmbeddedTimelineService> timelineService) {
|
||||
super(context, writeConfig, timelineService);
|
||||
this.metrics = new HoodieMetrics(config, config.getTableName());
|
||||
this.metrics = new HoodieMetrics(config);
|
||||
this.index = createIndex(writeConfig);
|
||||
this.txnManager = new TransactionManager(config, fs);
|
||||
}
|
||||
|
||||
@@ -54,9 +54,9 @@ public class HoodieMetrics {
|
||||
private Timer clusteringTimer = null;
|
||||
private Timer indexTimer = null;
|
||||
|
||||
public HoodieMetrics(HoodieWriteConfig config, String tableName) {
|
||||
public HoodieMetrics(HoodieWriteConfig config) {
|
||||
this.config = config;
|
||||
this.tableName = tableName;
|
||||
this.tableName = config.getTableName();
|
||||
if (config.isMetricsOn()) {
|
||||
Metrics.init(config);
|
||||
this.rollbackTimerName = getMetricsName("timer", HoodieTimeline.ROLLBACK_ACTION);
|
||||
|
||||
@@ -53,9 +53,7 @@ public class Metrics {
|
||||
}
|
||||
reporter.start();
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
reportAndCloseReporter();
|
||||
}));
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(this::reportAndCloseReporter));
|
||||
}
|
||||
|
||||
private void reportAndCloseReporter() {
|
||||
|
||||
@@ -41,20 +41,20 @@ public class MetricsReporterFactory {
|
||||
private static final Logger LOG = LogManager.getLogger(MetricsReporterFactory.class);
|
||||
|
||||
public static MetricsReporter createReporter(HoodieWriteConfig config, MetricRegistry registry) {
|
||||
MetricsReporterType type = config.getMetricsReporterType();
|
||||
MetricsReporter reporter = null;
|
||||
String reporterClassName = config.getMetricReporterClassName();
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(config.getMetricReporterClassName())) {
|
||||
Object instance = ReflectionUtils
|
||||
.loadClass(config.getMetricReporterClassName(),
|
||||
new Class<?>[] {Properties.class, MetricRegistry.class}, config.getProps(), registry);
|
||||
if (!StringUtils.isNullOrEmpty(reporterClassName)) {
|
||||
Object instance = ReflectionUtils.loadClass(
|
||||
reporterClassName, new Class<?>[] {Properties.class, MetricRegistry.class}, config.getProps(), registry);
|
||||
if (!(instance instanceof AbstractUserDefinedMetricsReporter)) {
|
||||
throw new HoodieException(config.getMetricReporterClassName()
|
||||
+ " is not a subclass of AbstractUserDefinedMetricsReporter");
|
||||
+ " is not a subclass of AbstractUserDefinedMetricsReporter");
|
||||
}
|
||||
return (MetricsReporter) instance;
|
||||
}
|
||||
|
||||
MetricsReporterType type = config.getMetricsReporterType();
|
||||
MetricsReporter reporter = null;
|
||||
switch (type) {
|
||||
case GRAPHITE:
|
||||
reporter = new MetricsGraphiteReporter(config, registry);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TestHoodieConsoleMetrics {
|
||||
when(config.getTableName()).thenReturn("console_metrics_test");
|
||||
when(config.isMetricsOn()).thenReturn(true);
|
||||
when(config.getMetricsReporterType()).thenReturn(MetricsReporterType.CONSOLE);
|
||||
new HoodieMetrics(config, "raw_table");
|
||||
new HoodieMetrics(config);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
||||
@@ -52,7 +52,7 @@ public class TestHoodieJmxMetrics {
|
||||
when(config.getMetricsReporterType()).thenReturn(MetricsReporterType.JMX);
|
||||
when(config.getJmxHost()).thenReturn("localhost");
|
||||
when(config.getJmxPort()).thenReturn(String.valueOf(NetworkTestUtils.nextFreePort()));
|
||||
new HoodieMetrics(config, "raw_table");
|
||||
new HoodieMetrics(config);
|
||||
registerGauge("jmx_metric1", 123L);
|
||||
assertEquals("123", Metrics.getInstance().getRegistry().getGauges()
|
||||
.get("jmx_metric1").getValue().toString());
|
||||
@@ -65,7 +65,7 @@ public class TestHoodieJmxMetrics {
|
||||
when(config.getMetricsReporterType()).thenReturn(MetricsReporterType.JMX);
|
||||
when(config.getJmxHost()).thenReturn("localhost");
|
||||
when(config.getJmxPort()).thenReturn(String.valueOf(NetworkTestUtils.nextFreePort()));
|
||||
new HoodieMetrics(config, "raw_table");
|
||||
new HoodieMetrics(config);
|
||||
registerGauge("jmx_metric2", 123L);
|
||||
assertEquals("123", Metrics.getInstance().getRegistry().getGauges()
|
||||
.get("jmx_metric2").getValue().toString());
|
||||
|
||||
@@ -50,8 +50,9 @@ public class TestHoodieMetrics {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
when(config.isMetricsOn()).thenReturn(true);
|
||||
when(config.getTableName()).thenReturn("raw_table");
|
||||
when(config.getMetricsReporterType()).thenReturn(MetricsReporterType.INMEMORY);
|
||||
metrics = new HoodieMetrics(config, "raw_table");
|
||||
metrics = new HoodieMetrics(config);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
||||
@@ -46,10 +46,11 @@ public class TestPrometheusReporter {
|
||||
@Test
|
||||
public void testRegisterGauge() {
|
||||
when(config.isMetricsOn()).thenReturn(true);
|
||||
when(config.getTableName()).thenReturn("foo");
|
||||
when(config.getMetricsReporterType()).thenReturn(MetricsReporterType.PROMETHEUS);
|
||||
when(config.getPrometheusPort()).thenReturn(9090);
|
||||
assertDoesNotThrow(() -> {
|
||||
new HoodieMetrics(config, "raw_table");
|
||||
new HoodieMetrics(config);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ public class TestPushGateWayReporter {
|
||||
@Test
|
||||
public void testRegisterGauge() {
|
||||
when(config.isMetricsOn()).thenReturn(true);
|
||||
when(config.getTableName()).thenReturn("foo");
|
||||
when(config.getMetricsReporterType()).thenReturn(MetricsReporterType.PROMETHEUS_PUSHGATEWAY);
|
||||
when(config.getPushGatewayHost()).thenReturn("localhost");
|
||||
when(config.getPushGatewayPort()).thenReturn(9091);
|
||||
@@ -57,7 +58,7 @@ public class TestPushGateWayReporter {
|
||||
when(config.getPushGatewayRandomJobNameSuffix()).thenReturn(false);
|
||||
|
||||
assertDoesNotThrow(() -> {
|
||||
new HoodieMetrics(config, "raw_table");
|
||||
new HoodieMetrics(config);
|
||||
});
|
||||
|
||||
registerGauge("pushGateWayReporter_metric", 123L);
|
||||
|
||||
Reference in New Issue
Block a user