Search in sources :

Example 6 with ResourceGroupManagerPlugin

use of io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin in project trino by trinodb.

the class TestResourceGroupIntegration method testMemoryFraction.

@Test
public void testMemoryFraction() throws Exception {
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().build()) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        getResourceGroupManager(queryRunner).setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_memory_percentage.json")));
        queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk");
        waitForGlobalResourceGroup(queryRunner);
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Test(org.testng.annotations.Test)

Example 7 with ResourceGroupManagerPlugin

use of io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin in project trino by trinodb.

the class TestResourceGroupIntegration method testPathToRoot.

@Test
public void testPathToRoot() throws Exception {
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().build()) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        InternalResourceGroupManager<?> manager = getResourceGroupManager(queryRunner);
        manager.setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json")));
        queryRunner.execute(testSessionBuilder().setCatalog("tpch").setSchema("tiny").setSource("dashboard-foo").build(), "SELECT COUNT(*), clerk FROM orders GROUP BY clerk");
        List<ResourceGroupInfo> path = manager.tryGetPathToRoot(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("global"), "user-user"), "dashboard-user")).orElseThrow(() -> new IllegalStateException("Resource group not found"));
        assertEquals(path.size(), 3);
        assertThat(path.get(1).getSubGroups()).isPresent();
        assertEquals(path.get(2).getId(), new ResourceGroupId("global"));
        assertEquals(path.get(2).getHardConcurrencyLimit(), 100);
        assertThat(path.get(2).getRunningQueries()).isNotPresent();
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) ResourceGroupInfo(io.trino.server.ResourceGroupInfo) Test(org.testng.annotations.Test)

Example 8 with ResourceGroupManagerPlugin

use of io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin in project trino by trinodb.

the class TestEventListenerBasic method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    Session session = testSessionBuilder().setSystemProperty("task_concurrency", "1").setCatalog("tpch").setSchema("tiny").setClientInfo("{\"clientVersion\":\"testVersion\"}").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).setNodeCount(1).build();
    queryRunner.installPlugin(new TpchPlugin());
    queryRunner.installPlugin(new TestingEventListenerPlugin(generatedEvents));
    queryRunner.installPlugin(new ResourceGroupManagerPlugin());
    queryRunner.createCatalog("tpch", "tpch");
    queryRunner.installPlugin(new Plugin() {

        @Override
        public Iterable<ConnectorFactory> getConnectorFactories() {
            MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListTables((session, s) -> ImmutableList.of(new SchemaTableName("default", "tests_table"))).withGetColumns(schemaTableName -> ImmutableList.of(new ColumnMetadata("test_varchar", createVarcharType(15)), new ColumnMetadata("test_bigint", BIGINT))).withGetTableHandle((session, schemaTableName) -> {
                if (!schemaTableName.getTableName().startsWith("create")) {
                    return new MockConnectorTableHandle(schemaTableName);
                }
                return null;
            }).withApplyProjection((session, handle, projections, assignments) -> {
                if (((MockConnectorTableHandle) handle).getTableName().getTableName().equals("tests_table")) {
                    throw new RuntimeException("Throw from apply projection");
                }
                return Optional.empty();
            }).withGetViews((connectorSession, prefix) -> {
                ConnectorViewDefinition definition = new ConnectorViewDefinition("SELECT nationkey AS test_column FROM tpch.tiny.nation", Optional.empty(), Optional.empty(), ImmutableList.of(new ConnectorViewDefinition.ViewColumn("test_column", BIGINT.getTypeId())), Optional.empty(), Optional.empty(), true);
                SchemaTableName viewName = new SchemaTableName("default", "test_view");
                return ImmutableMap.of(viewName, definition);
            }).withGetMaterializedViews((connectorSession, prefix) -> {
                ConnectorMaterializedViewDefinition definition = new ConnectorMaterializedViewDefinition("SELECT nationkey AS test_column FROM tpch.tiny.nation", Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(new Column("test_column", BIGINT.getTypeId())), Optional.empty(), Optional.of("alice"), ImmutableMap.of());
                SchemaTableName materializedViewName = new SchemaTableName("default", "test_materialized_view");
                return ImmutableMap.of(materializedViewName, definition);
            }).withRowFilter(schemaTableName -> {
                if (schemaTableName.getTableName().equals("test_table_with_row_filter")) {
                    return new ViewExpression("user", Optional.of("tpch"), Optional.of("tiny"), "EXISTS (SELECT 1 FROM nation WHERE name = test_varchar)");
                }
                return null;
            }).withColumnMask((schemaTableName, columnName) -> {
                if (schemaTableName.getTableName().equals("test_table_with_column_mask") && columnName.equals("test_varchar")) {
                    return new ViewExpression("user", Optional.of("tpch"), Optional.of("tiny"), "(SELECT cast(max(orderkey) AS varchar(15)) FROM orders)");
                }
                return null;
            }).build();
            return ImmutableList.of(connectorFactory);
        }
    });
    queryRunner.createCatalog("mock", "mock", ImmutableMap.of());
    queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_simple.json")));
    queries = new EventsAwaitingQueries(generatedEvents, queryRunner, Duration.ofSeconds(1));
    return queryRunner;
}
Also used : TestingEventListenerPlugin(io.trino.execution.TestEventListenerPlugin.TestingEventListenerPlugin) QueryId(io.trino.spi.QueryId) MaterializedResult(io.trino.testing.MaterializedResult) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) QueryCreatedEvent(io.trino.spi.eventlistener.QueryCreatedEvent) QueryFailureInfo(io.trino.spi.eventlistener.QueryFailureInfo) Test(org.testng.annotations.Test) TableInfo(io.trino.spi.eventlistener.TableInfo) ConnectorMaterializedViewDefinition(io.trino.spi.connector.ConnectorMaterializedViewDefinition) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Duration(java.time.Duration) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) Assert.assertFalse(org.testng.Assert.assertFalse) ImmutableSet(com.google.common.collect.ImmutableSet) TestingEventListenerPlugin(io.trino.execution.TestEventListenerPlugin.TestingEventListenerPlugin) ImmutableMap(com.google.common.collect.ImmutableMap) ViewExpression(io.trino.spi.security.ViewExpression) Set(java.util.Set) SchemaTableName(io.trino.spi.connector.SchemaTableName) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) Plugin(io.trino.spi.Plugin) Resources.getResource(com.google.common.io.Resources.getResource) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) BIGINT(io.trino.spi.type.BigintType.BIGINT) Optional(java.util.Optional) Session(io.trino.Session) QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) DataProvider(org.testng.annotations.DataProvider) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) RoutineInfo(io.trino.spi.eventlistener.RoutineInfo) Assert.assertEquals(org.testng.Assert.assertEquals) Column(io.trino.spi.connector.ConnectorMaterializedViewDefinition.Column) EventFilters(io.trino.execution.EventsCollector.EventFilters) ColumnDetail(io.trino.spi.eventlistener.ColumnDetail) ImmutableList(com.google.common.collect.ImmutableList) OutputColumnMetadata(io.trino.spi.eventlistener.OutputColumnMetadata) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) ExecutorService(java.util.concurrent.ExecutorService) QueryStatistics(io.trino.spi.eventlistener.QueryStatistics) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) MoreExecutors.shutdownAndAwaitTermination(com.google.common.util.concurrent.MoreExecutors.shutdownAndAwaitTermination) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Language(org.intellij.lang.annotations.Language) ColumnInfo(io.trino.spi.eventlistener.ColumnInfo) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) File(java.io.File) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) UUID.randomUUID(java.util.UUID.randomUUID) TestQueues.createResourceGroupId(io.trino.execution.TestQueues.createResourceGroupId) QueryRunner(io.trino.testing.QueryRunner) Assert.assertTrue(org.testng.Assert.assertTrue) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) MockConnectorFactory(io.trino.connector.MockConnectorFactory) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) OutputColumnMetadata(io.trino.spi.eventlistener.OutputColumnMetadata) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) ConnectorMaterializedViewDefinition(io.trino.spi.connector.ConnectorMaterializedViewDefinition) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition) ViewExpression(io.trino.spi.security.ViewExpression) Column(io.trino.spi.connector.ConnectorMaterializedViewDefinition.Column) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Session(io.trino.Session) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) TestingEventListenerPlugin(io.trino.execution.TestEventListenerPlugin.TestingEventListenerPlugin) Plugin(io.trino.spi.Plugin) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin)

Example 9 with ResourceGroupManagerPlugin

use of io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin in project trino by trinodb.

the class TestEventListenerWithSplits method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    Session session = testSessionBuilder().setSystemProperty("task_concurrency", "1").setCatalog("tpch").setSchema("tiny").setClientInfo("{\"clientVersion\":\"testVersion\"}").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).setNodeCount(1).build();
    queryRunner.installPlugin(new TpchPlugin());
    queryRunner.installPlugin(new TestingEventListenerPlugin(generatedEvents));
    queryRunner.installPlugin(new ResourceGroupManagerPlugin());
    queryRunner.createCatalog("tpch", "tpch", ImmutableMap.of(TPCH_SPLITS_PER_NODE, Integer.toString(SPLITS_PER_NODE)));
    queryRunner.installPlugin(new Plugin() {

        @Override
        public Iterable<ConnectorFactory> getConnectorFactories() {
            MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListTables((session, s) -> ImmutableList.of(new SchemaTableName("default", "test_table"))).withApplyProjection((session, handle, projections, assignments) -> {
                throw new RuntimeException("Throw from apply projection");
            }).build();
            return ImmutableList.of(connectorFactory);
        }
    });
    queryRunner.createCatalog("mock", "mock", ImmutableMap.of());
    queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_simple.json")));
    queries = new EventsAwaitingQueries(generatedEvents, queryRunner, Duration.ofSeconds(1));
    return queryRunner;
}
Also used : TestingEventListenerPlugin(io.trino.execution.TestEventListenerPlugin.TestingEventListenerPlugin) QueryCompletedEvent(io.trino.spi.eventlistener.QueryCompletedEvent) MaterializedResult(io.trino.testing.MaterializedResult) QueryCreatedEvent(io.trino.spi.eventlistener.QueryCreatedEvent) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) TPCH_SPLITS_PER_NODE(io.trino.plugin.tpch.TpchConnectorFactory.TPCH_SPLITS_PER_NODE) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Duration(java.time.Duration) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Assert.assertFalse(org.testng.Assert.assertFalse) Collectors.toSet(java.util.stream.Collectors.toSet) QueryStatistics(io.trino.spi.eventlistener.QueryStatistics) SplitCompletedEvent(io.trino.spi.eventlistener.SplitCompletedEvent) ImmutableSet(com.google.common.collect.ImmutableSet) TestingEventListenerPlugin(io.trino.execution.TestEventListenerPlugin.TestingEventListenerPlugin) QueryType(io.trino.spi.resourcegroups.QueryType) ImmutableMap(com.google.common.collect.ImmutableMap) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Language(org.intellij.lang.annotations.Language) Set(java.util.Set) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) SchemaTableName(io.trino.spi.connector.SchemaTableName) Plugin(io.trino.spi.Plugin) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) TestQueues.createResourceGroupId(io.trino.execution.TestQueues.createResourceGroupId) QueryRunner(io.trino.testing.QueryRunner) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) Session(io.trino.Session) MockConnectorFactory(io.trino.connector.MockConnectorFactory) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) SchemaTableName(io.trino.spi.connector.SchemaTableName) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Session(io.trino.Session) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) TestingEventListenerPlugin(io.trino.execution.TestEventListenerPlugin.TestingEventListenerPlugin) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Plugin(io.trino.spi.Plugin)

Example 10 with ResourceGroupManagerPlugin

use of io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin in project trino by trinodb.

the class TestExecutionJmxMetrics method testQueryStats.

@Test(timeOut = 30_000)
public void testQueryStats() throws Exception {
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().setAdditionalModule(new PrefixObjectNameGeneratorModule("io.trino")).build()) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        InternalResourceGroupManager<?> resourceGroupManager = queryRunner.getCoordinator().getResourceGroupManager().orElseThrow(() -> new IllegalStateException("Resource manager not configured"));
        resourceGroupManager.setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getClass().getClassLoader().getResource("resource_groups_single_query.json").getPath()));
        MBeanServer mbeanServer = queryRunner.getCoordinator().getMbeanServer();
        QueryId firstDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_RUNNING_QUERY);
        waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
        assertEquals(getMbeanAttribute(mbeanServer, "RunningQueries"), 1);
        assertEquals(getMbeanAttribute(mbeanServer, "QueuedQueries"), 0);
        // the second "dashboard" query can't run right away because the resource group has a hardConcurrencyLimit of 1
        QueryId secondDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_RUNNING_QUERY);
        waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
        assertEquals(getMbeanAttribute(mbeanServer, "RunningQueries"), 1);
        assertEquals(getMbeanAttribute(mbeanServer, "QueuedQueries"), 1);
        cancelQuery(queryRunner, secondDashboardQuery);
        waitForQueryState(queryRunner, secondDashboardQuery, FAILED);
        assertEquals(getMbeanAttribute(mbeanServer, "RunningQueries"), 1);
        assertEquals(getMbeanAttribute(mbeanServer, "QueuedQueries"), 0);
        // cancel the running query to avoid polluting the logs with meaningless stack traces
        try {
            cancelQuery(queryRunner, firstDashboardQuery);
            waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
        } catch (Exception ignore) {
        }
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) PrefixObjectNameGeneratorModule(io.trino.server.PrefixObjectNameGeneratorModule) MBeanServer(javax.management.MBeanServer) Test(org.testng.annotations.Test)

Aggregations

ResourceGroupManagerPlugin (io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin)14 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)14 Test (org.testng.annotations.Test)13 QueryId (io.trino.spi.QueryId)7 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Session (io.trino.Session)3 MockConnectorFactory (io.trino.connector.MockConnectorFactory)3 TpchPlugin (io.trino.plugin.tpch.TpchPlugin)3 Plugin (io.trino.spi.Plugin)3 ConnectorFactory (io.trino.spi.connector.ConnectorFactory)3 SchemaTableName (io.trino.spi.connector.SchemaTableName)3 AbstractTestQueryFramework (io.trino.testing.AbstractTestQueryFramework)3 TestingSession.testSessionBuilder (io.trino.testing.TestingSession.testSessionBuilder)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)2 MockConnectorTableHandle (io.trino.connector.MockConnectorTableHandle)2 TestingEventListenerPlugin (io.trino.execution.TestEventListenerPlugin.TestingEventListenerPlugin)2 TestQueues.createResourceGroupId (io.trino.execution.TestQueues.createResourceGroupId)2 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)2