diff options
author | Øyvind Grønnesby <oyving@verizonmedia.com> | 2021-02-09 09:38:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 09:38:02 +0100 |
commit | 95756ebe69d5e79b7419570f9d20cb590b1f5a92 (patch) | |
tree | faeb49b5be1aa2f7a63d98a6afa65c902ea9f3b4 /controller-server | |
parent | eb847b3bd3730a52284ea385701dd96899f61e44 (diff) | |
parent | b19b6ba1f27f8295f965555dd4c166d8f2334404 (diff) |
Merge pull request #16438 from vespa-engine/andreer/exclude-temporary-deployments-when-calculating-quota
exclude temporary deployments when calculating quota
Diffstat (limited to 'controller-server')
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); + } } |