Search in sources :

Example 11 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class StaticSelector method match.

@Override
public Optional<SelectionContext<VariableMap>> match(SelectionCriteria criteria) {
    Map<String, String> variables = new HashMap<>();
    if (userRegex.isPresent()) {
        Matcher userMatcher = userRegex.get().matcher(criteria.getUser());
        if (!userMatcher.matches()) {
            return Optional.empty();
        }
        addVariableValues(userRegex.get(), criteria.getUser(), variables);
    }
    if (sourceRegex.isPresent()) {
        String source = criteria.getSource().orElse("");
        if (!sourceRegex.get().matcher(source).matches()) {
            return Optional.empty();
        }
        addVariableValues(sourceRegex.get(), source, variables);
    }
    if (!clientTags.isEmpty() && !criteria.getTags().containsAll(clientTags)) {
        return Optional.empty();
    }
    if (selectorResourceEstimate.isPresent() && !selectorResourceEstimate.get().match(criteria.getResourceEstimates())) {
        return Optional.empty();
    }
    if (queryType.isPresent()) {
        String contextQueryType = criteria.getQueryType().orElse("");
        if (!queryType.get().equalsIgnoreCase(contextQueryType)) {
            return Optional.empty();
        }
    }
    variables.putIfAbsent(USER_VARIABLE, criteria.getUser());
    // Special handling for source, which is an optional field that is part of the standard variables
    variables.putIfAbsent(SOURCE_VARIABLE, criteria.getSource().orElse(""));
    VariableMap map = new VariableMap(variables);
    ResourceGroupId id = group.expandTemplate(map);
    OptionalInt firstDynamicSegment = group.getFirstDynamicSegment();
    return Optional.of(new SelectionContext<>(id, map, firstDynamicSegment));
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) OptionalInt(java.util.OptionalInt)

Example 12 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestResourceGroupIdTemplate method testNoSource.

@Test
public void testNoSource() {
    ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.${pipeline}.${SOURCE}_s");
    ResourceGroupId expected = new ResourceGroupId(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("test"), "pipeline"), "testpipeline"), "_s");
    Pattern userPattern = Pattern.compile("scheduler.important.(?<pipeline>[^\\[]*).*");
    StaticSelector selector = new StaticSelector(Optional.of(userPattern), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), template);
    SelectionCriteria context = new SelectionCriteria(true, "scheduler.important.testpipeline[5]", Optional.empty(), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
    assertEquals(selector.match(context).map(SelectionContext::getResourceGroupId), Optional.of(expected));
}
Also used : Pattern(java.util.regex.Pattern) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) SelectionCriteria(com.facebook.presto.spi.resourceGroups.SelectionCriteria) Test(org.testng.annotations.Test)

Example 13 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestFileResourceGroupConfigurationManager method testLegacyConfiguration.

@Test
public void testLegacyConfiguration() {
    ResourceGroupConfigurationManager<VariableMap> manager = parse("resource_groups_config_legacy.json");
    ResourceGroupId globalId = new ResourceGroupId("global");
    ResourceGroup global = new TestingResourceGroup(globalId);
    manager.configure(global, new SelectionContext<>(globalId, new VariableMap(ImmutableMap.of("USER", "user"))));
    assertEquals(global.getSoftMemoryLimit(), new DataSize(3, MEGABYTE));
    assertEquals(global.getMaxQueuedQueries(), 99);
    assertEquals(global.getHardConcurrencyLimit(), 42);
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) DataSize(io.airlift.units.DataSize) ResourceGroup(com.facebook.presto.spi.resourceGroups.ResourceGroup) Test(org.testng.annotations.Test)

Example 14 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestStaticSelector method testSourceRegex.

@Test
public void testSourceRegex() {
    ResourceGroupId resourceGroupId = new ResourceGroupId(new ResourceGroupId("global"), "foo");
    StaticSelector selector = new StaticSelector(Optional.empty(), Optional.of(Pattern.compile(".*source.*")), Optional.empty(), Optional.empty(), Optional.empty(), new ResourceGroupIdTemplate("global.foo"));
    assertEquals(selector.match(newSelectionCriteria("userA", null, ImmutableSet.of("tag1"), EMPTY_RESOURCE_ESTIMATES)), Optional.empty());
    assertEquals(selector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES)).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
    assertEquals(selector.match(newSelectionCriteria("A.user", "a source b", ImmutableSet.of("tag1"), EMPTY_RESOURCE_ESTIMATES)).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Test(org.testng.annotations.Test)

Example 15 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestStaticSelector method testSelectorResourceEstimate.

@Test
public void testSelectorResourceEstimate() {
    ResourceGroupId resourceGroupId = new ResourceGroupId(new ResourceGroupId("global"), "foo");
    StaticSelector smallQuerySelector = new StaticSelector(Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new SelectorResourceEstimate(Optional.of(new Range<>(Optional.empty(), Optional.of(Duration.valueOf("5m")))), Optional.empty(), Optional.of(new Range<>(Optional.empty(), Optional.of(DataSize.valueOf("500MB")))))), Optional.empty(), new ResourceGroupIdTemplate("global.foo"));
    assertEquals(smallQuerySelector.match(newSelectionCriteria("userA", null, ImmutableSet.of("tag1", "tag2"), new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.of(DataSize.valueOf("400MB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
    assertEquals(smallQuerySelector.match(newSelectionCriteria("A.user", "a source b", ImmutableSet.of("tag1"), new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.of(DataSize.valueOf("600MB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.empty());
    assertEquals(smallQuerySelector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.empty(), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.empty());
    StaticSelector largeQuerySelector = new StaticSelector(Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new SelectorResourceEstimate(Optional.empty(), Optional.empty(), Optional.of(new Range<>(Optional.of(DataSize.valueOf("5TB")), Optional.empty())))), Optional.empty(), new ResourceGroupIdTemplate("global.foo"));
    assertEquals(largeQuerySelector.match(newSelectionCriteria("userA", null, ImmutableSet.of("tag1", "tag2"), new ResourceEstimates(Optional.of(Duration.valueOf("100h")), Optional.empty(), Optional.of(DataSize.valueOf("4TB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.empty());
    assertEquals(largeQuerySelector.match(newSelectionCriteria("A.user", "a source b", ImmutableSet.of("tag1"), new ResourceEstimates(Optional.empty(), Optional.empty(), Optional.of(DataSize.valueOf("6TB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
    assertEquals(largeQuerySelector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), new ResourceEstimates(Optional.of(Duration.valueOf("1s")), Optional.of(Duration.valueOf("1s")), Optional.of(DataSize.valueOf("6TB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
}
Also used : ResourceEstimates(com.facebook.presto.spi.session.ResourceEstimates) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Range(com.facebook.presto.resourceGroups.SelectorResourceEstimate.Range) Test(org.testng.annotations.Test)

Aggregations

ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)41 Test (org.testng.annotations.Test)31 QueryId (com.facebook.presto.spi.QueryId)12 ResourceGroupRuntimeInfo (com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)9 ResourceGroupInfo (com.facebook.presto.server.ResourceGroupInfo)5 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Duration (io.airlift.units.Duration)5 String.format (java.lang.String.format)5 Optional (java.util.Optional)5 TestQueues.createResourceGroupId (com.facebook.presto.execution.TestQueues.createResourceGroupId)4 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)4 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)3 DataSize (io.airlift.units.DataSize)3 HashMap (java.util.HashMap)3 SECONDS (java.util.concurrent.TimeUnit.SECONDS)3 Assert.assertEquals (org.testng.Assert.assertEquals)3 Assert.assertTrue (org.testng.Assert.assertTrue)3 Session (com.facebook.presto.Session)2 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)2