[HUDI-209] Implement JMX metrics reporter (#1106)
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user