Search in sources :

Example 1 with JobContext

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

the class JobsLogs method logExecutionStart.

/**
 * Track a job. If the job has finished {@link #logExecutionEnd(java.util.UUID, String)}
 * must be called.
 * <p>
 * If {@link #isEnabled()} is false this method won't do anything.
 */
public void logExecutionStart(UUID jobId, String statement, User user, StatementClassifier.Classification classification) {
    activeRequests.increment();
    if (!isEnabled()) {
        return;
    }
    jobsTable.put(jobId, new JobContext(jobId, statement, System.currentTimeMillis(), user, classification));
}
Also used : JobContext(io.crate.expression.reference.sys.job.JobContext)

Example 2 with JobContext

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

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

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

Example 5 with JobContext

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

the class JobsLogs method logExecutionEnd.

/**
 * mark a job as finished.
 * <p>
 * If {@link #isEnabled()} is false this method won't do anything.
 */
public void logExecutionEnd(UUID jobId, @Nullable String errorMessage) {
    activeRequests.decrement();
    JobContext jobContext = jobsTable.remove(jobId);
    if (!isEnabled() || jobContext == null) {
        return;
    }
    JobContextLog jobContextLog = new JobContextLog(jobContext, errorMessage);
    recordMetrics(jobContextLog);
    long stamp = jobsLogLock.readLock();
    try {
        jobsLog.add(jobContextLog);
    } finally {
        jobsLogLock.unlockRead(stamp);
    }
}
Also used : JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) JobContext(io.crate.expression.reference.sys.job.JobContext)

Aggregations

JobContext (io.crate.expression.reference.sys.job.JobContext)8 JobContextLog (io.crate.expression.reference.sys.job.JobContextLog)5 Test (org.junit.Test)5 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)3 Classification (io.crate.planner.operators.StatementClassifier.Classification)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 StatementClassifier (io.crate.planner.operators.StatementClassifier)1 User (io.crate.user.User)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1