use of io.crate.metadata.sys.MetricsView in project crate by crate.
the class JobsLogsTest method testExecutionFailureIsRecordedInMetrics.
@Test
public void testExecutionFailureIsRecordedInMetrics() {
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<MetricsView> metrics = StreamSupport.stream(jobsLogs.metrics().spliterator(), false).collect(Collectors.toList());
assertThat(metrics.size(), is(1));
assertThat(metrics.get(0).failedCount(), is(1L));
assertThat(metrics.get(0).totalCount(), is(1L));
assertThat(metrics.get(0).classification(), is(new Classification(UNDEFINED)));
}
use of io.crate.metadata.sys.MetricsView in project crate by crate.
the class QueryStatsTest method testTrackedStatementTypes.
@Test
public void testTrackedStatementTypes() {
List<MetricsView> oneMetricForEachStatementType = new ArrayList<>();
for (StatementType type : StatementType.values()) {
if (type.equals(StatementType.UNDEFINED)) {
continue;
}
oneMetricForEachStatementType.add(createMetric(new Classification(type), 1));
}
Map<StatementType, QueryStats.Metric> metricsByCommand = createMetricsMap(oneMetricForEachStatementType);
assertThat(metricsByCommand.size(), is(7));
assertThat(metricsByCommand.get(StatementType.SELECT), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.UPDATE), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.INSERT), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.DELETE), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.DDL), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.MANAGEMENT), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.COPY), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.UNDEFINED), is(nullValue()));
}
use of io.crate.metadata.sys.MetricsView in project crate by crate.
the class QueryStats method createMetricsMap.
static Map<StatementType, Metric> createMetricsMap(Iterable<MetricsView> metrics) {
Map<StatementType, Metric> metricsByStmtType = new HashMap<>();
for (MetricsView classifiedMetrics : metrics) {
long sumOfDurations = classifiedMetrics.sumOfDurations();
long failedCount = classifiedMetrics.failedCount();
metricsByStmtType.compute(classificationType(classifiedMetrics.classification()), (key, oldMetric) -> {
if (oldMetric == null) {
return new Metric(sumOfDurations, classifiedMetrics.totalCount(), failedCount);
}
oldMetric.inc(sumOfDurations, classifiedMetrics.totalCount(), failedCount);
return oldMetric;
});
}
return metricsByStmtType;
}
use of io.crate.metadata.sys.MetricsView 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