Search in sources :

Example 26 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 27 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 28 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)

Example 29 with ServiceMetricEvent

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

the class MetricsEmittingQueryProcessingPoolTest method testPrioritizedExecutorDelegate.

@Test
public void testPrioritizedExecutorDelegate() {
    PrioritizedExecutorService service = Mockito.mock(PrioritizedExecutorService.class);
    Mockito.when(service.getQueueSize()).thenReturn(10);
    ExecutorServiceMonitor monitor = new ExecutorServiceMonitor();
    List<Event> events = new ArrayList<>();
    MetricsEmittingQueryProcessingPool processingPool = new MetricsEmittingQueryProcessingPool(service, monitor);
    Assert.assertSame(service, processingPool.delegate());
    ServiceEmitter serviceEmitter = new ServiceEmitter("service", "host", Mockito.mock(Emitter.class)) {

        @Override
        public void emit(Event event) {
            events.add(event);
        }
    };
    monitor.doMonitor(serviceEmitter);
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(((ServiceMetricEvent) (events.get(0))).getMetric(), "segment/scan/pending");
    Assert.assertEquals(((ServiceMetricEvent) (events.get(0))).getValue(), 10);
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) Emitter(org.apache.druid.java.util.emitter.core.Emitter) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) ArrayList(java.util.ArrayList) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Event(org.apache.druid.java.util.emitter.core.Event) Test(org.junit.Test)

Example 30 with ServiceMetricEvent

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

the class JettyServerModuleTest method testJettyServerModule.

@Test
public void testJettyServerModule() {
    List<Event> events = new ArrayList<>();
    ServiceEmitter serviceEmitter = new ServiceEmitter("service", "host", Mockito.mock(Emitter.class)) {

        @Override
        public void emit(Event event) {
            events.add(event);
        }
    };
    QueuedThreadPool jettyServerThreadPool = Mockito.mock(QueuedThreadPool.class);
    JettyServerModule.setJettyServerThreadPool(jettyServerThreadPool);
    Mockito.when(jettyServerThreadPool.getThreads()).thenReturn(100);
    Mockito.when(jettyServerThreadPool.getIdleThreads()).thenReturn(40);
    Mockito.when(jettyServerThreadPool.isLowOnThreads()).thenReturn(true);
    Mockito.when(jettyServerThreadPool.getMinThreads()).thenReturn(30);
    Mockito.when(jettyServerThreadPool.getMaxThreads()).thenReturn(100);
    Mockito.when(jettyServerThreadPool.getQueueSize()).thenReturn(50);
    Mockito.when(jettyServerThreadPool.getBusyThreads()).thenReturn(60);
    JettyServerModule.JettyMonitor jettyMonitor = new JettyServerModule.JettyMonitor("ds", "t0");
    jettyMonitor.doMonitor(serviceEmitter);
    Assert.assertEquals(8, events.size());
    List<Pair<String, Number>> expectedEvents = Arrays.asList(new Pair<>("jetty/numOpenConnections", 0), new Pair<>("jetty/threadPool/total", 100), new Pair<>("jetty/threadPool/idle", 40), new Pair<>("jetty/threadPool/isLowOnThreads", 1), new Pair<>("jetty/threadPool/min", 30), new Pair<>("jetty/threadPool/max", 100), new Pair<>("jetty/threadPool/queueSize", 50), new Pair<>("jetty/threadPool/busy", 60));
    for (int i = 0; i < expectedEvents.size(); i++) {
        Pair<String, Number> expected = expectedEvents.get(i);
        ServiceMetricEvent actual = (ServiceMetricEvent) (events.get(i));
        Assert.assertEquals(expected.lhs, actual.getMetric());
        Assert.assertEquals(expected.rhs, actual.getValue());
    }
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) Emitter(org.apache.druid.java.util.emitter.core.Emitter) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) ArrayList(java.util.ArrayList) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Event(org.apache.druid.java.util.emitter.core.Event) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Pair(org.apache.druid.java.util.common.Pair) Test(org.junit.Test)

Aggregations

ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)30 Test (org.junit.Test)26 DateTime (org.joda.time.DateTime)9 HashMap (java.util.HashMap)7 Emitter (org.apache.druid.java.util.emitter.core.Emitter)6 Event (org.apache.druid.java.util.emitter.core.Event)6 SpanData (io.opentelemetry.sdk.trace.data.SpanData)5 ServiceEventBuilder (org.apache.druid.java.util.emitter.service.ServiceEventBuilder)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Parameters (junitparams.Parameters)2 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)2 AlertEvent (org.apache.druid.java.util.emitter.service.AlertEvent)2 ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)2 ImmutableList (com.google.common.collect.ImmutableList)1