From f31bdad79851056a49ed873353fde73c84f92c61 Mon Sep 17 00:00:00 2001 From: Ola Aunrønning Date: Wed, 23 Mar 2022 14:30:29 +0100 Subject: Include architecture in metering. Remove unused metering API --- .../hosted/controller/api/integration/billing/Bill.java | 9 ++++++++- .../api/integration/billing/PlanRegistryMock.java | 3 ++- .../controller/api/integration/resource/CostInfo.java | 9 ++++++++- .../api/integration/resource/MeteringClient.java | 2 -- .../api/integration/resource/ResourceAllocation.java | 16 ++++++++++++---- .../api/integration/resource/ResourceDatabaseClient.java | 2 -- .../integration/resource/ResourceDatabaseClientMock.java | 16 +++------------- .../api/integration/resource/ResourceSnapshot.java | 13 +++++++++---- .../api/integration/resource/ResourceUsage.java | 8 +++++++- .../api/integration/stubs/MockMeteringClient.java | 11 ----------- 10 files changed, 49 insertions(+), 40 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 1788154b9e2..01488711f59 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 @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.api.integration.billing; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.zone.ZoneId; @@ -187,6 +188,7 @@ public class Bill { private BigDecimal cpuCost; private BigDecimal memoryCost; private BigDecimal diskCost; + private NodeResources.Architecture architecture; public LineItem(String id, String description, BigDecimal amount, String plan, String agent, ZonedDateTime addedAt) { this.id = id; @@ -198,7 +200,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) { + BigDecimal cpuHours, BigDecimal memoryHours, BigDecimal diskHours, BigDecimal cpuCost, BigDecimal memoryCost, BigDecimal diskCost, NodeResources.Architecture architecture) { this(id, description, amount, plan, agent, addedAt); this.startedAt = startedAt; this.endedAt = endedAt; @@ -214,6 +216,7 @@ public class Bill { this.cpuCost = cpuCost; this.memoryCost = memoryCost; this.diskCost = diskCost; + this.architecture = architecture; } /** The opaque ID of this */ @@ -290,6 +293,10 @@ public class Bill { return Optional.ofNullable(diskCost); } + public Optional getArchitecture() { + return Optional.ofNullable(architecture); + } + @Override public boolean equals(Object o) { if (this == o) return true; 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 5fb4d853e67..4757fa76224 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 @@ -117,7 +117,8 @@ public class PlanRegistryMock implements PlanRegistry { usage.getDiskMillis().divide(millisPerHour, RoundingMode.HALF_UP), cpuCost, memCost, - dgbCost + dgbCost, + usage.getArchitecture() ); } 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 3bc9580307b..c756100e563 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 @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.api.integration.resource; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; import java.math.BigDecimal; @@ -19,11 +20,12 @@ public class CostInfo { private final BigDecimal cpuCost; private final BigDecimal memoryCost; private final BigDecimal diskCost; + private final NodeResources.Architecture architecture; public CostInfo(ApplicationId applicationId, ZoneId zoneId, BigDecimal cpuHours, BigDecimal memoryHours, BigDecimal diskHours, - BigDecimal cpuCost, BigDecimal memoryCost, BigDecimal diskCost) { + BigDecimal cpuCost, BigDecimal memoryCost, BigDecimal diskCost, NodeResources.Architecture architecture) { this.applicationId = applicationId; this.zoneId = zoneId; this.cpuHours = cpuHours; @@ -32,6 +34,7 @@ public class CostInfo { this.cpuCost = cpuCost; this.memoryCost = memoryCost; this.diskCost = diskCost; + this.architecture = architecture; } public ApplicationId getApplicationId() { @@ -70,4 +73,8 @@ public class CostInfo { return cpuCost.add(memoryCost).add(diskCost); } + public NodeResources.Architecture getArchitecture() { + return architecture; + } + } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringClient.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringClient.java index 767ba4aa34b..944a5eaf696 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringClient.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringClient.java @@ -17,8 +17,6 @@ public interface MeteringClient { void consume(Collection resources); - MeteringData getMeteringData(TenantName tenantName, ApplicationName applicationName); - List getSnapshotHistoryForTenant(TenantName tenantName, YearMonth yearMonth); void refresh(); diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java index 742e3a01171..8191540e898 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java @@ -1,6 +1,8 @@ // 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.NodeResources; + import java.util.Objects; /** @@ -10,16 +12,18 @@ import java.util.Objects; */ public class ResourceAllocation { - public static final ResourceAllocation ZERO = new ResourceAllocation(0, 0, 0); + public static final ResourceAllocation ZERO = new ResourceAllocation(0, 0, 0, NodeResources.Architecture.getDefault()); private final double cpuCores; private final double memoryGb; private final double diskGb; + private final NodeResources.Architecture architecture; - public ResourceAllocation(double cpuCores, double memoryGb, double diskGb) { + public ResourceAllocation(double cpuCores, double memoryGb, double diskGb, NodeResources.Architecture architecture) { this.cpuCores = cpuCores; this.memoryGb = memoryGb; this.diskGb = diskGb; + this.architecture = architecture; } public double usageFraction(ResourceAllocation total) { @@ -38,14 +42,18 @@ public class ResourceAllocation { return diskGb; } + public NodeResources.Architecture getArchitecture() { + return architecture; + } + /** Returns a copy of this with the given allocation added */ public ResourceAllocation plus(ResourceAllocation allocation) { - return new ResourceAllocation(cpuCores + allocation.cpuCores, memoryGb + allocation.memoryGb, diskGb + allocation.diskGb); + return new ResourceAllocation(cpuCores + allocation.cpuCores, memoryGb + allocation.memoryGb, diskGb + allocation.diskGb, architecture); } /** Returns a copy of this with each resource multiplied by given factor */ public ResourceAllocation multiply(double multiplicand) { - return new ResourceAllocation(cpuCores * multiplicand, memoryGb * multiplicand, diskGb * multiplicand); + return new ResourceAllocation(cpuCores * multiplicand, memoryGb * multiplicand, diskGb * multiplicand, architecture); } @Override diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java index 2f277193231..8ae12c0e7ac 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java @@ -18,8 +18,6 @@ public interface ResourceDatabaseClient { void writeResourceSnapshots(Collection snapshots); - List getResourceSnapshotsForMonth(TenantName tenantName, ApplicationName applicationName, YearMonth month); - List getResourceSnapshotsForPeriod(TenantName tenantName, long startTimestamp, long endTimestamp); void refreshMaterializedView(); 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 5a4d250ea9d..c680990e240 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 @@ -44,19 +44,6 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient { this.resourceSnapshots.addAll(items); } - @Override - public List getResourceSnapshotsForMonth(TenantName tenantName, ApplicationName applicationName, YearMonth month) { - return resourceSnapshots.stream() - .filter(resourceSnapshot -> { - LocalDate snapshotDate = LocalDate.ofInstant(resourceSnapshot.getTimestamp(), ZoneId.of("UTC")); - return YearMonth.from(snapshotDate).equals(month) && - snapshotDate.getYear() == month.getYear() && - resourceSnapshot.getApplicationId().tenant().equals(tenantName) && - resourceSnapshot.getApplicationId().application().equals(applicationName); - }) - .collect(Collectors.toList()); - } - @Override public Set getMonthsWithSnapshotsForTenant(TenantName tenantName) { return Collections.emptySet(); @@ -88,6 +75,7 @@ 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) @@ -100,10 +88,12 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient { assert a.getApplicationId().equals(b.getApplicationId()); assert a.getZoneId().equals(b.getZoneId()); assert a.getPlan().equals(b.getPlan()); + assert a.getArchitecture().equals(b.getArchitecture()); return new ResourceUsage( a.getApplicationId(), a.getZoneId(), a.getPlan(), + a.getArchitecture(), a.getCpuMillis().add(b.getCpuMillis()), a.getMemoryMillis().add(b.getMemoryMillis()), a.getDiskMillis().add(b.getDiskMillis()) 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 9b3de004bae..85ee23f4df0 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 @@ -24,15 +24,15 @@ public class ResourceSnapshot { private final Instant timestamp; private final ZoneId zoneId; - public ResourceSnapshot(ApplicationId applicationId, double cpuCores, double memoryGb, double diskGb, Instant timestamp, ZoneId zoneId) { + public ResourceSnapshot(ApplicationId applicationId, double cpuCores, double memoryGb, double diskGb, NodeResources.Architecture architecture, Instant timestamp, ZoneId zoneId) { this.applicationId = applicationId; - this.resourceAllocation = new ResourceAllocation(cpuCores, memoryGb, diskGb); + this.resourceAllocation = new ResourceAllocation(cpuCores, memoryGb, diskGb, architecture); this.timestamp = timestamp; this.zoneId = zoneId; } - public static ResourceSnapshot from(ApplicationId applicationId, int nodes, double cpuCores, double memoryGb, double diskGb, Instant timestamp, ZoneId zoneId) { - return new ResourceSnapshot(applicationId, cpuCores * nodes, memoryGb * nodes, diskGb * nodes, timestamp, zoneId); + 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(List nodes, Instant timestamp, ZoneId zoneId) { @@ -48,6 +48,7 @@ public class ResourceSnapshot { 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 ); @@ -81,6 +82,10 @@ public class ResourceSnapshot { return zoneId; } + public NodeResources.Architecture getArchitecture() { + return resourceAllocation.getArchitecture(); + } + @Override public boolean equals(Object o) { if (this == o) return true; 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 fdea3b26372..850ca040d03 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 @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.api.integration.resource; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.vespa.hosted.controller.api.integration.billing.Plan; @@ -15,8 +16,9 @@ public class ResourceUsage { private final BigDecimal cpuMillis; private final BigDecimal memoryMillis; private final BigDecimal diskMillis; + private final NodeResources.Architecture architecture; - public ResourceUsage(ApplicationId applicationId, ZoneId zoneId, Plan plan, + public ResourceUsage(ApplicationId applicationId, ZoneId zoneId, Plan plan, NodeResources.Architecture architecture, BigDecimal cpuMillis, BigDecimal memoryMillis, BigDecimal diskMillis) { this.applicationId = applicationId; this.zoneId = zoneId; @@ -24,6 +26,7 @@ public class ResourceUsage { this.memoryMillis = memoryMillis; this.diskMillis = diskMillis; this.plan = plan; + this.architecture = architecture; } public ApplicationId getApplicationId() { @@ -50,4 +53,7 @@ public class ResourceUsage { return plan; } + public NodeResources.Architecture getArchitecture() { + return architecture; + } } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java index 003ecb32a32..ca094f98607 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java @@ -1,17 +1,14 @@ // 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.stubs; -import com.yahoo.config.provision.ApplicationName; import com.yahoo.config.provision.TenantName; import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringData; -import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAllocation; import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceSnapshot; import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringClient; import java.time.YearMonth; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -31,14 +28,6 @@ public class MockMeteringClient implements MeteringClient { this.resources = resources; } - @Override - public MeteringData getMeteringData(TenantName tenantName, ApplicationName applicationName) { - return meteringData.orElseGet(() -> { - ResourceAllocation emptyAllocation = new ResourceAllocation(0, 0, 0); - return new MeteringData(emptyAllocation, emptyAllocation, emptyAllocation, Collections.emptyMap()); - }); - } - @Override public List getSnapshotHistoryForTenant(TenantName tenantName, YearMonth yearMonth) { return new ArrayList<>(resources); -- cgit v1.2.3