Search in sources :

Example 36 with ServiceEmitter

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

the class EmitterModule method getServiceEmitter.

@Provides
@ManageLifecycle
public ServiceEmitter getServiceEmitter(@Self Supplier<DruidNode> configSupplier, Emitter emitter, @ExtraServiceDimensions Map<String, String> extraServiceDimensions) {
    final DruidNode config = configSupplier.get();
    log.info("Using emitter [%s] for metrics and alerts, with dimensions [%s].", emitter, extraServiceDimensions);
    final ServiceEmitter retVal = new ServiceEmitter(config.getServiceName(), config.getHostAndPortToUse(), emitter, ImmutableMap.copyOf(extraServiceDimensions));
    EmittingLogger.registerEmitter(retVal);
    return retVal;
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) DruidNode(org.apache.druid.server.DruidNode) ManageLifecycle(org.apache.druid.guice.ManageLifecycle) Provides(com.google.inject.Provides)

Example 37 with ServiceEmitter

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

the class KillSupervisorsCustomDuty method run.

@Override
public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) {
    long timestamp = System.currentTimeMillis() - retainDuration.getMillis();
    try {
        int supervisorRemoved = metadataSupervisorManager.removeTerminatedSupervisorsOlderThan(timestamp);
        ServiceEmitter emitter = params.getEmitter();
        emitter.emit(new ServiceMetricEvent.Builder().build("metadata/kill/supervisor/count", supervisorRemoved));
        log.info("Finished running KillSupervisors duty. Removed %,d supervisor specs", supervisorRemoved);
    } catch (Exception e) {
        log.error(e, "Failed to kill terminated supervisor metadata");
    }
    return params;
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter)

Example 38 with ServiceEmitter

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

the class BackgroundCachePopulatorTest method before.

@Before
public void before() {
    this.backgroundCachePopulator = new BackgroundCachePopulator(Execs.multiThreaded(2, "CachingQueryRunnerTest-%d"), JSON_MAPPER, new CachePopulatorStats(), -1);
    TopNQueryBuilder builder = new TopNQueryBuilder().dataSource("ds").dimension("top_dim").metric("imps").threshold(3).intervals("2011-01-05/2011-01-10").aggregators(AGGS).granularity(Granularities.ALL);
    this.query = builder.build();
    this.toolchest = new TopNQueryQueryToolChest(new TopNQueryConfig());
    List<Result> expectedRes = makeTopNResults(false, OBJECTS);
    this.closable = new AssertingClosable();
    final Sequence resultSeq = Sequences.wrap(Sequences.simple(expectedRes), new SequenceWrapper() {

        @Override
        public void before() {
            Assert.assertFalse(closable.isClosed());
        }

        @Override
        public void after(boolean isDone, Throwable thrown) {
            closable.close();
        }
    });
    this.baseRunner = (queryPlus, responseContext) -> resultSeq;
    this.cache = new Cache() {

        private final ConcurrentMap<NamedKey, byte[]> baseMap = new ConcurrentHashMap<>();

        @Override
        public byte[] get(NamedKey key) {
            return baseMap.get(key);
        }

        @Override
        public void put(NamedKey key, byte[] value) {
            baseMap.put(key, value);
        }

        @Override
        public Map<NamedKey, byte[]> getBulk(Iterable<NamedKey> keys) {
            return null;
        }

        @Override
        public void close(String namespace) {
        }

        @Override
        public void close() {
        }

        @Override
        public CacheStats getStats() {
            return null;
        }

        @Override
        public boolean isLocal() {
            return true;
        }

        @Override
        public void doMonitor(ServiceEmitter emitter) {
        }
    };
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) SequenceWrapper(org.apache.druid.java.util.common.guava.SequenceWrapper) Sequence(org.apache.druid.java.util.common.guava.Sequence) Result(org.apache.druid.query.Result) TopNQueryConfig(org.apache.druid.query.topn.TopNQueryConfig) TopNQueryQueryToolChest(org.apache.druid.query.topn.TopNQueryQueryToolChest) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Before(org.junit.Before)

Example 39 with ServiceEmitter

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

the class LookupCoordinatorManagerTest method setUpStatic.

@BeforeClass
public static void setUpStatic() {
    LoggingEmitter loggingEmitter = EasyMock.createNiceMock(LoggingEmitter.class);
    EasyMock.replay(loggingEmitter);
    SERVICE_EMITTER = new ServiceEmitter("", "", loggingEmitter) {

        @Override
        public void emit(Event event) {
            EVENT_EMITS.incrementAndGet();
            super.emit(event);
        }
    };
    EmittingLogger.registerEmitter(SERVICE_EMITTER);
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) Event(org.apache.druid.java.util.emitter.core.Event) LoggingEmitter(org.apache.druid.java.util.emitter.core.LoggingEmitter) BeforeClass(org.junit.BeforeClass)

Example 40 with ServiceEmitter

use of org.apache.druid.java.util.emitter.service.ServiceEmitter 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

ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)45 Test (org.junit.Test)24 Before (org.junit.Before)9 Event (org.apache.druid.java.util.emitter.core.Event)8 CachingEmitter (org.apache.druid.query.CachingEmitter)8 DefaultQueryMetricsTest (org.apache.druid.query.DefaultQueryMetricsTest)8 ArrayList (java.util.ArrayList)7 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)7 Map (java.util.Map)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 List (java.util.List)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)5 DruidNode (org.apache.druid.server.DruidNode)5 DataSegment (org.apache.druid.timeline.DataSegment)5 Interval (org.joda.time.Interval)5 ImmutableSet (com.google.common.collect.ImmutableSet)4