diff options
author | Øyvind Grønnesby <oyving@yahooinc.com> | 2023-03-08 15:04:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-08 15:04:28 +0100 |
commit | 2134efb6eb0f3988571e773f5fe996ec3c3e47ab (patch) | |
tree | eea17153b99b95678d2b5224c77a4bc51412224b /controller-server/src/test/java/com | |
parent | b180fdfea329bc7e6e09cbcd1fefe67dc2f22202 (diff) | |
parent | 3c325c2ee25bc1d39190dfe7ee5b43eadc6225c0 (diff) |
Merge pull request #26173 from vespa-engine/ogronnesby/billing-dimensions
New billing dimensions
Diffstat (limited to 'controller-server/src/test/java/com')
6 files changed, 38 insertions, 23 deletions
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java index 157abe17841..3034c93e593 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java @@ -61,18 +61,20 @@ public class ResourceMeterMaintainerTest { .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().cost().getAsDouble()))); List<ResourceSnapshot> resourceSnapshots = List.of( - new ResourceSnapshot(app1, 12, 34, 56, NodeResources.Architecture.getDefault(), Instant.EPOCH, z1), - new ResourceSnapshot(app1, 23, 45, 67, NodeResources.Architecture.getDefault(), Instant.EPOCH, z2), - new ResourceSnapshot(app2, 34, 56, 78, NodeResources.Architecture.getDefault(), Instant.EPOCH, z1)); + new ResourceSnapshot(app1, resources(12, 34, 56), Instant.EPOCH, z1, Version.emptyVersion), + new ResourceSnapshot(app1, resources(23, 45, 67), Instant.EPOCH, z2, Version.emptyVersion), + new ResourceSnapshot(app2, resources(34, 56, 78), Instant.EPOCH, z1, Version.emptyVersion)); + maintainer.updateDeploymentCost(resourceSnapshots); assertCost.accept(app1, Map.of(z1, 1.72, z2, 3.05)); assertCost.accept(app2, Map.of(z1, 4.39)); // Remove a region from app1 and add region to app2 resourceSnapshots = List.of( - new ResourceSnapshot(app1, 23, 45, 67, NodeResources.Architecture.getDefault(), Instant.EPOCH, z2), - new ResourceSnapshot(app2, 34, 56, 78, NodeResources.Architecture.getDefault(), Instant.EPOCH, z1), - new ResourceSnapshot(app2, 45, 67, 89, NodeResources.Architecture.getDefault(), Instant.EPOCH, z2)); + new ResourceSnapshot(app1, resources(23, 45, 67), Instant.EPOCH, z2, Version.emptyVersion), + new ResourceSnapshot(app2, resources(34, 56, 78), Instant.EPOCH, z1, Version.emptyVersion), + new ResourceSnapshot(app2, resources(45, 67, 89), Instant.EPOCH, z2, Version.emptyVersion)); + maintainer.updateDeploymentCost(resourceSnapshots); assertCost.accept(app1, Map.of(z2, 3.05)); assertCost.accept(app2, Map.of(z1, 4.39, z2, 5.72)); @@ -97,13 +99,13 @@ public class ResourceMeterMaintainerTest { ResourceSnapshot app1 = consumedResources.stream().filter(snapshot -> snapshot.getApplicationId().equals(ApplicationId.from("tenant1", "app1", "default"))).findFirst().orElseThrow(); ResourceSnapshot app2 = consumedResources.stream().filter(snapshot -> snapshot.getApplicationId().equals(ApplicationId.from("tenant2", "app2", "default"))).findFirst().orElseThrow(); - assertEquals(24, app1.getCpuCores(), Double.MIN_VALUE); - assertEquals(24, app1.getMemoryGb(), Double.MIN_VALUE); - assertEquals(500, app1.getDiskGb(), Double.MIN_VALUE); + assertEquals(24, app1.resources().vcpu(), Double.MIN_VALUE); + assertEquals(24, app1.resources().memoryGb(), Double.MIN_VALUE); + assertEquals(500, app1.resources().diskGb(), Double.MIN_VALUE); - assertEquals(40, app2.getCpuCores(), Double.MIN_VALUE); - assertEquals(24, app2.getMemoryGb(), Double.MIN_VALUE); - assertEquals(500, app2.getDiskGb(), Double.MIN_VALUE); + assertEquals(40, app2.resources().vcpu(), Double.MIN_VALUE); + assertEquals(24, app2.resources().memoryGb(), Double.MIN_VALUE); + assertEquals(500, app2.resources().diskGb(), Double.MIN_VALUE); assertEquals(tester.clock().millis() / 1000, metrics.getMetric("metering_last_reported")); assertEquals(2224.0d, (Double) metrics.getMetric("metering_total_reported"), Double.MIN_VALUE); @@ -154,4 +156,8 @@ public class ResourceMeterMaintainerTest { .build()) .toList(); } + + private NodeResources resources(double cpu, double ram, double disk) { + return new NodeResources(cpu, ram, disk, 0, NodeResources.DiskSpeed.getDefault(), NodeResources.StorageType.getDefault(), NodeResources.Architecture.getDefault(), NodeResources.GpuResources.getDefault()); + } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2Test.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2Test.java index 857dcbac6fd..43271277ce9 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2Test.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2Test.java @@ -103,7 +103,7 @@ public class BillingApiHandlerV2Test extends ControllerContainerCloudTest { var singleRequest = request("/billing/v2/tenant/" + tenant + "/bill/id-1").roles(tenantReader); tester.assertResponse(singleRequest, """ - {"id":"id-1","from":"2020-05-23","to":"2020-05-28","total":"123.00","status":"OPEN","statusHistory":[{"at":"2020-05-23T00:00:00Z","status":"OPEN"}],"items":[{"id":"some-id","description":"description","amount":"123.00","plan":{"id":"paid","name":"Paid Plan - for testing purposes"},"cpu":{},"memory":{},"disk":{}}]}"""); + {"id":"id-1","from":"2020-05-23","to":"2020-05-28","total":"123.00","status":"OPEN","statusHistory":[{"at":"2020-05-23T00:00:00Z","status":"OPEN"}],"items":[{"id":"some-id","description":"description","amount":"123.00","plan":{"id":"paid","name":"Paid Plan - for testing purposes"},"majorVersion":0,"cpu":{},"memory":{},"disk":{}}]}"""); } @Test diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/billing-all-tenants.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/billing-all-tenants.json index e9b18a879b9..d761439667a 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/billing-all-tenants.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/billing-all-tenants.json @@ -16,7 +16,8 @@ "description": "description", "amount": "123.00", "plan": "paid", - "planName": "Plan with id: paid" + "planName": "Plan with id: paid", + "majorVersion": 0 } ] }, @@ -27,7 +28,8 @@ "description": "support", "amount": "42.00", "plan": "some-plan", - "planName": "Plan with id: some-plan" + "planName": "Plan with id: some-plan", + "majorVersion": 0 } ] } @@ -47,7 +49,8 @@ "description": "description", "amount": "123.00", "plan": "paid", - "planName": "Plan with id: paid" + "planName": "Plan with id: paid", + "majorVersion": 0 } ] }, diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/line-item-list.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/line-item-list.json index e8404b12dd8..fbfc5ce09ee 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/line-item-list.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/line-item-list.json @@ -5,7 +5,8 @@ "description": "some description", "amount": "123.45", "plan": "some-plan", - "planName": "Plan with id: some-plan" + "planName": "Plan with id: some-plan", + "majorVersion": 0 } ] } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/tenant-billing-view.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/tenant-billing-view.json index adb319a3642..4e255205e19 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/tenant-billing-view.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/tenant-billing-view.json @@ -12,7 +12,8 @@ "description": "description", "amount": "123.00", "plan": "paid", - "planName": "Plan with id: paid" + "planName": "Plan with id: paid", + "majorVersion": 0 } ] }, @@ -38,7 +39,8 @@ "description": "description", "amount": "123.00", "plan": "paid", - "planName": "Plan with id: paid" + "planName": "Plan with id: paid", + "majorVersion": 0 } ] } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/ControllerApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/ControllerApiTest.java index e3a0684771c..ac7287b7e27 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/ControllerApiTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/ControllerApiTest.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.restapi.controller; import com.yahoo.application.container.handler.Request; +import com.yahoo.component.Version; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; @@ -157,10 +158,12 @@ public class ControllerApiTest extends ControllerContainerTest { ApplicationId applicationId = ApplicationId.from("tenant", "app", "instance"); Instant timestamp = Instant.ofEpochMilli(123456789); ZoneId zoneId = ZoneId.defaultId(); - List<ResourceSnapshot> snapshots = List.of( - new ResourceSnapshot(applicationId, 12, 48, 1200, NodeResources.Architecture.arm64, timestamp, zoneId), - new ResourceSnapshot(applicationId, 24, 96, 2400, NodeResources.Architecture.x86_64, timestamp, zoneId) - ); + var resources = List.of( + new NodeResources(12, 48, 1200, 0, NodeResources.DiskSpeed.any, NodeResources.StorageType.any, NodeResources.Architecture.arm64), + new NodeResources(24, 96, 2400, 0, NodeResources.DiskSpeed.any, NodeResources.StorageType.any, NodeResources.Architecture.x86_64)); + + var snapshots = resources.stream().map(x -> new ResourceSnapshot(applicationId, x, timestamp, zoneId, Version.emptyVersion)).toList(); + tester.controller().serviceRegistry().resourceDatabase().writeResourceSnapshots(snapshots); tester.assertResponse( operatorRequest("http://localhost:8080/controller/v1/metering/tenant/tenantName/month/2020-02", "", Request.Method.GET), |