Search in sources :

Example 1 with Classification

use of io.crate.planner.operators.StatementClassifier.Classification in project crate by crate.

the class JobsLogsTest method testExecutionStart.

@Test
public void testExecutionStart() {
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    User user = User.of("arthur");
    Classification classification = new Classification(SELECT, Collections.singleton("Collect"));
    JobContext jobContext = new JobContext(UUID.randomUUID(), "select 1", 1L, user, classification);
    jobsLogs.logExecutionStart(jobContext.id(), jobContext.stmt(), user, classification);
    List<JobContext> jobsEntries = StreamSupport.stream(jobsLogs.activeJobs().spliterator(), false).collect(Collectors.toList());
    assertThat(jobsEntries.size(), is(1));
    assertThat(jobsEntries.get(0).username(), is(user.name()));
    assertThat(jobsEntries.get(0).stmt(), is("select 1"));
    assertThat(jobsEntries.get(0).classification(), is(classification));
}
Also used : User(io.crate.user.User) Classification(io.crate.planner.operators.StatementClassifier.Classification) JobContext(io.crate.expression.reference.sys.job.JobContext) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 2 with Classification

use of io.crate.planner.operators.StatementClassifier.Classification in project crate by crate.

the class JobsLogsTest method testExecutionFailureIsRecordedInMetrics.

@Test
public void testExecutionFailureIsRecordedInMetrics() {
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    User user = User.of("arthur");
    Queue<JobContextLog> q = new BlockingEvictingQueue<>(1);
    jobsLogs.updateJobsLog(new QueueSink<>(q, () -> {
    }));
    jobsLogs.logPreExecutionFailure(UUID.randomUUID(), "select foo", "stmt error", user);
    List<MetricsView> metrics = StreamSupport.stream(jobsLogs.metrics().spliterator(), false).collect(Collectors.toList());
    assertThat(metrics.size(), is(1));
    assertThat(metrics.get(0).failedCount(), is(1L));
    assertThat(metrics.get(0).totalCount(), is(1L));
    assertThat(metrics.get(0).classification(), is(new Classification(UNDEFINED)));
}
Also used : User(io.crate.user.User) JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) Classification(io.crate.planner.operators.StatementClassifier.Classification) BlockingEvictingQueue(io.crate.common.collections.BlockingEvictingQueue) MetricsView(io.crate.metadata.sys.MetricsView) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 3 with Classification

use of io.crate.planner.operators.StatementClassifier.Classification in project crate by crate.

the class JobsLogsTest method testRunningJobsAreNotLostOnSettingsChange.

@Test
public void testRunningJobsAreNotLostOnSettingsChange() throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool(2);
    Settings settings = Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), true).build();
    JobsLogService jobsLogService = new JobsLogService(settings, clusterService::localNode, clusterSettings, nodeCtx, scheduler, breakerService);
    JobsLogs jobsLogs = jobsLogService.get();
    Classification classification = new Classification(SELECT, Collections.singleton("Collect"));
    CountDownLatch latch = new CountDownLatch(2);
    AtomicBoolean doInsertJobs = new AtomicBoolean(true);
    AtomicInteger numJobs = new AtomicInteger();
    int maxQueueSize = JobsLogService.STATS_JOBS_LOG_SIZE_SETTING.getDefault(Settings.EMPTY);
    try {
        executor.submit(() -> {
            while (doInsertJobs.get() && numJobs.get() < maxQueueSize) {
                UUID uuid = UUID.randomUUID();
                int i = numJobs.getAndIncrement();
                jobsLogs.logExecutionStart(uuid, "select 1", User.CRATE_USER, classification);
                if (i % 2 == 0) {
                    jobsLogs.logExecutionEnd(uuid, null);
                } else {
                    jobsLogs.logPreExecutionFailure(uuid, "select 1", "failure", User.CRATE_USER);
                }
            }
            latch.countDown();
        });
        executor.submit(() -> {
            jobsLogService.updateJobSink(maxQueueSize + 10, JobsLogService.STATS_JOBS_LOG_EXPIRATION_SETTING.getDefault(Settings.EMPTY));
            doInsertJobs.set(false);
            latch.countDown();
        });
        latch.await(10, TimeUnit.SECONDS);
        assertThat(StreamSupport.stream(jobsLogs.jobsLog().spliterator(), false).count(), is((long) numJobs.get()));
    } finally {
        executor.shutdown();
        executor.awaitTermination(2, TimeUnit.SECONDS);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Classification(io.crate.planner.operators.StatementClassifier.Classification) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 4 with Classification

use of io.crate.planner.operators.StatementClassifier.Classification in project crate by crate.

the class JobsLogsTest method testExecutionFailure.

@Test
public void testExecutionFailure() {
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    User user = User.of("arthur");
    Queue<JobContextLog> q = new BlockingEvictingQueue<>(1);
    jobsLogs.updateJobsLog(new QueueSink<>(q, () -> {
    }));
    jobsLogs.logPreExecutionFailure(UUID.randomUUID(), "select foo", "stmt error", user);
    List<JobContextLog> jobsLogEntries = StreamSupport.stream(jobsLogs.jobsLog().spliterator(), false).collect(Collectors.toList());
    assertThat(jobsLogEntries.size(), is(1));
    assertThat(jobsLogEntries.get(0).username(), is(user.name()));
    assertThat(jobsLogEntries.get(0).statement(), is("select foo"));
    assertThat(jobsLogEntries.get(0).errorMessage(), is("stmt error"));
    assertThat(jobsLogEntries.get(0).classification(), is(new Classification(UNDEFINED)));
}
Also used : User(io.crate.user.User) JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) Classification(io.crate.planner.operators.StatementClassifier.Classification) BlockingEvictingQueue(io.crate.common.collections.BlockingEvictingQueue) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 5 with Classification

use of io.crate.planner.operators.StatementClassifier.Classification in project crate by crate.

the class JobsLogsTest method testLogsArentWipedOnSizeChange.

@Test
public void testLogsArentWipedOnSizeChange() {
    Settings settings = Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), true).build();
    JobsLogService stats = new JobsLogService(settings, clusterService::localNode, clusterSettings, nodeCtx, scheduler, breakerService);
    LogSink<JobContextLog> jobsLogSink = (LogSink<JobContextLog>) stats.get().jobsLog();
    LogSink<OperationContextLog> operationsLogSink = (LogSink<OperationContextLog>) stats.get().operationsLog();
    Classification classification = new Classification(SELECT, Collections.singleton("Collect"));
    jobsLogSink.add(new JobContextLog(new JobContext(UUID.randomUUID(), "select 1", 1L, User.CRATE_USER, classification), null));
    clusterSettings.applySettings(Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), true).put(JobsLogService.STATS_JOBS_LOG_SIZE_SETTING.getKey(), 200).build());
    assertThat(StreamSupport.stream(stats.get().jobsLog().spliterator(), false).count(), is(1L));
    operationsLogSink.add(new OperationContextLog(new OperationContext(1, UUID.randomUUID(), "foo", 2L, () -> -1), null));
    operationsLogSink.add(new OperationContextLog(new OperationContext(1, UUID.randomUUID(), "foo", 3L, () -> 1), null));
    clusterSettings.applySettings(Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), true).put(JobsLogService.STATS_OPERATIONS_LOG_SIZE_SETTING.getKey(), 1).build());
    assertThat(StreamSupport.stream(stats.get().operationsLog().spliterator(), false).count(), is(1L));
}
Also used : OperationContext(io.crate.expression.reference.sys.operation.OperationContext) OperationContextLog(io.crate.expression.reference.sys.operation.OperationContextLog) JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) Classification(io.crate.planner.operators.StatementClassifier.Classification) JobContext(io.crate.expression.reference.sys.job.JobContext) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

Classification (io.crate.planner.operators.StatementClassifier.Classification)6 Test (org.junit.Test)6 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)5 JobContextLog (io.crate.expression.reference.sys.job.JobContextLog)3 User (io.crate.user.User)3 BlockingEvictingQueue (io.crate.common.collections.BlockingEvictingQueue)2 JobContext (io.crate.expression.reference.sys.job.JobContext)2 MetricsView (io.crate.metadata.sys.MetricsView)2 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)2 Settings (org.elasticsearch.common.settings.Settings)2 OperationContext (io.crate.expression.reference.sys.operation.OperationContext)1 OperationContextLog (io.crate.expression.reference.sys.operation.OperationContextLog)1 StatementType (io.crate.planner.Plan.StatementType)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1