use of io.crate.execution.engine.collect.stats.JobsLogService 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));
}
use of io.crate.execution.engine.collect.stats.JobsLogService in project crate by crate.
the class JobLogIntegrationTest method assertJobLogOnNodesHaveOnlyStatement.
private void assertJobLogOnNodesHaveOnlyStatement(String statement) throws Exception {
for (JobsLogService jobsLogService : internalCluster().getDataNodeInstances(JobsLogService.class)) {
assertBusy(() -> {
assertThat(jobsLogService.jobsLogSize(), is(1));
JobsLogs jobsLogs = jobsLogService.get();
Iterator<JobContextLog> iterator = jobsLogs.jobsLog().iterator();
if (iterator.hasNext()) {
assertThat(iterator.next().statement(), is(statement));
}
});
}
}
use of io.crate.execution.engine.collect.stats.JobsLogService in project crate by crate.
the class MetricsITest method testTotalCountOnMetrics.
@Test
public void testTotalCountOnMetrics() throws Exception {
int numQueries = 100;
for (int i = 0; i < numQueries; i++) {
execute("SELECT 1");
}
// We record the data for the histograms **after** we notify the result receivers
// (see {@link JobsLogsUpdateListener usage).
// So it might happen that the recording of the statement the "SELECT 1" in the metrics is done
// AFTER its execution has returned to this test (because async programming is evil like that).
assertBusy(() -> {
long cnt = 0;
for (JobsLogService jobsLogService : internalCluster().getInstances(JobsLogService.class)) {
for (MetricsView metrics : jobsLogService.get().metrics()) {
if (metrics.classification().type() == Plan.StatementType.SELECT) {
cnt += metrics.totalCount();
}
}
}
assertThat(cnt, is((long) numQueries));
});
execute("SELECT sum(total_count) FROM sys.jobs_metrics WHERE classification['type'] = 'SELECT'");
assertThat(response.rows()[0][0], Matchers.is((long) numQueries));
}
Aggregations