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