Search in sources :

Example 1 with Metrics

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

the class TestMemoryConnectorTest method testCustomMetricsScanFilter.

@Test
// TODO (https://github.com/trinodb/trino/issues/8691) fix the test
@Flaky(issue = "https://github.com/trinodb/trino/issues/8691", match = "ComparisonFailure: expected:<LongCount\\{total=\\[\\d+]}> but was:<(LongCount\\{total=\\[\\d+]}|null)>")
public void testCustomMetricsScanFilter() {
    Metrics metrics = collectCustomMetrics("SELECT partkey FROM part WHERE partkey % 1000 > 0");
    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 2 with Metrics

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

the class OperatorContext method getOperatorMetrics.

public static Metrics getOperatorMetrics(Metrics operatorMetrics, long inputPositions) {
    TDigest digest = new TDigest();
    digest.add(inputPositions);
    return operatorMetrics.mergeWith(new Metrics(ImmutableMap.of("Input distribution", new TDigestHistogram(digest))));
}
Also used : Metrics(io.trino.spi.metrics.Metrics) TDigest(io.airlift.stats.TDigest) TDigestHistogram(io.trino.plugin.base.metrics.TDigestHistogram)

Example 3 with Metrics

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

the class WorkProcessorSourceOperatorAdapter method updateOperatorStats.

private void updateOperatorStats() {
    long currentPhysicalInputBytes = sourceOperator.getPhysicalInputDataSize().toBytes();
    long currentPhysicalInputPositions = sourceOperator.getPhysicalInputPositions();
    long currentReadTimeNanos = sourceOperator.getReadTime().roundTo(NANOSECONDS);
    long currentInternalNetworkInputBytes = sourceOperator.getInternalNetworkInputDataSize().toBytes();
    long currentInternalNetworkPositions = sourceOperator.getInternalNetworkPositions();
    long currentInputBytes = sourceOperator.getInputDataSize().toBytes();
    long currentInputPositions = sourceOperator.getInputPositions();
    long currentDynamicFilterSplitsProcessed = sourceOperator.getDynamicFilterSplitsProcessed();
    Metrics currentMetrics = sourceOperator.getMetrics();
    Metrics currentConnectorMetrics = sourceOperator.getConnectorMetrics();
    if (currentPhysicalInputBytes != previousPhysicalInputBytes || currentPhysicalInputPositions != previousPhysicalInputPositions || currentReadTimeNanos != previousReadTimeNanos) {
        operatorContext.recordPhysicalInputWithTiming(currentPhysicalInputBytes - previousPhysicalInputBytes, currentPhysicalInputPositions - previousPhysicalInputPositions, currentReadTimeNanos - previousReadTimeNanos);
        previousPhysicalInputBytes = currentPhysicalInputBytes;
        previousPhysicalInputPositions = currentPhysicalInputPositions;
        previousReadTimeNanos = currentReadTimeNanos;
    }
    if (currentInternalNetworkInputBytes != previousInternalNetworkInputBytes || currentInternalNetworkPositions != previousInternalNetworkPositions) {
        operatorContext.recordNetworkInput(currentInternalNetworkInputBytes - previousInternalNetworkInputBytes, currentInternalNetworkPositions - previousInternalNetworkPositions);
        previousInternalNetworkInputBytes = currentInternalNetworkInputBytes;
        previousInternalNetworkPositions = currentInternalNetworkPositions;
    }
    if (currentInputBytes != previousInputBytes || currentInputPositions != previousInputPositions) {
        operatorContext.recordProcessedInput(currentInputBytes - previousInputBytes, currentInputPositions - previousInputPositions);
        previousInputBytes = currentInputBytes;
        previousInputPositions = currentInputPositions;
    }
    if (currentDynamicFilterSplitsProcessed != previousDynamicFilterSplitsProcessed) {
        operatorContext.recordDynamicFilterSplitProcessed(currentDynamicFilterSplitsProcessed - previousDynamicFilterSplitsProcessed);
        previousDynamicFilterSplitsProcessed = currentDynamicFilterSplitsProcessed;
    }
    operatorContext.setLatestMetrics(currentMetrics);
    operatorContext.setLatestConnectorMetrics(currentConnectorMetrics);
}
Also used : Metrics(io.trino.spi.metrics.Metrics)

Example 4 with Metrics

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

the class TestMetrics method testMergeHistogram.

@Test
public void testMergeHistogram() {
    TDigest d1 = new TDigest();
    d1.add(10.0, 1);
    TDigest d2 = new TDigest();
    d2.add(5.0, 2);
    Metrics m1 = new Metrics(ImmutableMap.of("a", new TDigestHistogram(d1)));
    Metrics m2 = new Metrics(ImmutableMap.of("a", new TDigestHistogram(d2)));
    TDigestHistogram merged = (TDigestHistogram) merge(m1, m2).getMetrics().get("a");
    assertThat(merged.getTotal()).isEqualTo(3L);
    assertThat(merged.getPercentile(0)).isEqualTo(5.0);
    assertThat(merged.getPercentile(100)).isEqualTo(10.0);
    assertThat(merged.toString()).matches("\\{count=3\\.00, p01=5\\.00, p05=5\\.00, p10=5\\.00, p25=5\\.00, p50=7\\.50, p75=10\\.00, p90=10\\.00, p95=10\\.00, p99=10\\.00, min=5\\.00, max=10\\.00\\}");
}
Also used : Metrics(io.trino.spi.metrics.Metrics) TDigest(io.airlift.stats.TDigest) Test(org.testng.annotations.Test)

Example 5 with Metrics

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

the class TestMetrics method testMergeCount.

@Test
public void testMergeCount() {
    Metrics m1 = new Metrics(ImmutableMap.of("a", new LongCount(1), "b", new LongCount(2)));
    Metrics m2 = new Metrics(ImmutableMap.of("b", new LongCount(3), "c", new LongCount(4)));
    Metrics merged = merge(m1, m2);
    Map<String, Metric<?>> expectedMap = ImmutableMap.of("a", new LongCount(1), "b", new LongCount(5), "c", new LongCount(4));
    assertThat(merged.getMetrics()).isEqualTo(expectedMap);
}
Also used : Metrics(io.trino.spi.metrics.Metrics) Metric(io.trino.spi.metrics.Metric) Test(org.testng.annotations.Test)

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