Search in sources :

Example 1 with OperationContextLog

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

use of io.crate.expression.reference.sys.operation.OperationContextLog in project crate by crate.

the class JobsLogsTest method testUniqueOperationIdsInOperationsTable.

@Test
public void testUniqueOperationIdsInOperationsTable() {
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    Queue<OperationContextLog> q = new BlockingEvictingQueue<>(10);
    jobsLogs.updateOperationsLog(new QueueSink<>(q, () -> {
    }));
    OperationContext ctxA = new OperationContext(0, UUID.randomUUID(), "dummyOperation", 1L, () -> -1);
    jobsLogs.operationStarted(ctxA.id, ctxA.jobId, ctxA.name, () -> -1);
    OperationContext ctxB = new OperationContext(0, UUID.randomUUID(), "dummyOperation", 1L, () -> -1);
    jobsLogs.operationStarted(ctxB.id, ctxB.jobId, ctxB.name, () -> 1);
    jobsLogs.operationFinished(ctxB.id, ctxB.jobId, null);
    List<OperationContextLog> entries = StreamSupport.stream(jobsLogs.operationsLog().spliterator(), false).collect(Collectors.toList());
    assertThat(entries, contains(new OperationContextLog(ctxB, null)));
    assertFalse(entries.contains(new OperationContextLog(ctxA, null)));
    jobsLogs.operationFinished(ctxA.id, ctxA.jobId, null);
    entries = StreamSupport.stream(jobsLogs.operationsLog().spliterator(), false).collect(Collectors.toList());
    assertTrue(entries.contains(new OperationContextLog(ctxA, null)));
}
Also used : OperationContext(io.crate.expression.reference.sys.operation.OperationContext) OperationContextLog(io.crate.expression.reference.sys.operation.OperationContextLog) BlockingEvictingQueue(io.crate.common.collections.BlockingEvictingQueue) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 3 with OperationContextLog

use of io.crate.expression.reference.sys.operation.OperationContextLog in project crate by crate.

the class JobsLogs method operationFinished.

public void operationFinished(int operationId, UUID jobId, @Nullable String errorMessage) {
    if (!isEnabled()) {
        return;
    }
    OperationContext operationContext = operationsTable.remove(uniqueOperationId(operationId, jobId));
    if (operationContext == null) {
        // been enabled before the finish
        return;
    }
    OperationContextLog operationContextLog = new OperationContextLog(operationContext, errorMessage);
    long stamp = operationsLogRWLock.readLock();
    try {
        operationsLog.add(operationContextLog);
    } finally {
        operationsLogRWLock.unlockRead(stamp);
    }
}
Also used : OperationContext(io.crate.expression.reference.sys.operation.OperationContext) OperationContextLog(io.crate.expression.reference.sys.operation.OperationContextLog)

Example 4 with OperationContextLog

use of io.crate.expression.reference.sys.operation.OperationContextLog 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)

Example 5 with OperationContextLog

use of io.crate.expression.reference.sys.operation.OperationContextLog in project crate by crate.

the class SysOperationsLogTableInfoTest method test_job_id_returns_job_id_of_operation_context_log.

@Test
public void test_job_id_returns_job_id_of_operation_context_log() {
    var table = SysOperationsLogTableInfo.create();
    var expressionFactory = table.expressions().get(new ColumnIdent("job_id"));
    var expression = expressionFactory.create();
    int id = 1;
    UUID jobId = UUID.randomUUID();
    String name = "Dummy";
    long started = 1;
    LongSupplier bytesUsed = () -> 10;
    String errorMessage = null;
    expression.setNextRow(new OperationContextLog(new OperationContext(id, jobId, name, started, bytesUsed), errorMessage));
    Object value = (String) expression.value();
    assertThat(value, Matchers.is(jobId.toString()));
}
Also used : OperationContext(io.crate.expression.reference.sys.operation.OperationContext) ColumnIdent(io.crate.metadata.ColumnIdent) OperationContextLog(io.crate.expression.reference.sys.operation.OperationContextLog) UUID(java.util.UUID) LongSupplier(java.util.function.LongSupplier) Test(org.junit.jupiter.api.Test)

Aggregations

OperationContextLog (io.crate.expression.reference.sys.operation.OperationContextLog)5 OperationContext (io.crate.expression.reference.sys.operation.OperationContext)4 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)3 Test (org.junit.Test)3 JobContextLog (io.crate.expression.reference.sys.job.JobContextLog)2 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)2 Settings (org.elasticsearch.common.settings.Settings)2 BlockingEvictingQueue (io.crate.common.collections.BlockingEvictingQueue)1 JobContext (io.crate.expression.reference.sys.job.JobContext)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 Classification (io.crate.planner.operators.StatementClassifier.Classification)1 UUID (java.util.UUID)1 LongSupplier (java.util.function.LongSupplier)1 Test (org.junit.jupiter.api.Test)1