summaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorØyvind Grønnesby <oyving@yahooinc.com>2023-03-08 15:04:28 +0100
committerGitHub <noreply@github.com>2023-03-08 15:04:28 +0100
commit2134efb6eb0f3988571e773f5fe996ec3c3e47ab (patch)
treeeea17153b99b95678d2b5224c77a4bc51412224b /controller-api
parentb180fdfea329bc7e6e09cbcd1fefe67dc2f22202 (diff)
parent3c325c2ee25bc1d39190dfe7ee5b43eadc6225c0 (diff)
Merge pull request #26173 from vespa-engine/ogronnesby/billing-dimensions
New billing dimensions
Diffstat (limited to 'controller-api')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Bill.java13
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/PlanRegistryMock.java3
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java8
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringData.java42
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java12
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java59
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java9
7 files changed, 60 insertions, 86 deletions
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/MeteringData.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringData.java
deleted file mode 100644
index 59ea8440701..00000000000
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringData.java
+++ /dev/null
@@ -1,42 +0,0 @@
-// 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.config.provision.ApplicationId;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author olaa
- */
-public class MeteringData {
-
- private final ResourceAllocation thisMonth;
- private final ResourceAllocation lastMonth;
- private final ResourceAllocation currentSnapshot;
- Map<ApplicationId, List<ResourceSnapshot>> snapshotHistory;
-
- public MeteringData(ResourceAllocation thisMonth, ResourceAllocation lastMonth, ResourceAllocation currentSnapshot, Map<ApplicationId, List<ResourceSnapshot>> snapshotHistory) {
- this.thisMonth = thisMonth;
- this.lastMonth = lastMonth;
- this.currentSnapshot = currentSnapshot;
- this.snapshotHistory = snapshotHistory;
- }
-
- public ResourceAllocation getThisMonth() {
- return thisMonth;
- }
-
- public ResourceAllocation getLastMonth() {
- return lastMonth;
- }
-
- public ResourceAllocation getCurrentSnapshot() {
- return currentSnapshot;
- }
-
- public Map<ApplicationId, List<ResourceSnapshot>> getSnapshotHistory() {
- return snapshotHistory;
- }
-
-}
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..c1d210e990d 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
@@ -78,10 +78,11 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient {
a.getApplicationId(),
a.getZoneId(),
plan,
- a.getArchitecture(),
- BigDecimal.valueOf(a.getCpuCores()).multiply(d),
- BigDecimal.valueOf(a.getMemoryGb()).multiply(d),
- BigDecimal.valueOf(a.getDiskGb()).multiply(d)
+ a.resources().architecture(),
+ a.getVersion().getMajor(),
+ BigDecimal.valueOf(a.resources().vcpu()).multiply(d),
+ BigDecimal.valueOf(a.resources().memoryGb()).multiply(d),
+ BigDecimal.valueOf(a.resources().diskGb()).multiply(d)
);
})
.toList();
@@ -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.resources().architecture(), 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..4a849b831b7 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;
@@ -20,19 +21,21 @@ import java.util.stream.Collectors;
public class ResourceSnapshot {
private final ApplicationId applicationId;
- private final ResourceAllocation resourceAllocation;
+ private final NodeResources resources;
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, NodeResources resources, Instant timestamp, ZoneId zoneId, Version version) {
this.applicationId = applicationId;
- this.resourceAllocation = new ResourceAllocation(cpuCores, memoryGb, diskGb, architecture);
+ this.resources = resources;
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);
+ public static ResourceSnapshot from(ApplicationId applicationId, int nodes, NodeResources resources, Instant timestamp, ZoneId zoneId) {
+ return new ResourceSnapshot(applicationId, resources.multipliedBy(nodes), timestamp, zoneId, Version.emptyVersion);
}
public static ResourceSnapshot from(List<Node> nodes, Instant timestamp, ZoneId zoneId) {
@@ -41,37 +44,26 @@ public class ResourceSnapshot {
.map(node -> node.owner().get())
.collect(Collectors.toSet());
+ Set<Version> versions = nodes.stream()
+ .map(Node::currentVersion)
+ .collect(Collectors.toSet());
+
if (applicationIds.size() != 1) throw new IllegalArgumentException("List of nodes can only represent one application");
+ if (versions.size() != 1) throw new IllegalArgumentException("List of nodes can only represent one version");
+
+ var resources = nodes.stream()
+ .map(Node::resources)
+ .reduce(NodeResources.zero(), NodeResources::add);
- return new ResourceSnapshot(
- applicationIds.iterator().next(),
- nodes.stream().map(Node::resources).mapToDouble(NodeResources::vcpu).sum(),
- nodes.stream().map(Node::resources).mapToDouble(NodeResources::memoryGb).sum(),
- nodes.stream().map(Node::resources).mapToDouble(NodeResources::diskGb).sum(),
- nodes.stream().map(node -> node.resources().architecture()).findFirst().orElse(NodeResources.Architecture.getDefault()),
- timestamp,
- zoneId
- );
+ return new ResourceSnapshot(applicationIds.iterator().next(), resources, timestamp, zoneId, versions.iterator().next());
}
public ApplicationId getApplicationId() {
return applicationId;
}
- public ResourceAllocation allocation() {
- return resourceAllocation;
- }
-
- public double getCpuCores() {
- return resourceAllocation.getCpuCores();
- }
-
- public double getMemoryGb() {
- return resourceAllocation.getMemoryGb();
- }
-
- public double getDiskGb() {
- return resourceAllocation.getDiskGb();
+ public NodeResources resources() {
+ return resources;
}
public Instant getTimestamp() {
@@ -82,8 +74,8 @@ public class ResourceSnapshot {
return zoneId;
}
- public NodeResources.Architecture getArchitecture() {
- return resourceAllocation.getArchitecture();
+ public Version getVersion() {
+ return version;
}
@Override
@@ -93,13 +85,14 @@ public class ResourceSnapshot {
ResourceSnapshot other = (ResourceSnapshot) o;
return this.applicationId.equals(other.applicationId) &&
- this.resourceAllocation.equals(other.resourceAllocation) &&
+ this.resources.equals(other.resources) &&
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, resources, 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;
}