aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@verizonmedia.com>2022-06-21 13:07:28 +0200
committerOla Aunrønning <olaa@verizonmedia.com>2022-06-21 13:07:28 +0200
commit44f0e23f55c368a40dc25e6b43865fa3a7e8eaa8 (patch)
tree5a0980155207e6d8d3837e58529de54a19b701e1 /controller-api
parentba227e9fd89e75514db94e244ff42352d86dd1ca (diff)
parent6e14406b30bd27b4a82f94d4ff61e5e4cfb52757 (diff)
Merge remote-tracking branch 'origin/master' into olaa/metering-monitoring-metrics
# Conflicts: # controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java # controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java
Diffstat (limited to 'controller-api')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/ClusterId.java49
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java3
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java23
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringClient.java24
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java10
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java24
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java53
7 files changed, 98 insertions, 88 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/ClusterId.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/ClusterId.java
new file mode 100644
index 00000000000..0565a916dfa
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/ClusterId.java
@@ -0,0 +1,49 @@
+package com.yahoo.vespa.hosted.controller.api.identifiers;
+
+import com.yahoo.config.provision.ClusterSpec;
+
+import java.util.Objects;
+
+/**
+ * DeploymentId x ClusterSpec.Id = ClusterId
+ *
+ * @author ogronnesby
+ */
+public class ClusterId {
+ private final DeploymentId deploymentId;
+ private final ClusterSpec.Id clusterId;
+
+ public ClusterId(DeploymentId deploymentId, ClusterSpec.Id clusterId) {
+ this.deploymentId = deploymentId;
+ this.clusterId = clusterId;
+ }
+
+ public DeploymentId deploymentId() {
+ return deploymentId;
+ }
+
+ public ClusterSpec.Id clusterId() {
+ return clusterId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ ClusterId clusterId1 = (ClusterId) o;
+ return Objects.equals(deploymentId, clusterId1.deploymentId) && Objects.equals(clusterId, clusterId1.clusterId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(deploymentId, clusterId);
+ }
+
+ @Override
+ public String toString() {
+ return "ClusterId{" +
+ "deploymentId=" + deploymentId +
+ ", clusterId=" + clusterId +
+ '}';
+ }
+}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java
index be83fd8de48..bf16913d05a 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java
@@ -28,7 +28,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.organization.Mailer;
import com.yahoo.vespa.hosted.controller.api.integration.organization.OwnershipIssues;
import com.yahoo.vespa.hosted.controller.api.integration.organization.SystemMonitor;
import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportConsumer;
-import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringClient;
import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceDatabaseClient;
import com.yahoo.vespa.hosted.controller.api.integration.secrets.GcpSecretStore;
import com.yahoo.vespa.hosted.controller.api.integration.secrets.TenantSecretService;
@@ -63,8 +62,6 @@ public interface ServiceRegistry {
EndpointCertificateValidator endpointCertificateValidator();
- MeteringClient meteringService();
-
ContactRetriever contactRetriever();
IssueHandler issueHandler();
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 6e60ec76199..b500cd1c133 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
@@ -7,6 +7,7 @@ import com.yahoo.config.provision.ClusterSpec;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
/**
@@ -131,6 +132,28 @@ public class Cluster {
public Instant at() { return at; }
public Optional<Instant> completion() { return completion; }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ ScalingEvent that = (ScalingEvent) o;
+ return Objects.equals(from, that.from) && Objects.equals(to, that.to) && Objects.equals(at, that.at) && Objects.equals(completion, that.completion);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(from, to, at, completion);
+ }
+
+ @Override
+ public String toString() {
+ return "ScalingEvent{" +
+ "from=" + from +
+ ", to=" + to +
+ ", at=" + at +
+ ", completion=" + completion +
+ '}';
+ }
}
}
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
deleted file mode 100644
index 944a5eaf696..00000000000
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringClient.java
+++ /dev/null
@@ -1,24 +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.ApplicationName;
-import com.yahoo.config.provision.TenantName;
-
-import java.time.YearMonth;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Consumes and retrieves snapshots of resources allocated per application.
- *
- * @author olaa
- */
-public interface MeteringClient {
-
- void consume(Collection<ResourceSnapshot> resources);
-
- 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/ResourceDatabaseClient.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java
index 51b5a3c2543..c2973313995 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
@@ -3,16 +3,18 @@ package com.yahoo.vespa.hosted.controller.api.integration.resource;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
-import com.yahoo.config.provision.zone.ZoneId;
+import com.yahoo.vespa.hosted.controller.api.identifiers.ClusterId;
+import com.yahoo.vespa.hosted.controller.api.integration.configserver.Cluster;
import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
+
import java.time.Instant;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.List;
-import java.util.Map;
+import java.util.Optional;
import java.util.Set;
/**
@@ -26,6 +28,10 @@ public interface ResourceDatabaseClient {
void refreshMaterializedView();
+ void writeScalingEvents(ClusterId clusterId, Collection<Cluster.ScalingEvent> scalingEvents);
+
+ List<Cluster.ScalingEvent> scalingEvents(Instant from, Instant to, Optional<ApplicationId> application);
+
Set<YearMonth> getMonthsWithSnapshotsForTenant(TenantName tenantName);
List<ResourceSnapshot> getRawSnapshotHistoryForTenant(TenantName tenantName, YearMonth yearMonth);
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 cf955e38218..cae3743f386 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
@@ -4,15 +4,15 @@ package com.yahoo.vespa.hosted.controller.api.integration.resource;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.ApplicationName;
import com.yahoo.config.provision.TenantName;
-import com.yahoo.config.provision.zone.ZoneId;
+import com.yahoo.vespa.hosted.controller.api.identifiers.ClusterId;
import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
import com.yahoo.vespa.hosted.controller.api.integration.billing.Plan;
import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanRegistry;
+import com.yahoo.vespa.hosted.controller.api.integration.configserver.Cluster;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.Instant;
-import java.time.LocalDate;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Collection;
@@ -35,7 +35,7 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient {
PlanRegistry planRegistry;
Map<TenantName, Plan> planMap = new HashMap<>();
List<ResourceSnapshot> resourceSnapshots = new ArrayList<>();
- Map<ApplicationId, Set<ZoneId>> lastSnapshots = new HashMap<>();
+ Map<ClusterId, List<Cluster.ScalingEvent>> scalingEvents = new HashMap<>();
private boolean hasRefreshedMaterializedView = false;
public ResourceDatabaseClientMock(PlanRegistry planRegistry) {
@@ -107,7 +107,7 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient {
public List<ResourceUsage> getResourceSnapshotsForPeriod(TenantName tenantName, long start, long end) {
var tenantPlan = planMap.getOrDefault(tenantName, planRegistry.defaultPlan());
- var snapshotsPerDeployment = resourceSnapshots.stream()
+ return resourceSnapshots.stream()
.filter(snapshot -> snapshot.getTimestamp().isAfter(Instant.ofEpochMilli(start)))
.filter(snapshot -> snapshot.getTimestamp().isBefore(Instant.ofEpochMilli(end)))
.filter(snapshot -> snapshot.getApplicationId().tenant().equals(tenantName))
@@ -120,8 +120,6 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient {
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
-
- return snapshotsPerDeployment;
}
@Override
@@ -134,6 +132,16 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient {
return Instant.ofEpochMilli(987654L);
}
+ @Override
+ public void writeScalingEvents(ClusterId clusterId, Collection<Cluster.ScalingEvent> scalingEvents) {
+ this.scalingEvents.put(clusterId, List.copyOf(scalingEvents));
+ }
+
+ @Override
+ public List<Cluster.ScalingEvent> scalingEvents(Instant from, Instant to, Optional<ApplicationId> application) {
+ return List.of();
+ }
+
public void setPlan(TenantName tenant, Plan plan) {
planMap.put(tenant, plan);
}
@@ -142,4 +150,8 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient {
return hasRefreshedMaterializedView;
}
+ public List<ResourceSnapshot> resourceSnapshots() {
+ return resourceSnapshots;
+ }
+
}
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
deleted file mode 100644
index ca094f98607..00000000000
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java
+++ /dev/null
@@ -1,53 +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.stubs;
-
-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.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.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * @author olaa
- */
-public class MockMeteringClient implements MeteringClient {
-
- private Collection<ResourceSnapshot> resources = new ArrayList<>();
- private Optional<MeteringData> meteringData;
- private boolean isRefreshed = false;
-
- @Override
- public void consume(Collection<ResourceSnapshot> resources){
- this.resources = resources;
- }
-
- @Override
- public List<ResourceSnapshot> getSnapshotHistoryForTenant(TenantName tenantName, YearMonth yearMonth) {
- return new ArrayList<>(resources);
- }
-
- @Override
- public void refresh() {
- isRefreshed = true;
- }
-
- public Collection<ResourceSnapshot> consumedResources() {
- return this.resources;
- }
-
- public void setMeteringData(MeteringData meteringData) {
- this.meteringData = Optional.of(meteringData);
- this.resources = meteringData.getSnapshotHistory().entrySet().stream().map(Map.Entry::getValue).flatMap(List::stream).collect(Collectors.toList());
- }
-
- public boolean isRefreshed() {
- return isRefreshed;
- }
-}