Search in sources :

Example 1 with MetricsView

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)));
}
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) MetricsView(io.crate.metadata.sys.MetricsView) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 2 with MetricsView

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()));
}
Also used : StatementType(io.crate.planner.Plan.StatementType) Classification(io.crate.planner.operators.StatementClassifier.Classification) ArrayList(java.util.ArrayList) MetricsView(io.crate.metadata.sys.MetricsView) Test(org.junit.Test)

Example 3 with MetricsView

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;
}
Also used : HashMap(java.util.HashMap) StatementType(io.crate.planner.Plan.StatementType) MetricsView(io.crate.metadata.sys.MetricsView)

Example 4 with MetricsView

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));
}
Also used : MetricsView(io.crate.metadata.sys.MetricsView) JobsLogService(io.crate.execution.engine.collect.stats.JobsLogService) Test(org.junit.Test)

Aggregations

MetricsView (io.crate.metadata.sys.MetricsView)4 Test (org.junit.Test)3 StatementType (io.crate.planner.Plan.StatementType)2 Classification (io.crate.planner.operators.StatementClassifier.Classification)2 BlockingEvictingQueue (io.crate.common.collections.BlockingEvictingQueue)1 JobsLogService (io.crate.execution.engine.collect.stats.JobsLogService)1 JobContextLog (io.crate.expression.reference.sys.job.JobContextLog)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 User (io.crate.user.User)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1