Search in sources :

Example 61 with ServiceMetricEvent

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());
}
Also used : TimelineMetric(org.apache.hadoop.metrics2.sink.timeline.TimelineMetric) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) File(java.io.File) Test(org.junit.Test)

Example 62 with ServiceMetricEvent

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());
}
Also used : ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 63 with ServiceMetricEvent

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));
}
Also used : HashMap(java.util.HashMap) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 64 with ServiceMetricEvent

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));
}
Also used : HashMap(java.util.HashMap) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)64 Test (org.junit.Test)56 DateTime (org.joda.time.DateTime)18 HashMap (java.util.HashMap)14 ServiceEventBuilder (org.apache.druid.java.util.emitter.service.ServiceEventBuilder)14 Emitter (org.apache.druid.java.util.emitter.core.Emitter)12 Event (org.apache.druid.java.util.emitter.core.Event)12 SpanData (io.opentelemetry.sdk.trace.data.SpanData)10 ImmutableMap (com.google.common.collect.ImmutableMap)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 OutputStream (java.io.OutputStream)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Parameters (junitparams.Parameters)4 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)4 AlertEvent (org.apache.druid.java.util.emitter.service.AlertEvent)4 ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)4 ImmutableList (com.google.common.collect.ImmutableList)2