From e97115b107f378e60aa060af4ac4d4fafc83ab46 Mon Sep 17 00:00:00 2001 From: Øyvind Grønnesby Date: Wed, 22 Feb 2023 15:08:58 +0100 Subject: Add major version to billing --- .../controller/api/integration/billing/Bill.java | 13 ++++++++++--- .../api/integration/billing/PlanRegistryMock.java | 3 ++- .../controller/api/integration/resource/CostInfo.java | 8 +++++++- .../resource/ResourceDatabaseClientMock.java | 4 +++- .../api/integration/resource/ResourceSnapshot.java | 19 ++++++++++++++----- .../api/integration/resource/ResourceUsage.java | 9 ++++++++- 6 files changed, 44 insertions(+), 12 deletions(-) (limited to 'controller-api') diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Bill.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Bill.java index 01488711f59..854413a4adb 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Bill.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Bill.java @@ -189,6 +189,7 @@ public class Bill { private BigDecimal memoryCost; private BigDecimal diskCost; private NodeResources.Architecture architecture; + private int majorVersion; public LineItem(String id, String description, BigDecimal amount, String plan, String agent, ZonedDateTime addedAt) { this.id = id; @@ -200,7 +201,7 @@ public class Bill { } public LineItem(String id, String description, BigDecimal amount, String plan, String agent, ZonedDateTime addedAt, ZonedDateTime startedAt, ZonedDateTime endedAt, ApplicationId applicationId, ZoneId zoneId, - BigDecimal cpuHours, BigDecimal memoryHours, BigDecimal diskHours, BigDecimal cpuCost, BigDecimal memoryCost, BigDecimal diskCost, NodeResources.Architecture architecture) { + BigDecimal cpuHours, BigDecimal memoryHours, BigDecimal diskHours, BigDecimal cpuCost, BigDecimal memoryCost, BigDecimal diskCost, NodeResources.Architecture architecture, int majorVersion) { this(id, description, amount, plan, agent, addedAt); this.startedAt = startedAt; this.endedAt = endedAt; @@ -217,6 +218,7 @@ public class Bill { this.memoryCost = memoryCost; this.diskCost = diskCost; this.architecture = architecture; + this.majorVersion = majorVersion; } /** The opaque ID of this */ @@ -297,6 +299,10 @@ public class Bill { return Optional.ofNullable(architecture); } + public int getMajorVersion() { + return majorVersion; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -311,12 +317,13 @@ public class Bill { startedAt.equals(lineItem.startedAt) && endedAt.equals(lineItem.endedAt) && applicationId.equals(lineItem.applicationId) && - zoneId.equals(lineItem.zoneId); + zoneId.equals(lineItem.zoneId) && + majorVersion == lineItem.majorVersion; } @Override public int hashCode() { - return Objects.hash(id, description, amount, plan, agent, addedAt, startedAt, endedAt, applicationId, zoneId); + return Objects.hash(id, description, amount, plan, agent, addedAt, startedAt, endedAt, applicationId, zoneId, majorVersion); } @Override diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/PlanRegistryMock.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/PlanRegistryMock.java index 723ffa383eb..ecce9b7ccfa 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/PlanRegistryMock.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/PlanRegistryMock.java @@ -124,7 +124,8 @@ public class PlanRegistryMock implements PlanRegistry { cpuCost, memCost, dgbCost, - usage.getArchitecture() + usage.getArchitecture(), + usage.getMajorVersion() ); } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java index c756100e563..571a7b5a58e 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java @@ -21,11 +21,12 @@ public class CostInfo { private final BigDecimal memoryCost; private final BigDecimal diskCost; private final NodeResources.Architecture architecture; + private final int majorVersion; public CostInfo(ApplicationId applicationId, ZoneId zoneId, BigDecimal cpuHours, BigDecimal memoryHours, BigDecimal diskHours, - BigDecimal cpuCost, BigDecimal memoryCost, BigDecimal diskCost, NodeResources.Architecture architecture) { + BigDecimal cpuCost, BigDecimal memoryCost, BigDecimal diskCost, NodeResources.Architecture architecture, int majorVersion) { this.applicationId = applicationId; this.zoneId = zoneId; this.cpuHours = cpuHours; @@ -35,6 +36,7 @@ public class CostInfo { this.memoryCost = memoryCost; this.diskCost = diskCost; this.architecture = architecture; + this.majorVersion = majorVersion; } public ApplicationId getApplicationId() { @@ -77,4 +79,8 @@ public class CostInfo { return architecture; } + public int getMajorVersion() { + return majorVersion; + } + } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java index 542bdd52477..d04d400d36f 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java @@ -79,6 +79,7 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient { a.getZoneId(), plan, a.getArchitecture(), + a.getVersion().getMajor(), BigDecimal.valueOf(a.getCpuCores()).multiply(d), BigDecimal.valueOf(a.getMemoryGb()).multiply(d), BigDecimal.valueOf(a.getDiskGb()).multiply(d) @@ -97,6 +98,7 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient { a.getZoneId(), a.getPlan(), a.getArchitecture(), + a.getMajorVersion(), a.getCpuMillis().add(b.getCpuMillis()), a.getMemoryMillis().add(b.getMemoryMillis()), a.getDiskMillis().add(b.getDiskMillis()) @@ -112,7 +114,7 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient { .filter(snapshot -> snapshot.getTimestamp().isBefore(Instant.ofEpochMilli(end))) .filter(snapshot -> snapshot.getApplicationId().tenant().equals(tenantName)) .collect(Collectors.groupingBy( - usage -> Objects.hash(usage.getApplicationId(), usage.getZoneId(), tenantPlan.id().value()) + usage -> Objects.hash(usage.getApplicationId(), usage.getZoneId(), tenantPlan.id().value(), usage.getArchitecture(), usage.getVersion().getMajor()) )) .values().stream() .map(snapshots -> resourceUsageFromSnapshots(tenantPlan, snapshots)) diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java index 85ee23f4df0..4ff79706683 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.resource; +import com.yahoo.component.Version; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; @@ -23,16 +24,18 @@ public class ResourceSnapshot { private final ResourceAllocation resourceAllocation; private final Instant timestamp; private final ZoneId zoneId; + private final Version version; - public ResourceSnapshot(ApplicationId applicationId, double cpuCores, double memoryGb, double diskGb, NodeResources.Architecture architecture, Instant timestamp, ZoneId zoneId) { + public ResourceSnapshot(ApplicationId applicationId, double cpuCores, double memoryGb, double diskGb, NodeResources.Architecture architecture, Instant timestamp, ZoneId zoneId, Version version) { this.applicationId = applicationId; this.resourceAllocation = new ResourceAllocation(cpuCores, memoryGb, diskGb, architecture); this.timestamp = timestamp; this.zoneId = zoneId; + this.version = version; } public static ResourceSnapshot from(ApplicationId applicationId, int nodes, double cpuCores, double memoryGb, double diskGb, NodeResources.Architecture architecture, Instant timestamp, ZoneId zoneId) { - return new ResourceSnapshot(applicationId, cpuCores * nodes, memoryGb * nodes, diskGb * nodes, architecture, timestamp, zoneId); + return new ResourceSnapshot(applicationId, cpuCores * nodes, memoryGb * nodes, diskGb * nodes, architecture, timestamp, zoneId, Version.emptyVersion); } public static ResourceSnapshot from(List nodes, Instant timestamp, ZoneId zoneId) { @@ -50,7 +53,8 @@ public class ResourceSnapshot { nodes.stream().map(Node::resources).mapToDouble(NodeResources::diskGb).sum(), nodes.stream().map(node -> node.resources().architecture()).findFirst().orElse(NodeResources.Architecture.getDefault()), timestamp, - zoneId + zoneId, + nodes.stream().map(Node::currentVersion).min(Version::compareTo).orElse(Version.emptyVersion) ); } @@ -82,6 +86,10 @@ public class ResourceSnapshot { return zoneId; } + public Version getVersion() { + return version; + } + public NodeResources.Architecture getArchitecture() { return resourceAllocation.getArchitecture(); } @@ -95,11 +103,12 @@ public class ResourceSnapshot { return this.applicationId.equals(other.applicationId) && this.resourceAllocation.equals(other.resourceAllocation) && this.timestamp.equals(other.timestamp) && - this.zoneId.equals(other.zoneId); + this.zoneId.equals(other.zoneId) && + this.version.equals(other.version); } @Override public int hashCode(){ - return Objects.hash(applicationId, resourceAllocation, timestamp, zoneId); + return Objects.hash(applicationId, resourceAllocation, timestamp, zoneId, version); } } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java index 850ca040d03..bd1252d0879 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.resource; +import com.yahoo.component.Version; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; @@ -17,9 +18,10 @@ public class ResourceUsage { private final BigDecimal memoryMillis; private final BigDecimal diskMillis; private final NodeResources.Architecture architecture; + private final int majorVersion; public ResourceUsage(ApplicationId applicationId, ZoneId zoneId, Plan plan, NodeResources.Architecture architecture, - BigDecimal cpuMillis, BigDecimal memoryMillis, BigDecimal diskMillis) { + int majorVersion, BigDecimal cpuMillis, BigDecimal memoryMillis, BigDecimal diskMillis) { this.applicationId = applicationId; this.zoneId = zoneId; this.cpuMillis = cpuMillis; @@ -27,6 +29,7 @@ public class ResourceUsage { this.diskMillis = diskMillis; this.plan = plan; this.architecture = architecture; + this.majorVersion = majorVersion; } public ApplicationId getApplicationId() { @@ -53,6 +56,10 @@ public class ResourceUsage { return plan; } + public int getMajorVersion() { + return majorVersion; + } + public NodeResources.Architecture getArchitecture() { return architecture; } -- cgit v1.2.3