Search in sources :

Example 31 with ServiceEmitter

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

the class PendingTaskBasedProvisioningStrategyTest method testProvisionAlert.

@Test
public void testProvisionAlert() throws Exception {
    ServiceEmitter emitter = EasyMock.createMock(ServiceEmitter.class);
    EmittingLogger.registerEmitter(emitter);
    emitter.emit(EasyMock.<ServiceEventBuilder>anyObject());
    EasyMock.expectLastCall();
    EasyMock.replay(emitter);
    EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(1).times(3);
    EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(2).times(1);
    EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(new ArrayList<String>()).times(2);
    EasyMock.expect(autoScaler.terminateWithIds(EasyMock.anyObject())).andReturn(null);
    EasyMock.expect(autoScaler.provision()).andReturn(new AutoScalingData(Collections.singletonList("fake")));
    EasyMock.replay(autoScaler);
    RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
    EasyMock.expect(runner.getPendingTaskPayloads()).andReturn(Collections.singletonList(NoopTask.create())).times(2);
    EasyMock.expect(runner.getWorkers()).andReturn(Arrays.asList(new TestZkWorker(testTask, "http", "hi", "lo", MIN_VERSION, 1).toImmutable(), // Invalid version node
    new TestZkWorker(testTask, "http", "h1", "n1", INVALID_VERSION).toImmutable(), // Invalid version node
    new TestZkWorker(testTask, "http", "h2", "n1", INVALID_VERSION).toImmutable())).times(2);
    EasyMock.expect(runner.getConfig()).andReturn(new RemoteTaskRunnerConfig());
    EasyMock.replay(runner);
    Provisioner provisioner = strategy.makeProvisioner(runner);
    boolean provisionedSomething = provisioner.doProvision();
    Assert.assertTrue(provisionedSomething);
    Assert.assertTrue(provisioner.getStats().toList().size() == 1);
    DateTime createdTime = provisioner.getStats().toList().get(0).getTimestamp();
    Assert.assertTrue(provisioner.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.PROVISION);
    Thread.sleep(2000);
    provisionedSomething = provisioner.doProvision();
    Assert.assertFalse(provisionedSomething);
    Assert.assertTrue(provisioner.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.PROVISION);
    DateTime anotherCreatedTime = provisioner.getStats().toList().get(0).getTimestamp();
    Assert.assertTrue(createdTime.equals(anotherCreatedTime));
    EasyMock.verify(autoScaler);
    EasyMock.verify(emitter);
    EasyMock.verify(runner);
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) RemoteTaskRunner(org.apache.druid.indexing.overlord.RemoteTaskRunner) ArrayList(java.util.ArrayList) RemoteTaskRunnerConfig(org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 32 with ServiceEmitter

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

the class KafkaIndexTaskTest method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    emitter = new ServiceEmitter("service", "host", new NoopEmitter());
    emitter.start();
    EmittingLogger.registerEmitter(emitter);
    zkServer = new TestingCluster(1);
    zkServer.start();
    kafkaServer = new TestBroker(zkServer.getConnectString(), null, 1, ImmutableMap.of("num.partitions", "2"));
    kafkaServer.start();
    taskExec = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool(Execs.makeThreadFactory("kafka-task-test-%d")));
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) TestingCluster(org.apache.curator.test.TestingCluster) TestBroker(org.apache.druid.indexing.kafka.test.TestBroker) NoopEmitter(org.apache.druid.java.util.emitter.core.NoopEmitter) BeforeClass(org.junit.BeforeClass)

Example 33 with ServiceEmitter

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

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

the class KillDatasourceMetadata method run.

@Override
public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) {
    long currentTimeMillis = System.currentTimeMillis();
    if ((lastKillTime + period) < currentTimeMillis) {
        lastKillTime = currentTimeMillis;
        long timestamp = currentTimeMillis - retainDuration;
        try {
            // Datasource metadata only exists for datasource with supervisor
            // To determine if datasource metadata is still active, we check if the supervisor for that particular datasource
            // is still active or not
            Map<String, SupervisorSpec> allActiveSupervisor = metadataSupervisorManager.getLatestActiveOnly();
            Set<String> allDatasourceWithActiveSupervisor = allActiveSupervisor.values().stream().map(supervisorSpec -> supervisorSpec.getDataSources()).flatMap(Collection::stream).filter(datasource -> !Strings.isNullOrEmpty(datasource)).collect(Collectors.toSet());
            // We exclude removing datasource metadata with active supervisor
            int datasourceMetadataRemovedCount = indexerMetadataStorageCoordinator.removeDataSourceMetadataOlderThan(timestamp, allDatasourceWithActiveSupervisor);
            ServiceEmitter emitter = params.getEmitter();
            emitter.emit(new ServiceMetricEvent.Builder().build("metadata/kill/datasource/count", datasourceMetadataRemovedCount));
            log.info("Finished running KillDatasourceMetadata duty. Removed %,d datasource metadata", datasourceMetadataRemovedCount);
        } catch (Exception e) {
            log.error(e, "Failed to kill datasource metadata");
        }
    }
    return params;
}
Also used : Logger(org.apache.druid.java.util.common.logger.Logger) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Inject(com.google.inject.Inject) Collection(java.util.Collection) DruidCoordinatorRuntimeParams(org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams) Set(java.util.Set) Collectors(java.util.stream.Collectors) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) Strings(com.google.common.base.Strings) MetadataSupervisorManager(org.apache.druid.metadata.MetadataSupervisorManager) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) DruidCoordinatorConfig(org.apache.druid.server.coordinator.DruidCoordinatorConfig) Map(java.util.Map) IndexerMetadataStorageCoordinator(org.apache.druid.indexing.overlord.IndexerMetadataStorageCoordinator) Preconditions(com.google.common.base.Preconditions) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) Collection(java.util.Collection) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec)

Example 35 with ServiceEmitter

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

the class KillSupervisors method run.

@Override
public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) {
    long currentTimeMillis = System.currentTimeMillis();
    if ((lastKillTime + period) < currentTimeMillis) {
        lastKillTime = currentTimeMillis;
        long timestamp = currentTimeMillis - retainDuration;
        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)

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