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));
}
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)));
}
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);
}
}
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)));
}
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));
}
Aggregations