diff options
author | Ola Aunrønning <olaa@verizonmedia.com> | 2022-03-23 14:30:29 +0100 |
---|---|---|
committer | Ola Aunrønning <olaa@verizonmedia.com> | 2022-03-23 14:30:29 +0100 |
commit | f31bdad79851056a49ed873353fde73c84f92c61 (patch) | |
tree | 0916af15ff94e6264b76cf768096215a10eb96a5 | |
parent | 54329a8946debe301d2036397bc4a9d47764555f (diff) |
Include architecture in metering. Remove unused metering API
19 files changed, 91 insertions, 144 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 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<NodeResources.Architecture> 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<ResourceSnapshot> resources); - MeteringData getMeteringData(TenantName tenantName, ApplicationName applicationName); - List<ResourceSnapshot> 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<ResourceSnapshot> snapshots); - List<ResourceSnapshot> getResourceSnapshotsForMonth(TenantName tenantName, ApplicationName applicationName, YearMonth month); - List<ResourceUsage> 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 @@ -45,19 +45,6 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient { } @Override - public List<ResourceSnapshot> 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<YearMonth> 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<Node> 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; @@ -32,14 +29,6 @@ public class MockMeteringClient implements MeteringClient { } @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<ResourceSnapshot> getSnapshotHistoryForTenant(TenantName tenantName, YearMonth yearMonth) { return new ArrayList<>(resources); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java index acaf35133d7..81001b5371b 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java @@ -150,14 +150,21 @@ public class ResourceMeterMaintainer extends ControllerMaintainer { .filter(this::unlessNodeOwnerIsSystemApplication) .filter(this::isNodeStateMeterable) .filter(this::isClusterTypeMeterable) + // Grouping by ApplicationId -> Architecture -> ResourceSnapshot .collect(Collectors.groupingBy(node -> node.owner().get(), - Collectors.collectingAndThen(Collectors.toList(), - nodeList -> ResourceSnapshot.from( - nodeList, - clock.instant(), - zoneId)) - )).values(); + Collectors.collectingAndThen(Collectors.groupingBy(node -> node.resources().architecture()), + nodeList -> nodeList.entrySet() + .stream() + .collect(Collectors.toMap( + Map.Entry::getKey, + entry -> ResourceSnapshot.from(entry.getValue(), clock.instant(), zoneId)) + )) + )) + .values() + .stream() + .flatMap(list -> list.values().stream()) + .collect(Collectors.toList()); } private boolean unlessNodeOwnerIsSystemApplication(Node node) { @@ -182,7 +189,7 @@ public class ResourceMeterMaintainer extends ControllerMaintainer { public static double cost(ClusterResources clusterResources, SystemName systemName) { NodeResources nr = clusterResources.nodeResources(); - return cost(new ResourceAllocation(nr.vcpu(), nr.memoryGb(), nr.diskGb()).multiply(clusterResources.nodes()), systemName); + return cost(new ResourceAllocation(nr.vcpu(), nr.memoryGb(), nr.diskGb(), nr.architecture()).multiply(clusterResources.nodes()), systemName); } private static double cost(ResourceAllocation allocation, SystemName systemName) { @@ -201,7 +208,7 @@ public class ResourceMeterMaintainer extends ControllerMaintainer { metric.createContext(Collections.emptyMap())); resourceSnapshots.forEach(snapshot -> { - var context = getMetricContext(snapshot.getApplicationId(), snapshot.getZoneId()); + var context = getMetricContext(snapshot); metric.set("metering.vcpu", snapshot.getCpuCores(), context); metric.set("metering.memoryGB", snapshot.getMemoryGb(), context); metric.set("metering.diskGB", snapshot.getDiskGb(), context); @@ -222,4 +229,13 @@ public class ResourceMeterMaintainer extends ControllerMaintainer { "zoneId", zoneId.value() )); } + + private Metric.Context getMetricContext(ResourceSnapshot snapshot) { + return metric.createContext(Map.of( + "tenant", snapshot.getApplicationId().tenant().value(), + "applicationId", snapshot.getApplicationId().toFullString(), + "zoneId", snapshot.getZoneId().value(), + "architecture", snapshot.getArchitecture() + )); + } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/metric/CostCalculator.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/metric/CostCalculator.java index 089767dc586..b36b2b9cad8 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/metric/CostCalculator.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/metric/CostCalculator.java @@ -57,7 +57,7 @@ public class CostCalculator { Property property = propertyByTenantName.get(node.owner().get().tenant()); if (property == null) continue; var allocation = allocationByProperty.getOrDefault(property, ResourceAllocation.ZERO); - var nodeAllocation = new ResourceAllocation(node.resources().vcpu(), node.resources().memoryGb(), node.resources().diskGb()); + var nodeAllocation = new ResourceAllocation(node.resources().vcpu(), node.resources().memoryGb(), node.resources().diskGb(), node.resources().architecture()); allocationByProperty.put(property, allocation.plus(nodeAllocation)); totalAllocation = totalAllocation.plus(nodeAllocation); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index 246f3fff17e..a0a1ecb17a9 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -255,7 +255,6 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { if (path.matches("/application/v4/tenant/{tenant}/application/{application}/diff/{number}")) return applicationPackageDiff(path.get("tenant"), path.get("application"), path.get("number")); if (path.matches("/application/v4/tenant/{tenant}/application/{application}/deploying")) return deploying(path.get("tenant"), path.get("application"), "default", request); if (path.matches("/application/v4/tenant/{tenant}/application/{application}/deploying/pin")) return deploying(path.get("tenant"), path.get("application"), "default", request); - if (path.matches("/application/v4/tenant/{tenant}/application/{application}/metering")) return metering(path.get("tenant"), path.get("application"), request); if (path.matches("/application/v4/tenant/{tenant}/application/{application}/instance")) return applications(path.get("tenant"), Optional.of(path.get("application")), request); if (path.matches("/application/v4/tenant/{tenant}/application/{application}/instance/{instance}")) return instance(path.get("tenant"), path.get("application"), path.get("instance"), request); if (path.matches("/application/v4/tenant/{tenant}/application/{application}/instance/{instance}/deploying")) return deploying(path.get("tenant"), path.get("application"), path.get("instance"), request); @@ -1762,68 +1761,6 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { return new SlimeJsonResponse(slime); } - private HttpResponse metering(String tenant, String application, HttpRequest request) { - - Slime slime = new Slime(); - Cursor root = slime.setObject(); - - MeteringData meteringData = controller.serviceRegistry() - .meteringService() - .getMeteringData(TenantName.from(tenant), ApplicationName.from(application)); - - ResourceAllocation currentSnapshot = meteringData.getCurrentSnapshot(); - Cursor currentRate = root.setObject("currentrate"); - currentRate.setDouble("cpu", currentSnapshot.getCpuCores()); - currentRate.setDouble("mem", currentSnapshot.getMemoryGb()); - currentRate.setDouble("disk", currentSnapshot.getDiskGb()); - - ResourceAllocation thisMonth = meteringData.getThisMonth(); - Cursor thismonth = root.setObject("thismonth"); - thismonth.setDouble("cpu", thisMonth.getCpuCores()); - thismonth.setDouble("mem", thisMonth.getMemoryGb()); - thismonth.setDouble("disk", thisMonth.getDiskGb()); - - ResourceAllocation lastMonth = meteringData.getLastMonth(); - Cursor lastmonth = root.setObject("lastmonth"); - lastmonth.setDouble("cpu", lastMonth.getCpuCores()); - lastmonth.setDouble("mem", lastMonth.getMemoryGb()); - lastmonth.setDouble("disk", lastMonth.getDiskGb()); - - - Map<ApplicationId, List<ResourceSnapshot>> history = meteringData.getSnapshotHistory(); - Cursor details = root.setObject("details"); - - Cursor detailsCpu = details.setObject("cpu"); - Cursor detailsMem = details.setObject("mem"); - Cursor detailsDisk = details.setObject("disk"); - - history.forEach((applicationId, resources) -> { - String instanceName = applicationId.instance().value(); - Cursor detailsCpuApp = detailsCpu.setObject(instanceName); - Cursor detailsMemApp = detailsMem.setObject(instanceName); - Cursor detailsDiskApp = detailsDisk.setObject(instanceName); - Cursor detailsCpuData = detailsCpuApp.setArray("data"); - Cursor detailsMemData = detailsMemApp.setArray("data"); - Cursor detailsDiskData = detailsDiskApp.setArray("data"); - - resources.forEach(resourceSnapshot -> { - Cursor cpu = detailsCpuData.addObject(); - cpu.setLong("unixms", resourceSnapshot.getTimestamp().toEpochMilli()); - cpu.setDouble("value", resourceSnapshot.getCpuCores()); - - Cursor mem = detailsMemData.addObject(); - mem.setLong("unixms", resourceSnapshot.getTimestamp().toEpochMilli()); - mem.setDouble("value", resourceSnapshot.getMemoryGb()); - - Cursor disk = detailsDiskData.addObject(); - disk.setLong("unixms", resourceSnapshot.getTimestamp().toEpochMilli()); - disk.setDouble("value", resourceSnapshot.getDiskGb()); - }); - }); - - return new SlimeJsonResponse(slime); - } - private HttpResponse deploying(String tenantName, String applicationName, String instanceName, HttpRequest request) { Instance instance = controller.applications().requireInstance(ApplicationId.from(tenantName, applicationName, instanceName)); Slime slime = new Slime(); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/MeteringResponse.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/MeteringResponse.java index 850a9ef6107..33cd4948a7e 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/MeteringResponse.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/MeteringResponse.java @@ -32,6 +32,7 @@ public class MeteringResponse extends SlimeJsonResponse { object.setDouble("cpu", snapshot.getCpuCores()); object.setDouble("memory", snapshot.getMemoryGb()); object.setDouble("disk", snapshot.getDiskGb()); + object.setString("architecture", snapshot.getArchitecture().name()); }); return slime; } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainerTest.java index 80ee0988658..10193b48837 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainerTest.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.maintenance; +import com.yahoo.config.provision.NodeResources; import com.yahoo.vespa.hosted.controller.ControllerTester; import com.yahoo.vespa.hosted.controller.api.identifiers.Property; import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAllocation; @@ -38,7 +39,7 @@ public class CostReportMaintainerTest { "1970-01-01,Property3,128.0,96.0,2000.0,0.3333333333333333\n" + "1970-01-01,Property2,160.0,96.0,2000.0,0.3611111111111111", csv), - Map.of(new Property("Property3"), new ResourceAllocation(256, 192, 4000)) + Map.of(new Property("Property3"), new ResourceAllocation(256, 192, 4000, NodeResources.Architecture.getDefault())) ); 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 4acc9f91e79..6109890bae3 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 @@ -58,18 +58,18 @@ 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, Instant.EPOCH, z1), - new ResourceSnapshot(app1, 23, 45, 67, Instant.EPOCH, z2), - new ResourceSnapshot(app2, 34, 56, 78, Instant.EPOCH, z1)); + 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)); maintainer.updateDeploymentCost(resourceSnapshots); assertCost.accept(app1, Map.of(z1, 1.40, z2, 2.50)); assertCost.accept(app2, Map.of(z1, 3.59)); // Remove a region from app1 and add region to app2 resourceSnapshots = List.of( - new ResourceSnapshot(app1, 23, 45, 67, Instant.EPOCH, z2), - new ResourceSnapshot(app2, 34, 56, 78, Instant.EPOCH, z1), - new ResourceSnapshot(app2, 45, 67, 89, Instant.EPOCH, z2)); + 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)); maintainer.updateDeploymentCost(resourceSnapshots); assertCost.accept(app1, Map.of(z2, 2.50)); assertCost.accept(app2, Map.of(z1, 3.59, z2, 4.68)); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java index 8ab43f15c89..f56b466caa4 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java @@ -11,6 +11,7 @@ import com.yahoo.config.provision.ApplicationName; import com.yahoo.config.provision.AthenzService; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.InstanceName; +import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.RegionName; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.zone.RoutingMethod; @@ -1066,27 +1067,6 @@ public class ApplicationApiTest extends ControllerContainerTest { new File("deploy-result.json")); } - @Test - public void testMeteringResponses() { - MockMeteringClient mockMeteringClient = tester.serviceRegistry().meteringService(); - - // Mock response for MeteringClient - ResourceAllocation currentSnapshot = new ResourceAllocation(1, 2, 3); - ResourceAllocation thisMonth = new ResourceAllocation(12, 24, 1000); - ResourceAllocation lastMonth = new ResourceAllocation(24, 48, 2000); - ApplicationId applicationId = ApplicationId.from("doesnotexist", "doesnotexist", "default"); - Map<ApplicationId, List<ResourceSnapshot>> snapshotHistory = Map.of(applicationId, List.of( - new ResourceSnapshot(applicationId, 1, 2,3, Instant.ofEpochMilli(123), ZoneId.defaultId()), - new ResourceSnapshot(applicationId, 1, 2,3, Instant.ofEpochMilli(246), ZoneId.defaultId()), - new ResourceSnapshot(applicationId, 1, 2,3, Instant.ofEpochMilli(492), ZoneId.defaultId()))); - - mockMeteringClient.setMeteringData(new MeteringData(thisMonth, lastMonth, currentSnapshot, snapshotHistory)); - - tester.assertResponse(request("/application/v4/tenant/doesnotexist/application/doesnotexist/metering", GET) - .userIdentity(USER_ID) - .oAuthCredentials(OKTA_CREDENTIALS), - new File("instance1-metering.json")); - } @Test public void testRemovingAllDeployments() { 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 7bc01de2053..8a6244e19a0 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 @@ -3,6 +3,7 @@ package com.yahoo.vespa.hosted.controller.restapi.controller; import com.yahoo.application.container.handler.Request; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.test.ManualClock; @@ -158,8 +159,8 @@ public class ControllerApiTest extends ControllerContainerTest { Instant timestamp = Instant.ofEpochMilli(123456789); ZoneId zoneId = ZoneId.defaultId(); List<ResourceSnapshot> snapshots = List.of( - new ResourceSnapshot(applicationId, 12,48,1200, timestamp, zoneId), - new ResourceSnapshot(applicationId, 24, 96,2400, timestamp, zoneId) + new ResourceSnapshot(applicationId, 12,48,1200, NodeResources.Architecture.arm64, timestamp, zoneId), + new ResourceSnapshot(applicationId, 24, 96,2400, NodeResources.Architecture.x86_64, timestamp, zoneId) ); tester.controller().serviceRegistry().meteringService().consume(snapshots); tester.assertResponse( diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/responses/metering.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/responses/metering.json index b64e8f26a63..1008ada6def 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/responses/metering.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/responses/metering.json @@ -5,7 +5,8 @@ "zoneId": "prod.default", "cpu": 12.0, "memory": 48.0, - "disk": 1200.0 + "disk": 1200.0, + "architecture":"arm64" }, { "applicationId": "tenant.app.instance", @@ -13,6 +14,7 @@ "zoneId": "prod.default", "cpu": 24.0, "memory": 96.0, - "disk": 2400.0 + "disk": 2400.0, + "architecture":"x86_64" } ]
\ No newline at end of file |