Search in sources :

Example 6 with JobContextLog

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

the class JobsLogsTest method testExecutionFailure.

@Test
public void testExecutionFailure() {
    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<JobContextLog> jobsLogEntries = StreamSupport.stream(jobsLogs.jobsLog().spliterator(), false).collect(Collectors.toList());
    assertThat(jobsLogEntries.size(), is(1));
    assertThat(jobsLogEntries.get(0).username(), is(user.name()));
    assertThat(jobsLogEntries.get(0).statement(), is("select foo"));
    assertThat(jobsLogEntries.get(0).errorMessage(), is("stmt error"));
    assertThat(jobsLogEntries.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) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 7 with JobContextLog

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

Example 8 with JobContextLog

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

the class JobsLogs method logPreExecutionFailure.

/**
 * Create a entry into `sys.jobs_log`
 * This method can be used instead of {@link #logExecutionEnd(UUID, String)} if there was no {@link #logExecutionStart(UUID, String, User, StatementClassifier.Classification)}
 * Call because an error happened during parse, analysis or plan.
 * <p>
 * {@link #logExecutionStart(UUID, String, User, StatementClassifier.Classification)} is only called after a Plan has been created and execution starts.
 */
public void logPreExecutionFailure(UUID jobId, String stmt, String errorMessage, User user) {
    JobContextLog jobContextLog = new JobContextLog(new JobContext(jobId, stmt, System.currentTimeMillis(), user, new StatementClassifier.Classification(UNDEFINED)), errorMessage);
    long stamp = jobsLogLock.readLock();
    try {
        jobsLog.add(jobContextLog);
    } finally {
        jobsLogLock.unlockRead(stamp);
    }
    recordMetrics(jobContextLog);
}
Also used : JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) JobContext(io.crate.expression.reference.sys.job.JobContext)

Example 9 with JobContextLog

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

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

the class JobLogIntegrationTest method testJobLogWithEnabledAndDisabledStats.

@Test
// SET extra_float_digits = 3 gets added to the jobs_log
@UseJdbc(0)
public void testJobLogWithEnabledAndDisabledStats() throws Exception {
    String setStmt = "set global transient stats.jobs_log_size=1";
    execute(setStmt);
    // We record the statements in the log **after** we notify the result receivers (see {@link JobsLogsUpdateListener usage).
    // So it might happen that the "set global ..." statement execution is returned to this test but the recording
    // in the log is done AFTER the execution of the below "select name from sys.cluster" statement (because async
    // programming is evil like that). And then this test will fail and people will spend days and days to figure
    // out what's going on.
    // So let's just wait for the "set global ... " statement to be recorded here and then move on with our test.
    assertBusy(() -> {
        boolean setStmtFound = false;
        for (JobsLogService jobsLogService : internalCluster().getDataNodeInstances(JobsLogService.class)) {
            // each node must have received the new jobs_log_size setting change instruction
            assertThat(jobsLogService.jobsLogSize(), is(1));
            JobsLogs jobsLogs = jobsLogService.get();
            Iterator<JobContextLog> iterator = jobsLogs.jobsLog().iterator();
            if (iterator.hasNext()) {
                if (iterator.next().statement().equalsIgnoreCase(setStmt)) {
                    setStmtFound = true;
                }
            }
        }
        // at least one node must have the set statement logged
        assertThat(setStmtFound, is(true));
    });
    // only the latest queries are found in the log.
    for (SQLOperations sqlOperations : internalCluster().getDataNodeInstances(SQLOperations.class)) {
        Session session = sqlOperations.newSystemSession();
        execute("select name from sys.cluster", null, session);
    }
    assertJobLogOnNodesHaveOnlyStatement("select name from sys.cluster");
    for (SQLOperations sqlOperations : internalCluster().getDataNodeInstances(SQLOperations.class)) {
        Session session = sqlOperations.newSystemSession();
        execute("select id from sys.cluster", null, session);
    }
    assertJobLogOnNodesHaveOnlyStatement("select id from sys.cluster");
    execute("set global transient stats.enabled = false");
    for (JobsLogService jobsLogService : internalCluster().getDataNodeInstances(JobsLogService.class)) {
        assertBusy(() -> assertThat(jobsLogService.isEnabled(), is(false)));
    }
    execute("select * from sys.jobs_log");
    assertThat(response.rowCount(), is(0L));
}
Also used : JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) SQLOperations(io.crate.action.sql.SQLOperations) JobsLogService(io.crate.execution.engine.collect.stats.JobsLogService) Session(io.crate.action.sql.Session) UseJdbc(io.crate.testing.UseJdbc) 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