use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
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());
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class DimensionConverterTest method testConvert.
@Test
public void testConvert() {
DimensionConverter dimensionConverter = new DimensionConverter(new ObjectMapper(), null);
ServiceMetricEvent event = new ServiceMetricEvent.Builder().setDimension("dataSource", "data-source").setDimension("type", "groupBy").setDimension("interval", "2013/2015").setDimension("some_random_dim1", "random_dim_value1").setDimension("some_random_dim2", "random_dim_value2").setDimension("hasFilters", "no").setDimension("duration", "P1D").setDimension("remoteAddress", "194.0.90.2").setDimension("id", "ID").setDimension("context", "{context}").build(DateTimes.nowUtc(), "query/time", 10).build("broker", "brokerHost1");
ImmutableMap.Builder<String, String> actual = new ImmutableMap.Builder<>();
StatsDMetric statsDMetric = dimensionConverter.addFilteredUserDims(event.getService(), event.getMetric(), event.getUserDims(), actual);
Assert.assertEquals("correct StatsDMetric.Type", StatsDMetric.Type.timer, statsDMetric.type);
ImmutableMap.Builder<String, String> expected = new ImmutableMap.Builder<>();
expected.put("dataSource", "data-source");
expected.put("type", "groupBy");
Assert.assertEquals("correct Dimensions", expected.build(), actual.build());
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class EventConverterTest method testConvertWithoutNamespacePrefix.
@Test
public void testConvertWithoutNamespacePrefix() {
DateTime dateTime = DateTimes.nowUtc();
ServiceMetricEvent configuredEvent = new ServiceMetricEvent.Builder().setDimension("dataSource", "foo:bar").setDimension("type", "groupBy").build(dateTime, "query/time", 10).build("druid:broker", "127.0.0.1:8080");
Map<String, Object> expectedTags = new HashMap<>();
expectedTags.put("service", "druid_broker");
expectedTags.put("host", "127.0.0.1_8080");
expectedTags.put("dataSource", "foo_bar");
expectedTags.put("type", "groupBy");
OpentsdbEvent opentsdbEvent = converterWithoutNamespacePrefix.convert(configuredEvent);
Assert.assertEquals("query.time", opentsdbEvent.getMetric());
Assert.assertEquals(dateTime.getMillis() / 1000L, opentsdbEvent.getTimestamp());
Assert.assertEquals(10, opentsdbEvent.getValue());
Assert.assertEquals(expectedTags, opentsdbEvent.getTags());
ServiceMetricEvent notConfiguredEvent = new ServiceMetricEvent.Builder().setDimension("dataSource", "data-source").setDimension("type", "groupBy").build(dateTime, "foo/bar", 10).build("broker", "brokerHost1");
Assert.assertNull(converterWithoutNamespacePrefix.convert(notConfiguredEvent));
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class EventConverterTest method testConvertWithNamespacePrefix.
@Test
public void testConvertWithNamespacePrefix() {
DateTime dateTime = DateTimes.nowUtc();
ServiceMetricEvent configuredEvent = new ServiceMetricEvent.Builder().setDimension("dataSource", "foo:bar").setDimension("type", "groupBy").build(dateTime, "query/time", 10).build("druid:broker", "127.0.0.1:8080");
Map<String, Object> expectedTags = new HashMap<>();
expectedTags.put("service", "druid_broker");
expectedTags.put("host", "127.0.0.1_8080");
expectedTags.put("dataSource", "foo_bar");
expectedTags.put("type", "groupBy");
OpentsdbEvent opentsdbEvent = converterWithNamespacePrefix.convert(configuredEvent);
Assert.assertEquals("druid.query.time", opentsdbEvent.getMetric());
Assert.assertEquals(dateTime.getMillis() / 1000L, opentsdbEvent.getTimestamp());
Assert.assertEquals(10, opentsdbEvent.getValue());
Assert.assertEquals(expectedTags, opentsdbEvent.getTags());
ServiceMetricEvent notConfiguredEvent = new ServiceMetricEvent.Builder().setDimension("dataSource", "data-source").setDimension("type", "groupBy").build(dateTime, "foo/bar", 10).build("broker", "brokerHost1");
Assert.assertNull(converterWithNamespacePrefix.convert(notConfiguredEvent));
}
Aggregations