summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authortoby <smorgrav@yahoo-inc.com>2017-10-13 13:58:21 +0200
committertoby <smorgrav@yahoo-inc.com>2017-10-13 13:58:21 +0200
commit75b888c31f0c751e3f6682bfd04efddeb7523913 (patch)
tree9c3bf4309e326db6eda33ce815722d0b4e51b6a9 /controller-server
parent82d187a6f7e3f6f6adbd4430951791c17af17558 (diff)
Add deployment metric maintainer
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java43
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainerTest.java41
2 files changed, 84 insertions, 0 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java
new file mode 100644
index 00000000000..d9ef451ffb7
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java
@@ -0,0 +1,43 @@
+package com.yahoo.vespa.hosted.controller.maintenance;// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+import com.yahoo.vespa.curator.Lock;
+import com.yahoo.vespa.hosted.controller.Application;
+import com.yahoo.vespa.hosted.controller.Controller;
+import com.yahoo.vespa.hosted.controller.api.integration.MetricsService;
+import com.yahoo.vespa.hosted.controller.application.Deployment;
+import com.yahoo.vespa.hosted.controller.application.DeploymentMetrics;
+
+import java.time.Duration;
+
+/**
+ * Retrieve deployment metrics like qps and document count from the metric service and
+ * update the applications with this info.
+ *
+ * @author smorgrav
+ */
+public class DeploymentMetricsMaintainer extends Maintainer {
+
+ DeploymentMetricsMaintainer(Controller controller, Duration duration, JobControl jobControl) {
+ super(controller, duration, jobControl);
+ }
+
+ @Override
+ protected void maintain() {
+
+ for (Application application : controller().applications().asList()) {
+ try (Lock lock = controller().applications().lock(application.id())) {
+ for (Deployment deployment : application.deployments().values()) {
+
+ MetricsService.DeploymentMetrics metrics = controller().metricsService()
+ .getDeploymentMetrics(application.id(), deployment.zone());
+
+ DeploymentMetrics appMetrics = new DeploymentMetrics(metrics.queriesPerSecond(), metrics.writesPerSecond(),
+ metrics.documentCount(), metrics.queryLatencyMillis(), metrics.writeLatencyMillis());
+
+ Application app = application.with(deployment.withMetrics(appMetrics));
+ controller().applications().store(app, lock);
+ }
+ }
+ }
+ }
+}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainerTest.java
new file mode 100644
index 00000000000..cb503fc1fb7
--- /dev/null
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainerTest.java
@@ -0,0 +1,41 @@
+package com.yahoo.vespa.hosted.controller.maintenance;
+
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.config.provision.Environment;
+import com.yahoo.vespa.hosted.controller.ControllerTester;
+import com.yahoo.vespa.hosted.controller.application.Deployment;
+import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.time.Duration;
+
+/**
+ * @author smorgrav
+ */
+public class DeploymentMetricsMaintainerTest {
+
+ @Test
+ public void maintain() {
+ ControllerTester tester = new ControllerTester();
+ ApplicationId app = tester.createAndDeploy("tenant1", "domain1", "app1", Environment.dev, 123).id();
+
+ // Pre condition: no metric info on the deployment
+ Deployment deployment = tester.controller().applications().get(app).get().deployments().values().stream().findAny().get();
+ Assert.assertEquals(0, deployment.metrics().documentCount(), Double.MIN_VALUE);
+
+ DeploymentMetricsMaintainer maintainer = new DeploymentMetricsMaintainer(tester.controller(), Duration.ofMinutes(10), new JobControl(new MockCuratorDb()));
+ maintainer.maintain();
+
+ // Post condition:
+ deployment = tester.controller().applications().get(app).get().deployments().values().stream().findAny().get();
+ Assert.assertEquals(1, deployment.metrics().queriesPerSecond(), Double.MIN_VALUE);
+ Assert.assertEquals(2, deployment.metrics().writesPerSecond(), Double.MIN_VALUE);
+ Assert.assertEquals(3, deployment.metrics().documentCount(), Double.MIN_VALUE);
+ Assert.assertEquals(4, deployment.metrics().queryLatencyMillis(), Double.MIN_VALUE);
+ Assert.assertEquals(5, deployment.metrics().writeLatencyMillis(), Double.MIN_VALUE);
+ }
+
+} \ No newline at end of file