aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorandreer <andreer@verizonmedia.com>2021-02-08 14:32:18 +0100
committerandreer <andreer@verizonmedia.com>2021-02-08 15:19:34 +0100
commitb19b6ba1f27f8295f965555dd4c166d8f2334404 (patch)
treeddb51ff5b369e4600e3be9b5fc8bbfdd48221236 /controller-server
parent20369863ee98ff9ca07078bf7465f229573663b0 (diff)
exclude temporary deployments when calculating quota
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Application.java6
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Instance.java6
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/DeploymentQuotaCalculatorTest.java56
3 files changed, 62 insertions, 6 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Application.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Application.java
index 84ca2fb1a8e..ccb9dccdb3b 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Application.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Application.java
@@ -182,15 +182,17 @@ public class Application {
.min(Comparator.naturalOrder());
}
- /** Returns the total quota usage for this application */
+ /** Returns the total quota usage for this application, excluding temporary deployments */
public QuotaUsage quotaUsage() {
return instances().values().stream()
+ .filter(instance -> !instance.id().instance().isTester()) // Exclude temporary deployments
.map(Instance::quotaUsage).reduce(QuotaUsage::add).orElse(QuotaUsage.none);
}
- /** Returns the total quota usage for this application, excluding one specific deployment */
+ /** Returns the total quota usage for this application, excluding one specific deployment (and temporary deployments) */
public QuotaUsage quotaUsage(ApplicationId application, ZoneId zone) {
return instances().values().stream()
+ .filter(instance -> !instance.id().instance().isTester()) // Exclude temporary deployments
.map(instance -> instance.quotaUsageExcluding(application, zone))
.reduce(QuotaUsage::add).orElse(QuotaUsage.none);
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Instance.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Instance.java
index dcfc1cbc606..fc124947e5d 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Instance.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Instance.java
@@ -166,15 +166,17 @@ public class Instance {
return change;
}
- /** Returns the total quota usage for this instance **/
+ /** Returns the total quota usage for this instance, excluding temporary deployments **/
public QuotaUsage quotaUsage() {
return deployments.values().stream()
+ .filter(d -> !d.zone().environment().isTest()) // Exclude temporary deployments
.map(Deployment::quota).reduce(QuotaUsage::add).orElse(QuotaUsage.none);
}
- /** Returns the total quota usage for this instance, excluding one deployment */
+ /** Returns the total quota usage for this instance, excluding one specific deployment (and temporary deployments) */
public QuotaUsage quotaUsageExcluding(ApplicationId application, ZoneId zone) {
return deployments.values().stream()
+ .filter(d -> !d.zone().environment().isTest()) // Exclude temporary deployments
.filter(d -> !(application.equals(id) && d.zone().equals(zone)))
.map(Deployment::quota).reduce(QuotaUsage::add).orElse(QuotaUsage.none);
}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/DeploymentQuotaCalculatorTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/DeploymentQuotaCalculatorTest.java
index 0a262a41138..d0de33f30e3 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/DeploymentQuotaCalculatorTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/DeploymentQuotaCalculatorTest.java
@@ -1,16 +1,29 @@
package com.yahoo.vespa.hosted.controller.application;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.yahoo.component.Version;
import com.yahoo.config.application.api.DeploymentSpec;
+import com.yahoo.config.application.api.ValidationOverrides;
import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.vespa.hosted.controller.Application;
import com.yahoo.config.provision.zone.ZoneId;
+import com.yahoo.vespa.hosted.controller.Instance;
import com.yahoo.vespa.hosted.controller.api.integration.billing.Quota;
+import com.yahoo.vespa.hosted.controller.api.integration.deployment.ApplicationVersion;
import com.yahoo.vespa.hosted.controller.api.integration.noderepository.ApplicationData;
+import com.yahoo.vespa.hosted.controller.metric.ApplicationMetrics;
import org.junit.Test;
+
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.time.Instant;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.OptionalInt;
+import java.util.OptionalLong;
+import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -38,7 +51,7 @@ public class DeploymentQuotaCalculatorTest {
" </prod>\n" +
" </instance>\n" +
"</deployment>"));
- assertEquals(10d/3, calculated.budget().get().doubleValue(), 1e-5);
+ assertEquals(10d / 3, calculated.budget().orElseThrow().doubleValue(), 1e-5);
}
@Test
@@ -50,7 +63,7 @@ public class DeploymentQuotaCalculatorTest {
@Test
public void zero_quota_remains_zero() {
Quota calculated = DeploymentQuotaCalculator.calculate(Quota.zero(), List.of(), ApplicationId.defaultId(), ZoneId.defaultId(), DeploymentSpec.empty);
- assertEquals(calculated.budget().get().doubleValue(), 0, 1e-5);
+ assertEquals(calculated.budget().orElseThrow().doubleValue(), 0, 1e-5);
}
@Test
@@ -68,4 +81,43 @@ public class DeploymentQuotaCalculatorTest {
var calculated = DeploymentQuotaCalculator.calculate(tenantQuota, List.of(), ApplicationId.defaultId(), ZoneId.from("test", "apac1"), DeploymentSpec.empty);
assertEquals(tenantQuota, calculated);
}
+
+ @Test
+ public void temporary_deployments_are_excluded() {
+ var tenantQuota = Quota.unlimited().withBudget(42);
+
+ var instanceInTestEnv = new Instance(ApplicationId.from("default", "default", "foo")).withNewDeployment(
+ ZoneId.from("test", "apac1"),
+ ApplicationVersion.unknown,
+ Version.emptyVersion,
+ Instant.EPOCH,
+ Map.of(),
+ QuotaUsage.create(1));
+
+ var testerInstance = new Instance(ApplicationId.from("default", "default", "bar-t")).withNewDeployment(
+ ZoneId.from("prod", "apac1"),
+ ApplicationVersion.unknown,
+ Version.emptyVersion,
+ Instant.EPOCH,
+ Map.of(),
+ QuotaUsage.create(1));
+
+ var app = new Application(
+ TenantAndApplicationId.from(ApplicationId.defaultId()),
+ Instant.EPOCH,
+ DeploymentSpec.empty,
+ ValidationOverrides.empty,
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ OptionalInt.empty(),
+ new ApplicationMetrics(100, 100),
+ Set.of(),
+ OptionalLong.empty(),
+ Optional.empty(),
+ List.of(instanceInTestEnv, testerInstance));
+
+ Quota calculated = DeploymentQuotaCalculator.calculate(tenantQuota, List.of(app), ApplicationId.defaultId(), ZoneId.from("dev", "apac1"), DeploymentSpec.empty);
+ assertEquals(tenantQuota, calculated);
+ }
}