use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class HistoricalMetricsMonitorTest method testSimple.
@Test
public void testSimple() {
final long size = 5;
final String dataSource = "dataSource";
final DataSegment dataSegment = new DataSegment(dataSource, Intervals.of("2014/2015"), "version", ImmutableMap.of(), ImmutableList.of(), ImmutableList.of(), null, 1, size);
final long maxSize = 10;
final int priority = 111;
final String tier = "tier";
EasyMock.expect(druidServerConfig.getMaxSize()).andReturn(maxSize).once();
EasyMock.expect(segmentLoadDropMgr.getPendingDeleteSnapshot()).andReturn(ImmutableList.of(dataSegment)).once();
EasyMock.expect(druidServerConfig.getTier()).andReturn(tier).once();
EasyMock.expect(druidServerConfig.getPriority()).andReturn(priority).once();
EasyMock.expect(segmentManager.getDataSourceSizes()).andReturn(ImmutableMap.of(dataSource, size));
EasyMock.expect(druidServerConfig.getTier()).andReturn(tier).once();
EasyMock.expect(druidServerConfig.getPriority()).andReturn(priority).once();
EasyMock.expect(druidServerConfig.getMaxSize()).andReturn(maxSize).times(2);
EasyMock.expect(segmentManager.getDataSourceCounts()).andReturn(ImmutableMap.of(dataSource, 1L));
EasyMock.expect(druidServerConfig.getTier()).andReturn(tier).once();
EasyMock.expect(druidServerConfig.getPriority()).andReturn(priority).once();
final HistoricalMetricsMonitor monitor = new HistoricalMetricsMonitor(druidServerConfig, segmentManager, segmentLoadDropMgr);
final Capture<ServiceEventBuilder<ServiceMetricEvent>> eventCapture = EasyMock.newCapture(CaptureType.ALL);
serviceEmitter.emit(EasyMock.capture(eventCapture));
EasyMock.expectLastCall().times(5);
EasyMock.replay(druidServerConfig, segmentManager, segmentLoadDropMgr, serviceEmitter);
monitor.doMonitor(serviceEmitter);
EasyMock.verify(druidServerConfig, segmentManager, segmentLoadDropMgr, serviceEmitter);
final String host = "host";
final String service = "service";
Assert.assertTrue(eventCapture.hasCaptured());
final List<Map<String, Object>> events = Lists.transform(eventCapture.getValues(), new Function<ServiceEventBuilder<ServiceMetricEvent>, Map<String, Object>>() {
@Nullable
@Override
public Map<String, Object> apply(@Nullable ServiceEventBuilder<ServiceMetricEvent> input) {
final HashMap<String, Object> map = new HashMap<>(input.build(service, host).toMap());
Assert.assertNotNull(map.remove("feed"));
Assert.assertNotNull(map.remove("timestamp"));
Assert.assertNotNull(map.remove("service"));
Assert.assertNotNull(map.remove("host"));
return map;
}
});
Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/max", "value", maxSize), events.get(0));
Assert.assertEquals(ImmutableMap.<String, Object>of("dataSource", dataSource, "metric", "segment/pendingDelete", "priority", String.valueOf(priority), "tier", tier, "value", dataSegment.getSize()), events.get(1));
Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/used", "value", dataSegment.getSize(), "tier", tier, "priority", String.valueOf(priority), "dataSource", dataSource), events.get(2));
Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/usedPercent", "value", dataSegment.getSize() * 1.0D / maxSize, "tier", tier, "priority", String.valueOf(priority), "dataSource", dataSource), events.get(3));
Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/count", "value", 1L, "tier", tier, "priority", String.valueOf(priority), "dataSource", dataSource), events.get(4));
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class ShuffleMonitorTest method testDoMonitor.
@Test
public void testDoMonitor() {
final ShuffleMetrics shuffleMetrics = Mockito.mock(ShuffleMetrics.class);
final PerDatasourceShuffleMetrics perDatasourceShuffleMetrics = new PerDatasourceShuffleMetrics();
perDatasourceShuffleMetrics.accumulate(100);
perDatasourceShuffleMetrics.accumulate(200);
perDatasourceShuffleMetrics.accumulate(10);
Mockito.when(shuffleMetrics.snapshotAndReset()).thenReturn(ImmutableMap.of("supervisor", perDatasourceShuffleMetrics));
final StubServiceEmitter emitter = new StubServiceEmitter("service", "host");
final ShuffleMonitor monitor = new ShuffleMonitor();
monitor.setShuffleMetrics(shuffleMetrics);
Assert.assertTrue(monitor.doMonitor(emitter));
final List<Event> events = emitter.getEvents();
Assert.assertEquals(2, events.size());
Assert.assertSame(ServiceMetricEvent.class, events.get(0).getClass());
ServiceMetricEvent event = (ServiceMetricEvent) events.get(0);
Assert.assertEquals(ShuffleMonitor.SHUFFLE_BYTES_KEY, event.getMetric());
Assert.assertEquals(310L, event.getValue());
Assert.assertEquals(ImmutableMap.of(ShuffleMonitor.SUPERVISOR_TASK_ID_DIMENSION, "supervisor"), event.getUserDims());
Assert.assertSame(ServiceMetricEvent.class, events.get(1).getClass());
event = (ServiceMetricEvent) events.get(1);
Assert.assertEquals(ShuffleMonitor.SHUFFLE_REQUESTS_KEY, event.getMetric());
Assert.assertEquals(3, event.getValue());
Assert.assertEquals(ImmutableMap.of(ShuffleMonitor.SUPERVISOR_TASK_ID_DIMENSION, "supervisor"), event.getUserDims());
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class WhiteListBasedDruidToTimelineEventConverterTest method testDefaultIsInWhiteList.
@Test
@Parameters({ "query/time, true", "query/node/ttfb, true", "query/segmentAndCache/time, true", "query/time/balaba, true", "query/tim, false", "segment/added/bytes, true", "segment/count, true", "segment/size, true", "segment/cost/raw, false", "coordinator/TIER_1 /cost/raw, false", "segment/Kost/raw, false", ", false", "word, false", "coordinator, false", "server/, false", "ingest/persists/time, true", "jvm/mem/init, true", "jvm/gc/count, true" })
public void testDefaultIsInWhiteList(String key, boolean expectedValue) {
ServiceMetricEvent event = ServiceMetricEvent.builder().setFeed("metrics").build(createdTime, key, 10).build(serviceName, hostname);
boolean isIn = defaultWhiteListBasedDruidToTimelineEventConverter.druidEventToTimelineMetric(event) != null;
Assert.assertEquals(expectedValue, isIn);
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class InfluxdbEmitterTest method testTransformForInfluxWithShortMetric.
@Test
public void testTransformForInfluxWithShortMetric() {
DateTime date = new DateTime(2017, 10, 30, 10, 00, // 10:00am on 30/10/2017 = 1509357600000000000 in epoch nanoseconds
DateTimeZone.UTC);
String metric = "metric/time";
Number value = 1234;
ImmutableMap<String, String> serviceDims = ImmutableMap.of("service", "druid/historical", "host", "localhost", "version", "0.10.0");
ServiceMetricEvent.Builder builder = ServiceMetricEvent.builder();
ServiceEventBuilder eventBuilder = builder.build(date, metric, value);
ServiceMetricEvent event = (ServiceMetricEvent) eventBuilder.build(serviceDims);
InfluxdbEmitterConfig config = new InfluxdbEmitterConfig("localhost", 8086, null, null, null, null, "dbname", 10000, 15000, 30000, "adam", "password", null);
InfluxdbEmitter influxdbEmitter = new InfluxdbEmitter(config);
String expected = "druid_metric,service=druid/historical,hostname=localhost druid_time=1234 1509357600000000000" + "\n";
String actual = influxdbEmitter.transformForInfluxSystems(event);
Assert.assertEquals(expected, actual);
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class WhiteListBasedConverterTest method testDefaultIsInWhiteList.
@Test
@Parameters({ "query/time, true", "query/node/ttfb, true", "query/segmentAndCache/time, true", "query/time/balaba, true", "query/tim, false", "segment/added/bytes, false", "segment/count, true", "segment/size, true", "segment/cost/raw, false", "coordinator/TIER_1 /cost/raw, false", "segment/Kost/raw, false", ", false", "word, false", "coordinator, false", "server/, false", "ingest/persists/time, true", "jvm/mem/init, true", "jvm/gc/count, true" })
public void testDefaultIsInWhiteList(String key, boolean expectedValue) {
ServiceMetricEvent event = ServiceMetricEvent.builder().build(createdTime, key, 10).build(serviceName, hostname);
boolean isIn = defaultWhiteListBasedConverter.druidEventToGraphite(event) != null;
Assert.assertEquals(expectedValue, isIn);
}
Aggregations