Search in sources :

Example 56 with ServiceMetricEvent

use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class OpenTelemetryEmitterTest method testNoEmitNotServiceMetric.

// Check that we don't call "emitQueryTimeEvent" method for event that is not instance of ServiceMetricEvent
@Test
public void testNoEmitNotServiceMetric() {
    final Event notServiceMetricEvent = new Event() {

        @Override
        public Map<String, Object> toMap() {
            return Collections.emptyMap();
        }

        @Override
        public String getFeed() {
            return null;
        }
    };
    emitter.emit(notServiceMetricEvent);
    Assert.assertNull(noopExporter.spanDataCollection);
}
Also used : ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Event(org.apache.druid.java.util.emitter.core.Event) Test(org.junit.Test)

Example 57 with ServiceMetricEvent

use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class OpenTelemetryEmitterTest method testAttributes.

@Test
public void testAttributes() {
    final Map<String, String> context = new HashMap<>();
    final String expectedAttributeKey = "attribute";
    final String expectedAttributeValue = "value";
    context.put(expectedAttributeKey, expectedAttributeValue);
    final ServiceMetricEvent queryTimeMetricWithAttributes = new ServiceMetricEvent.Builder().setDimension("context", context).build(TIMESTAMP, "query/time", 100).build("druid/broker", "host");
    emitter.emit(queryTimeMetricWithAttributes);
    SpanData actualSpanData = noopExporter.spanDataCollection.iterator().next();
    Assert.assertEquals(1, actualSpanData.getAttributes().size());
    Assert.assertEquals(expectedAttributeValue, actualSpanData.getAttributes().get(AttributeKey.stringKey(expectedAttributeKey)));
}
Also used : SpanData(io.opentelemetry.sdk.trace.data.SpanData) HashMap(java.util.HashMap) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Test(org.junit.Test)

Example 58 with ServiceMetricEvent

use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class OpenTelemetryEmitterTest method testErrorStatus.

@Test
public void testErrorStatus() {
    final ServiceMetricEvent queryTimeMetric = new ServiceMetricEvent.Builder().setDimension("success", "false").build(TIMESTAMP, "query/time", 100).build("druid/broker", "host");
    emitter.emit(queryTimeMetric);
    SpanData actualSpanData = noopExporter.spanDataCollection.iterator().next();
    Assert.assertEquals(StatusCode.ERROR, actualSpanData.getStatus().getStatusCode());
}
Also used : SpanData(io.opentelemetry.sdk.trace.data.SpanData) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Test(org.junit.Test)

Example 59 with ServiceMetricEvent

use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class DropwizardEmitter method emit.

@Override
public void emit(Event event) {
    synchronized (started) {
        if (!started.get()) {
            throw new RejectedExecutionException("Dropwizard emitter Service not started.");
        }
    }
    if (event instanceof ServiceMetricEvent) {
        ServiceMetricEvent metricEvent = (ServiceMetricEvent) event;
        String host = metricEvent.getHost();
        String service = metricEvent.getService();
        String metric = metricEvent.getMetric();
        Map<String, Object> userDims = metricEvent.getUserDims();
        Number value = metricEvent.getValue();
        ImmutableList.Builder<String> nameBuilder = new ImmutableList.Builder<>();
        LinkedHashMap<String, String> dims = new LinkedHashMap<>();
        final DropwizardMetricSpec metricSpec = converter.addFilteredUserDims(service, metric, userDims, dims);
        if (metricSpec != null) {
            if (config.getPrefix() != null) {
                nameBuilder.add(config.getPrefix());
            }
            nameBuilder.add(StringUtils.format("metric=%s", metric));
            nameBuilder.add(StringUtils.format("service=%s", service));
            if (config.getIncludeHost()) {
                nameBuilder.add(StringUtils.format("hostname=%s", host));
            }
            dims.forEach((key, value1) -> nameBuilder.add(StringUtils.format("%s=%s", key, value1)));
            String fullName = StringUtils.replaceChar(Joiner.on(",").join(nameBuilder.build()), '/', ".");
            updateMetric(fullName, value, metricSpec);
        } else {
            log.debug("Service=[%s], Metric=[%s] has no mapping", service, metric);
        }
    } else if (event instanceof AlertEvent) {
        for (Emitter emitter : alertEmitters) {
            emitter.emit(event);
        }
    } else {
        throw new ISE("unknown event type [%s]", event.getClass());
    }
}
Also used : Emitter(org.apache.druid.java.util.emitter.core.Emitter) ImmutableList(com.google.common.collect.ImmutableList) AlertEvent(org.apache.druid.java.util.emitter.service.AlertEvent) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) LinkedHashMap(java.util.LinkedHashMap) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) ISE(org.apache.druid.java.util.common.ISE)

Example 60 with ServiceMetricEvent

use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class WhiteListBasedConverterTest 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);
    }
    WhiteListBasedConverter converter = new WhiteListBasedConverter(prefix, false, false, false, mapFile.getAbsolutePath(), new DefaultObjectMapper());
    ServiceMetricEvent event = new ServiceMetricEvent.Builder().setDimension("gcName", new String[] { "g1" }).build(createdTime, "jvm/gc/cpu", 10).build(serviceName, hostname);
    GraphiteEvent graphiteEvent = converter.druidEventToGraphite(event);
    Assert.assertNotNull(graphiteEvent);
    Assert.assertEquals(defaultNamespace + ".g1.jvm/gc/cpu", graphiteEvent.getEventPath());
}
Also used : 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)

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