1
0

[HUDI-209] Implement JMX metrics reporter (#1106)

This commit is contained in:
ForwardXu
2020-03-19 20:10:35 +08:00
committed by GitHub
parent 779edc0688
commit 1e321c2fc0
12 changed files with 295 additions and 45 deletions

View File

@@ -18,10 +18,8 @@
package org.apache.hudi.metrics;
import org.apache.hudi.config.HoodieMetricsConfig;
import org.apache.hudi.config.HoodieWriteConfig;
import org.junit.Before;
import org.junit.Test;
import static org.apache.hudi.metrics.Metrics.registerGauge;
@@ -34,20 +32,29 @@ import static org.mockito.Mockito.when;
*/
public class TestHoodieJmxMetrics {
@Before
public void start() {
HoodieWriteConfig config = mock(HoodieWriteConfig.class);
when(config.isMetricsOn()).thenReturn(true);
when(config.getMetricsReporterType()).thenReturn(MetricsReporterType.JMX);
when(config.getJmxHost()).thenReturn(HoodieMetricsConfig.DEFAULT_JMX_HOST);
when(config.getJmxPort()).thenReturn(HoodieMetricsConfig.DEFAULT_JMX_PORT);
new HoodieMetrics(config, "raw_table");
}
HoodieWriteConfig config = mock(HoodieWriteConfig.class);
@Test
public void testRegisterGauge() {
registerGauge("jmx_metric", 123L);
when(config.isMetricsOn()).thenReturn(true);
when(config.getMetricsReporterType()).thenReturn(MetricsReporterType.JMX);
when(config.getJmxHost()).thenReturn("localhost");
when(config.getJmxPort()).thenReturn("9889");
new HoodieMetrics(config, "raw_table");
registerGauge("jmx_metric1", 123L);
assertEquals("123", Metrics.getInstance().getRegistry().getGauges()
.get("jmx_metric").getValue().toString());
.get("jmx_metric1").getValue().toString());
}
@Test
public void testRegisterGaugeByRangerPort() {
when(config.isMetricsOn()).thenReturn(true);
when(config.getMetricsReporterType()).thenReturn(MetricsReporterType.JMX);
when(config.getJmxHost()).thenReturn("localhost");
when(config.getJmxPort()).thenReturn("1000-5000");
new HoodieMetrics(config, "raw_table");
registerGauge("jmx_metric2", 123L);
assertEquals("123", Metrics.getInstance().getRegistry().getGauges()
.get("jmx_metric2").getValue().toString());
}
}