diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2020-02-20 13:06:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-20 13:06:18 +0100 |
commit | 8b5de98db88a3e463fad6273c9622573c19d6fc6 (patch) | |
tree | 6c41ddbf4b96ab2d63dd98b5ff595fc5abdb0831 | |
parent | acfb0463e55aa4878cc3087ffcee356696eabf2a (diff) | |
parent | 2ba81cc47c9c5a69845e444ca207f3a02f652c5c (diff) |
Merge pull request #12285 from vespa-engine/mpolden/remove-cost-api
Remove /cost/v1/
-rw-r--r-- | controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/PathGroup.java | 3 | ||||
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainer.java | 6 | ||||
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/metric/CostCalculator.java (renamed from controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostCalculator.java) | 20 | ||||
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiHandler.java | 52 | ||||
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/package-info.java | 5 | ||||
-rw-r--r-- | controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java | 3 | ||||
-rw-r--r-- | controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiTest.java | 49 |
7 files changed, 13 insertions, 125 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/PathGroup.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/PathGroup.java index 67a6faac606..4c91238453a 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/PathGroup.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/PathGroup.java @@ -179,8 +179,7 @@ enum PathGroup { "/application/v4/tenant/"), /** Paths which contain (not very strictly) classified information about, e.g., customers. */ - classifiedInfo("/cost/v1/{*}", - "/", + classifiedInfo("/", "/d/{*}"), /** Same as classifiedInfo, but with optional /api prefix */ diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainer.java index ff88805f957..5b792f384e5 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainer.java @@ -1,12 +1,11 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.maintenance; -import com.yahoo.config.provision.CloudName; import com.yahoo.config.provision.SystemName; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.integration.configserver.NodeRepository; import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportConsumer; -import com.yahoo.vespa.hosted.controller.restapi.cost.CostCalculator; +import com.yahoo.vespa.hosted.controller.metric.CostCalculator; import java.time.Clock; import java.time.Duration; @@ -34,7 +33,8 @@ public class CostReportMaintainer extends Maintainer { @Override protected void maintain() { - consumer.consume(CostCalculator.resourceShareByPropertyToCsv(nodeRepository, controller(), clock, consumer.fixedAllocations(), CloudName.from("yahoo"))); + var csv = CostCalculator.resourceShareByPropertyToCsv(nodeRepository, controller(), clock, consumer.fixedAllocations()); + consumer.consume(csv); } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostCalculator.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/metric/CostCalculator.java index ec01b3817a7..4cc4ee0386c 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostCalculator.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/metric/CostCalculator.java @@ -1,5 +1,5 @@ // Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.controller.restapi.cost; +package com.yahoo.vespa.hosted.controller.metric; import com.yahoo.config.provision.CloudName; import com.yahoo.config.provision.Environment; @@ -28,12 +28,12 @@ import static com.yahoo.yolean.Exceptions.uncheck; public class CostCalculator { private static final double SELF_HOSTED_DISCOUNT = .5; + private static final CloudName cloudName = CloudName.from("yahoo"); public static String resourceShareByPropertyToCsv(NodeRepository nodeRepository, Controller controller, Clock clock, - Map<Property, ResourceAllocation> fixedAllocations, - CloudName cloudName) { + Map<Property, ResourceAllocation> fixedAllocations) { var date = DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.of("UTC")).format(clock.instant()); @@ -61,14 +61,12 @@ public class CostCalculator { } // Add fixed allocations from config - if (cloudName.equals(CloudName.from("yahoo"))) { - for (var kv : fixedAllocations.entrySet()) { - var property = kv.getKey(); - var allocation = allocationByProperty.getOrDefault(property, ResourceAllocation.ZERO); - var discountedFixedAllocation = kv.getValue().multiply(SELF_HOSTED_DISCOUNT); - allocationByProperty.put(property, allocation.plus(discountedFixedAllocation)); - totalAllocation = totalAllocation.plus(discountedFixedAllocation); - } + for (var kv : fixedAllocations.entrySet()) { + var property = kv.getKey(); + var allocation = allocationByProperty.getOrDefault(property, ResourceAllocation.ZERO); + var discountedFixedAllocation = kv.getValue().multiply(SELF_HOSTED_DISCOUNT); + allocationByProperty.put(property, allocation.plus(discountedFixedAllocation)); + totalAllocation = totalAllocation.plus(discountedFixedAllocation); } return toCsv(allocationByProperty, date, totalAllocation); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiHandler.java deleted file mode 100644 index 8bf3f4a6fd0..00000000000 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiHandler.java +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.controller.restapi.cost; - -import com.yahoo.config.provision.CloudName; -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.container.jdisc.LoggingRequestHandler; -import com.yahoo.restapi.Path; -import com.yahoo.vespa.hosted.controller.Controller; -import com.yahoo.vespa.hosted.controller.api.integration.configserver.NodeRepository; -import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportConsumer; -import com.yahoo.restapi.ErrorResponse; -import com.yahoo.restapi.StringResponse; - -import java.time.Clock; -import java.util.Optional; - -import static com.yahoo.jdisc.http.HttpRequest.Method.GET; - -/** - * @author ldalves - */ -public class CostApiHandler extends LoggingRequestHandler { - - private final Controller controller; - private final NodeRepository nodeRepository; - private final CostReportConsumer costReportConsumer; - - public CostApiHandler(Context ctx, Controller controller) { - super(ctx); - this.controller = controller; - this.nodeRepository = controller.serviceRegistry().configServer().nodeRepository(); - this.costReportConsumer = controller.serviceRegistry().costReportConsumer(); - } - - @Override - public HttpResponse handle(HttpRequest request) { - if (request.getMethod() != GET) { - return ErrorResponse.methodNotAllowed("Method '" + request.getMethod() + "' is not supported"); - } - - Path path = new Path(request.getUri()); - - if (path.matches("/cost/v1/csv")) { - Optional<String> cloudProperty = Optional.ofNullable(request.getProperty("cloud")); - CloudName cloud = cloudProperty.map(CloudName::from).orElse(CloudName.defaultName()); - return new StringResponse(CostCalculator.resourceShareByPropertyToCsv(nodeRepository, controller, Clock.systemUTC(), costReportConsumer.fixedAllocations(), cloud)); - } - - return ErrorResponse.notFoundError("Nothing at " + path); - } -} diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/package-info.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/package-info.java deleted file mode 100644 index a96ae5488fa..00000000000 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage -package com.yahoo.vespa.hosted.controller.restapi.cost; - -import com.yahoo.osgi.annotation.ExportPackage; diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java index da770c9c023..9e03a236f4a 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java @@ -92,9 +92,6 @@ public class ControllerContainerTest { " <handler id='com.yahoo.vespa.hosted.controller.restapi.os.OsApiHandler'>\n" + " <binding>http://*/os/v1/*</binding>\n" + " </handler>\n" + - " <handler id='com.yahoo.vespa.hosted.controller.restapi.cost.CostApiHandler'>\n" + - " <binding>http://*/cost/v1/*</binding>\n" + - " </handler>\n" + " <handler id='com.yahoo.vespa.hosted.controller.restapi.zone.v2.ZoneApiHandler'>\n" + " <binding>http://*/zone/v2</binding>\n" + " <binding>http://*/zone/v2/*</binding>\n" + diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiTest.java deleted file mode 100644 index f992a54a114..00000000000 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiTest.java +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.controller.restapi.cost; - -import com.yahoo.application.container.handler.Request; -import com.yahoo.config.provision.CloudName; -import com.yahoo.config.provision.SystemName; -import com.yahoo.config.provision.zone.ZoneApi; -import com.yahoo.vespa.athenz.api.AthenzIdentity; -import com.yahoo.vespa.athenz.api.AthenzUser; -import com.yahoo.vespa.hosted.controller.integration.ZoneApiMock; -import com.yahoo.vespa.hosted.controller.restapi.ContainerTester; -import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest; -import org.junit.Before; -import org.junit.Test; - -/** - * @author andreer - */ -public class CostApiTest extends ControllerContainerTest { - - private static final String responses = "src/test/java/com/yahoo/vespa/hosted/controller/restapi/cost/responses/"; - private static final AthenzIdentity operator = AthenzUser.fromUserId("operatorUser"); - private static final CloudName cloud1 = CloudName.from("yahoo"); - private static final CloudName cloud2 = CloudName.from("cloud2"); - private static final ZoneApi zone1 = ZoneApiMock.newBuilder().withId("prod.us-east-3").with(cloud1).build(); - private static final ZoneApi zone2 = ZoneApiMock.newBuilder().withId("prod.us-west-1").with(cloud1).build(); - private static final ZoneApi zone3 = ZoneApiMock.newBuilder().withId("prod.eu-west-1").with(cloud2).build(); - - private ContainerTester tester; - - @Before - public void before() { - tester = new ContainerTester(container, responses); - tester.serviceRegistry().zoneRegistry().setSystemName(SystemName.cd) - .setZones(zone1, zone2, zone3); - } - - @Test - public void test_api() { - assertResponse(new Request("http://localhost:8080/cost/v1/csv"), - "Date,Property,Reserved Cpu Cores,Reserved Memory GB,Reserved Disk Space GB,Usage Fraction\n", 200); - } - - private void assertResponse(Request request, String body, int statusCode) { - addIdentityToRequest(request, operator); - tester.assertResponse(request, body, statusCode); - } - -} |