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);
}
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 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 EmitClusterStatsAndMetricsTest method testRunEmitStatsForCompactionWhenHaveCompactSegmentDuty.
@Test
public void testRunEmitStatsForCompactionWhenHaveCompactSegmentDuty() {
String groupName = "blah";
ArgumentCaptor<ServiceEventBuilder> argumentCaptor = ArgumentCaptor.forClass(ServiceEventBuilder.class);
Mockito.when(mockDruidCoordinatorRuntimeParams.getEmitter()).thenReturn(mockServiceEmitter);
Mockito.when(mockDruidCoordinatorRuntimeParams.getCoordinatorStats()).thenReturn(mockCoordinatorStats);
Mockito.when(mockDruidCoordinatorRuntimeParams.getDruidCluster()).thenReturn(mockDruidCluster);
CoordinatorDuty duty = new EmitClusterStatsAndMetrics(mockDruidCoordinator, groupName, true);
duty.run(mockDruidCoordinatorRuntimeParams);
Mockito.verify(mockServiceEmitter, Mockito.atLeastOnce()).emit(argumentCaptor.capture());
List<ServiceEventBuilder> emittedEvents = argumentCaptor.getAllValues();
boolean foundCompactMetric = false;
boolean foundHistoricalDutyMetric = false;
for (ServiceEventBuilder eventBuilder : emittedEvents) {
ServiceMetricEvent serviceMetricEvent = ((ServiceMetricEvent) eventBuilder.build("x", "x"));
String metric = serviceMetricEvent.getMetric();
if ("segment/overShadowed/count".equals(metric)) {
foundHistoricalDutyMetric = true;
} else if ("compact/task/count".equals(metric)) {
foundCompactMetric = true;
}
String dutyGroup = (String) serviceMetricEvent.getUserDims().get("dutyGroup");
Assert.assertNotNull(dutyGroup);
Assert.assertEquals(groupName, dutyGroup);
}
Assert.assertFalse(foundHistoricalDutyMetric);
Assert.assertTrue(foundCompactMetric);
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class WhiteListBasedDruidToTimelineEventConverterTest method testWhiteListedStringArrayDimension.
@Test
public void testWhiteListedStringArrayDimension() throws IOException {
File mapFile = File.createTempFile("testing-" + System.nanoTime(), ".json");
mapFile.deleteOnExit();
try (OutputStream outputStream = new FileOutputStream(mapFile)) {
IOUtils.copyLarge(getClass().getResourceAsStream("/testWhiteListedStringArrayDimension.json"), outputStream);
}
WhiteListBasedDruidToTimelineEventConverter converter = new WhiteListBasedDruidToTimelineEventConverter(prefix, "druid", mapFile.getAbsolutePath(), new DefaultObjectMapper());
ServiceMetricEvent event = new ServiceMetricEvent.Builder().setDimension("gcName", new String[] { "g1" }).build(createdTime, "jvm/gc/cpu", 10).build(serviceName, hostname);
TimelineMetric metric = converter.druidEventToTimelineMetric(event);
Assert.assertNotNull(metric);
Assert.assertEquals(defaultNamespace + ".g1.jvm/gc/cpu", metric.getMetricName());
}
Aggregations