Search in sources :

Example 1 with JobContextLog

use of io.crate.expression.reference.sys.job.JobContextLog 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 2 with JobContextLog

use of io.crate.expression.reference.sys.job.JobContextLog in project crate by crate.

the class JobsLogsTest method testReEnableStats.

@Test
public void testReEnableStats() {
    clusterService.getClusterSettings().applySettings(Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), false).build());
    Settings settings = Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), false).put(JobsLogService.STATS_JOBS_LOG_SIZE_SETTING.getKey(), 100).put(JobsLogService.STATS_OPERATIONS_LOG_SIZE_SETTING.getKey(), 100).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();
    assertThat(stats.isEnabled(), is(false));
    assertThat(stats.jobsLogSize, is(100));
    assertThat(jobsLogSink, Matchers.instanceOf(NoopLogSink.class));
    assertThat(stats.operationsLogSize, is(100));
    assertThat(operationsLogSink, Matchers.instanceOf(NoopLogSink.class));
    clusterService.getClusterSettings().applySettings(Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), true).build());
    assertThat(stats.isEnabled(), is(true));
    assertThat(stats.jobsLogSize, is(100));
    assertThat(stats.get().jobsLog(), Matchers.instanceOf(FilteredLogSink.class));
    assertThat(stats.operationsLogSize, is(100));
    assertThat(stats.get().operationsLog(), Matchers.instanceOf(QueueSink.class));
}
Also used : OperationContextLog(io.crate.expression.reference.sys.operation.OperationContextLog) JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 3 with JobContextLog

use of io.crate.expression.reference.sys.job.JobContextLog in project crate by crate.

the class JobsLogsTest method testEntriesCanBeRejectedWithFilter.

@Test
public void testEntriesCanBeRejectedWithFilter() {
    Settings settings = Settings.builder().put(JobsLogService.STATS_JOBS_LOG_FILTER.getKey(), "stmt like 'select%'").build();
    JobsLogService stats = new JobsLogService(settings, clusterService::localNode, clusterSettings, nodeCtx, scheduler, breakerService);
    LogSink<JobContextLog> jobsLogSink = (LogSink<JobContextLog>) stats.get().jobsLog();
    jobsLogSink.add(new JobContextLog(new JobContext(UUID.randomUUID(), "insert into", 10L, User.CRATE_USER, null), null, 20L));
    jobsLogSink.add(new JobContextLog(new JobContext(UUID.randomUUID(), "select * from t1", 10L, User.CRATE_USER, null), null, 20L));
    assertThat(StreamSupport.stream(jobsLogSink.spliterator(), false).count(), is(1L));
}
Also used : JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) 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)

Example 4 with JobContextLog

use of io.crate.expression.reference.sys.job.JobContextLog in project crate by crate.

the class JobsLogsTest method testSettingsChanges.

@Test
public void testSettingsChanges() throws Exception {
    Settings settings = Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), true).put(JobsLogService.STATS_JOBS_LOG_SIZE_SETTING.getKey(), 100).put(JobsLogService.STATS_OPERATIONS_LOG_SIZE_SETTING.getKey(), 100).build();
    JobsLogService stats = new JobsLogService(settings, clusterService::localNode, clusterSettings, nodeCtx, scheduler, breakerService);
    Supplier<LogSink<JobContextLog>> jobsLogSink = () -> (LogSink<JobContextLog>) stats.get().jobsLog();
    Supplier<LogSink<OperationContextLog>> operationsLogSink = () -> (LogSink<OperationContextLog>) stats.get().operationsLog();
    // sinks are still of type QueueSink
    assertThat(jobsLogSink.get(), Matchers.instanceOf(FilteredLogSink.class));
    assertThat(operationsLogSink.get(), Matchers.instanceOf(QueueSink.class));
    assertThat(inspectRamAccountingQueue((QueueSink) ((FilteredLogSink) jobsLogSink.get()).delegate), Matchers.instanceOf(BlockingEvictingQueue.class));
    assertThat(inspectRamAccountingQueue((QueueSink) operationsLogSink.get()), Matchers.instanceOf(BlockingEvictingQueue.class));
    clusterSettings.applySettings(Settings.builder().put(JobsLogService.STATS_JOBS_LOG_EXPIRATION_SETTING.getKey(), "10s").put(JobsLogService.STATS_OPERATIONS_LOG_EXPIRATION_SETTING.getKey(), "10s").build());
    assertThat(inspectRamAccountingQueue((QueueSink) ((FilteredLogSink<JobContextLog>) jobsLogSink.get()).delegate), Matchers.instanceOf(ConcurrentLinkedDeque.class));
    assertThat(inspectRamAccountingQueue((QueueSink) operationsLogSink.get()), Matchers.instanceOf(ConcurrentLinkedDeque.class));
    // set all to 0 but don't disable stats
    clusterSettings.applySettings(Settings.builder().put(JobsLogService.STATS_JOBS_LOG_SIZE_SETTING.getKey(), 0).put(JobsLogService.STATS_JOBS_LOG_EXPIRATION_SETTING.getKey(), "0s").put(JobsLogService.STATS_OPERATIONS_LOG_SIZE_SETTING.getKey(), 0).put(JobsLogService.STATS_OPERATIONS_LOG_EXPIRATION_SETTING.getKey(), "0s").build());
    assertThat(jobsLogSink.get(), Matchers.instanceOf(NoopLogSink.class));
    assertThat(operationsLogSink.get(), Matchers.instanceOf(NoopLogSink.class));
    assertThat(stats.isEnabled(), is(true));
    clusterSettings.applySettings(Settings.builder().put(JobsLogService.STATS_JOBS_LOG_SIZE_SETTING.getKey(), 200).put(JobsLogService.STATS_OPERATIONS_LOG_SIZE_SETTING.getKey(), 200).put(JobsLogService.STATS_ENABLED_SETTING.getKey(), true).build());
    assertThat(jobsLogSink.get(), Matchers.instanceOf(FilteredLogSink.class));
    assertThat(inspectRamAccountingQueue((QueueSink) ((FilteredLogSink<JobContextLog>) jobsLogSink.get()).delegate), Matchers.instanceOf(BlockingEvictingQueue.class));
    assertThat(operationsLogSink.get(), Matchers.instanceOf(QueueSink.class));
    assertThat(inspectRamAccountingQueue((QueueSink) operationsLogSink.get()), Matchers.instanceOf(BlockingEvictingQueue.class));
    // disable stats
    clusterSettings.applySettings(Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), false).build());
    assertThat(stats.isEnabled(), is(false));
    assertThat(jobsLogSink.get(), Matchers.instanceOf(NoopLogSink.class));
    assertThat(operationsLogSink.get(), Matchers.instanceOf(NoopLogSink.class));
}
Also used : JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) BlockingEvictingQueue(io.crate.common.collections.BlockingEvictingQueue) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 5 with JobContextLog

use of io.crate.expression.reference.sys.job.JobContextLog in project crate by crate.

the class RamAccountingQueueSinkTest method testRemoveExpiredLogs.

@Test
public void testRemoveExpiredLogs() {
    StatementClassifier.Classification classification = new StatementClassifier.Classification(Plan.StatementType.SELECT, Collections.singleton("Collect"));
    ConcurrentLinkedQueue<JobContextLog> q = new ConcurrentLinkedQueue<>();
    ScheduledFuture<?> task = TimeBasedQEviction.scheduleTruncate(1_000_000L, 1_000_000L, q, scheduler, TimeValue.timeValueSeconds(1L));
    q.add(new JobContextLog(new JobContext(UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff01"), "select 1", 1L, User.CRATE_USER, classification), null, 2000L));
    q.add(new JobContextLog(new JobContext(UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff02"), "select 1", 1L, User.CRATE_USER, classification), null, 4000L));
    q.add(new JobContextLog(new JobContext(UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff03"), "select 1", 1L, User.CRATE_USER, classification), null, 7000L));
    TimeBasedQEviction.removeExpiredLogs(q, 10_000L, 5_000L);
    assertThat(q.size(), is(1));
    assertThat(q.iterator().next().id(), is(UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff03")));
    task.cancel(true);
}
Also used : StatementClassifier(io.crate.planner.operators.StatementClassifier) JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) JobContext(io.crate.expression.reference.sys.job.JobContext) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Aggregations

JobContextLog (io.crate.expression.reference.sys.job.JobContextLog)11 Test (org.junit.Test)8 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)6 JobContext (io.crate.expression.reference.sys.job.JobContext)5 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)4 Settings (org.elasticsearch.common.settings.Settings)4 BlockingEvictingQueue (io.crate.common.collections.BlockingEvictingQueue)3 Classification (io.crate.planner.operators.StatementClassifier.Classification)3 JobsLogService (io.crate.execution.engine.collect.stats.JobsLogService)2 JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)2 OperationContextLog (io.crate.expression.reference.sys.operation.OperationContextLog)2 User (io.crate.user.User)2 SQLOperations (io.crate.action.sql.SQLOperations)1 Session (io.crate.action.sql.Session)1 OperationContext (io.crate.expression.reference.sys.operation.OperationContext)1 MetricsView (io.crate.metadata.sys.MetricsView)1 StatementClassifier (io.crate.planner.operators.StatementClassifier)1 UseJdbc (io.crate.testing.UseJdbc)1 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1