Search in sources :

Example 6 with Metrics

use of io.trino.spi.metrics.Metrics in project trino by trinodb.

the class TestMetrics method testDurationTiming.

@Test
public void testDurationTiming() {
    DurationTiming d1 = new DurationTiming(new Duration(1234, NANOSECONDS));
    DurationTiming d2 = new DurationTiming(new Duration(1, NANOSECONDS));
    assertThat(d1.toString()).matches("\\{duration=1.23us\\}");
    Metrics m1 = new Metrics(ImmutableMap.of("a", d1));
    Metrics m2 = new Metrics(ImmutableMap.of("a", d2));
    DurationTiming merged = (DurationTiming) merge(m1, m2).getMetrics().get("a");
    assertThat(merged.getAirliftDuration().roundTo(NANOSECONDS)).isEqualTo(1235);
    assertThat(merged.getDuration().toNanos()).isEqualTo(1235);
    assertThat(merged.toString()).matches("\\{duration=1.24us\\}");
}
Also used : Metrics(io.trino.spi.metrics.Metrics) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 7 with Metrics

use of io.trino.spi.metrics.Metrics in project trino by trinodb.

the class TestMetrics method testFailIncompatibleTypes.

@Test(expectedExceptions = ClassCastException.class)
public void testFailIncompatibleTypes() {
    Metrics m1 = new Metrics(ImmutableMap.of("a", new TDigestHistogram(new TDigest())));
    Metrics m2 = new Metrics(ImmutableMap.of("a", new LongCount(0)));
    merge(m1, m2);
}
Also used : Metrics(io.trino.spi.metrics.Metrics) TDigest(io.airlift.stats.TDigest) Test(org.testng.annotations.Test)

Example 8 with Metrics

use of io.trino.spi.metrics.Metrics in project trino by trinodb.

the class TextRenderer method printMetrics.

private void printMetrics(StringBuilder output, String label, Function<BasicOperatorStats, Metrics> metricsGetter, PlanNodeStats stats) {
    if (!verbose) {
        return;
    }
    Map<String, String> translatedOperatorTypes = translateOperatorTypes(stats.getOperatorTypes());
    for (String operator : translatedOperatorTypes.keySet()) {
        String translatedOperatorType = translatedOperatorTypes.get(operator);
        Metrics metrics = metricsGetter.apply(stats.getOperatorStats().get(operator));
        if (metrics.getMetrics().isEmpty()) {
            continue;
        }
        output.append(translatedOperatorType + label).append("\n");
        Map<String, Metric<?>> sortedMap = new TreeMap<>(metrics.getMetrics());
        sortedMap.forEach((name, metric) -> output.append(format("  '%s' = %s\n", name, metric)));
    }
}
Also used : Metrics(io.trino.spi.metrics.Metrics) Metric(io.trino.spi.metrics.Metric) TreeMap(java.util.TreeMap)

Example 9 with Metrics

use of io.trino.spi.metrics.Metrics in project trino by trinodb.

the class TestMemoryConnectorTest method testCustomMetricsScanOnly.

@Test
@Flaky(issue = "https://github.com/trinodb/trino/issues/8691", match = "ComparisonFailure: expected:<LongCount\\{total=\\[\\d+]}> but was:<(LongCount\\{total=\\[\\d+]}|null)>")
public void testCustomMetricsScanOnly() {
    Metrics metrics = collectCustomMetrics("SELECT partkey FROM part");
    assertThat(metrics.getMetrics().get("rows")).isEqualTo(new LongCount(PART_COUNT));
    assertThat(metrics.getMetrics().get("started")).isEqualTo(metrics.getMetrics().get("finished"));
    assertThat(((Count<?>) metrics.getMetrics().get("finished")).getTotal()).isGreaterThan(0);
}
Also used : Metrics(io.trino.spi.metrics.Metrics) LongCount(io.trino.plugin.base.metrics.LongCount) LongCount(io.trino.plugin.base.metrics.LongCount) Count(io.trino.spi.metrics.Count) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest) Flaky(io.trino.testng.services.Flaky)

Example 10 with Metrics

use of io.trino.spi.metrics.Metrics in project trino by trinodb.

the class TestMemoryConnectorTest method collectCustomMetrics.

private Metrics collectCustomMetrics(String sql) {
    DistributedQueryRunner runner = (DistributedQueryRunner) getQueryRunner();
    ResultWithQueryId<MaterializedResult> result = runner.executeWithQueryId(getSession(), sql);
    return runner.getCoordinator().getQueryManager().getFullQueryInfo(result.getQueryId()).getQueryStats().getOperatorSummaries().stream().map(OperatorStats::getConnectorMetrics).reduce(Metrics.EMPTY, Metrics::mergeWith);
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) Metrics(io.trino.spi.metrics.Metrics) MaterializedResult(io.trino.testing.MaterializedResult)

Aggregations

Metrics (io.trino.spi.metrics.Metrics)10 Test (org.testng.annotations.Test)6 TDigest (io.airlift.stats.TDigest)3 LongCount (io.trino.plugin.base.metrics.LongCount)2 Count (io.trino.spi.metrics.Count)2 Metric (io.trino.spi.metrics.Metric)2 BaseConnectorTest (io.trino.testing.BaseConnectorTest)2 Flaky (io.trino.testng.services.Flaky)2 Duration (io.airlift.units.Duration)1 TDigestHistogram (io.trino.plugin.base.metrics.TDigestHistogram)1 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)1 MaterializedResult (io.trino.testing.MaterializedResult)1 TreeMap (java.util.TreeMap)1