diff options
6 files changed, 71 insertions, 0 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java index 98b7ffd1d47..2f77fa6cfc4 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java @@ -19,6 +19,7 @@ public class Cluster { private final ClusterResources current; private final Optional<ClusterResources> target; private final Optional<ClusterResources> suggested; + private final Utilization utilization; private final List<ScalingEvent> scalingEvents; private final String autoscalingStatus; @@ -28,6 +29,7 @@ public class Cluster { ClusterResources current, Optional<ClusterResources> target, Optional<ClusterResources> suggested, + Utilization utilization, List<ScalingEvent> scalingEvents, String autoscalingStatus) { this.id = id; @@ -36,6 +38,7 @@ public class Cluster { this.current = current; this.target = target; this.suggested = suggested; + this.utilization = utilization; this.scalingEvents = scalingEvents; this.autoscalingStatus = autoscalingStatus; } @@ -46,6 +49,7 @@ public class Cluster { public ClusterResources current() { return current; } public Optional<ClusterResources> target() { return target; } public Optional<ClusterResources> suggested() { return suggested; } + public Utilization utilization() { return utilization; } public List<ScalingEvent> scalingEvents() { return scalingEvents; } public String autoscalingStatus() { return autoscalingStatus; } @@ -54,6 +58,24 @@ public class Cluster { return "cluster '" + id + "'"; } + public static class Utilization { + + private final double cpu, memory, disk; + + public Utilization(double cpu, double memory, double disk) { + this.cpu = cpu; + this.memory = memory; + this.disk = disk; + } + + public double cpu() { return cpu; } + public double memory() { return memory; } + public double disk() { return disk; } + + public static Utilization empty() { return new Utilization(0, 0, 0); } + + } + public static class ScalingEvent { private final ClusterResources from, to; diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterData.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterData.java index 99a72fbc827..688b2764c87 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterData.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterData.java @@ -28,6 +28,8 @@ public class ClusterData { public ClusterResourcesData suggested; @JsonProperty("target") public ClusterResourcesData target; + @JsonProperty("utilization") + public ClusterUtilizationData utilization; @JsonProperty("scalingEvents") public List<ScalingEventData> scalingEvents; @JsonProperty("autoscalingStatus") @@ -40,6 +42,7 @@ public class ClusterData { current.toClusterResources(), target == null ? Optional.empty() : Optional.of(target.toClusterResources()), suggested == null ? Optional.empty() : Optional.of(suggested.toClusterResources()), + utilization == null ? Cluster.Utilization.empty() : utilization.toClusterUtilization(), scalingEvents == null ? List.of() : scalingEvents.stream().map(data -> data.toScalingEvent()).collect(Collectors.toList()), autoscalingStatus); diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterUtilizationData.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterUtilizationData.java new file mode 100644 index 00000000000..a7de7664572 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterUtilizationData.java @@ -0,0 +1,33 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration.noderepository; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.yahoo.vespa.hosted.controller.api.integration.configserver.Cluster; + +import java.time.Instant; + +/** + * Utilization ratios + * + * @author bratseth + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ClusterUtilizationData { + + @JsonProperty("cpu") + public Double cpu; + + @JsonProperty("memory") + public Double memory; + + @JsonProperty("disk") + public Double disk; + + public Cluster.Utilization toClusterUtilization() { + return new Cluster.Utilization(cpu, memory, disk); + } + +} 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 f9dc62d7f34..38bcfda0ac7 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 @@ -740,6 +740,7 @@ public class ApplicationApiHandler extends LoggingRequestHandler { && ! cluster.target().get().justNumbers().equals(cluster.current().justNumbers())) toSlime(cluster.target().get(), clusterObject.setObject("target")); cluster.suggested().ifPresent(suggested -> toSlime(suggested, clusterObject.setObject("suggested"))); + utilizationToSlime(cluster.utilization(), clusterObject.setObject("utilization")); scalingEventsToSlime(cluster.scalingEvents(), clusterObject.setArray("scalingEvents")); clusterObject.setString("autoscalingStatus", cluster.autoscalingStatus()); } @@ -1984,6 +1985,12 @@ public class ApplicationApiHandler extends LoggingRequestHandler { object.setDouble("cost", Math.round(resources.nodes() * resources.nodeResources().cost() * 100.0 / 3.0) / 100.0); } + private void utilizationToSlime(Cluster.Utilization utilization, Cursor utilizationObject) { + utilizationObject.setDouble("cpu", utilization.cpu()); + utilizationObject.setDouble("memory", utilization.memory()); + utilizationObject.setDouble("disk", utilization.disk()); + } + private void scalingEventsToSlime(List<Cluster.ScalingEvent> scalingEvents, Cursor scalingEventsArray) { for (Cluster.ScalingEvent scalingEvent : scalingEvents) { Cursor scalingEventObject = scalingEventsArray.addObject(); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java index ee3c523a497..7ce1e6b8b83 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java @@ -115,6 +115,7 @@ public class ConfigServerMock extends AbstractComponent implements ConfigServer current, Optional.of(new ClusterResources(2, 1, new NodeResources(3, 8, 50, 1, slow, remote))), Optional.empty(), + new Cluster.Utilization(0.1, 0.2, 0.3), List.of(new Cluster.ScalingEvent(new ClusterResources(0, 0, NodeResources.unspecified()), current, Instant.ofEpochMilli(1234))), diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/application-clusters.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/application-clusters.json index 817cee7732a..2c208359f1b 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/application-clusters.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/application-clusters.json @@ -53,6 +53,11 @@ }, "cost": "(ignore)" }, + "utilization": { + "cpu": 0.1, + "memory": 0.2, + "disk": 0.3 + }, "scalingEvents": [ { "from": { |