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