aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorolaaun <olaa@oath.com>2019-03-08 13:47:42 +0100
committerGitHub <noreply@github.com>2019-03-08 13:47:42 +0100
commitb24341afc0cba1dc9e1a1d5249e1268961c8da19 (patch)
treec910f1a5508137bbb3f995524f660a94f3b7c060 /controller-server
parent345e39dd2ea662fde71454f282c5c4546e6d3fcc (diff)
parentc31822dc8943f995c61d9d3728bfc9dbfdfdf818 (diff)
Merge pull request #8707 from vespa-engine/olaa/remove-handlers
Remove handlers.
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/contactinfo/ContactInfoHandler.java144
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/metrics/MetricForwardingApiHandler.java156
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java6
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/contactinfo/ContactInfoHandlerTest.java40
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/metrics/MetricForwardingApiHandlerTest.java157
5 files changed, 0 insertions, 503 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/contactinfo/ContactInfoHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/contactinfo/ContactInfoHandler.java
deleted file mode 100644
index cf9db8fd992..00000000000
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/contactinfo/ContactInfoHandler.java
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.controller.restapi.contactinfo;
-
-import com.yahoo.config.provision.TenantName;
-import com.yahoo.container.jdisc.HttpRequest;
-import com.yahoo.container.jdisc.HttpResponse;
-import com.yahoo.container.jdisc.LoggingRequestHandler;
-import com.yahoo.io.IOUtils;
-import com.yahoo.restapi.Path;
-import com.yahoo.slime.ArrayTraverser;
-import com.yahoo.slime.Cursor;
-import com.yahoo.slime.Inspector;
-import com.yahoo.slime.Slime;
-import com.yahoo.vespa.config.SlimeUtils;
-import com.yahoo.vespa.hosted.controller.Controller;
-import com.yahoo.vespa.hosted.controller.restapi.ErrorResponse;
-import com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse;
-import com.yahoo.vespa.hosted.controller.restapi.StringResponse;
-import com.yahoo.vespa.hosted.controller.tenant.AthenzTenant;
-import com.yahoo.vespa.hosted.controller.api.integration.organization.Contact;
-import com.yahoo.yolean.Exceptions;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.logging.Level;
-
-/**
- * This implements the contactinfo/v1 API which allows getting and feeding
- * contact information for a given tenant.
- *
- * @author olaa
- */
-public class ContactInfoHandler extends LoggingRequestHandler {
-
- private final Controller controller;
-
- public ContactInfoHandler(Context ctx, Controller controller) {
- super(ctx);
- this.controller = controller;
- }
-
- @Override
- public HttpResponse handle(HttpRequest request) {
- try {
- switch (request.getMethod()) {
- case GET:
- return get(request);
- case POST:
- return post(request);
- default:
- return ErrorResponse.methodNotAllowed("Method '" + request.getMethod() + "' is unsupported");
- }
- }
- catch (IllegalArgumentException e) {
- return ErrorResponse.badRequest(Exceptions.toMessageString(e));
- }
- catch (RuntimeException e) {
- log.log(Level.WARNING, "Unexpected error handling '" + request.getUri() + "'", e);
- return ErrorResponse.internalServerError(Exceptions.toMessageString(e));
- }
- }
-
- private HttpResponse get(HttpRequest request) {
- Path path = new Path(request.getUri().getPath());
- if (path.matches("/contactinfo/v1/tenant/{tenant}")) return getContactInfo(path.get("tenant"));
- return ErrorResponse.notFoundError("Nothing at " + path);
- }
-
- private HttpResponse post(HttpRequest request) {
- Path path = new Path(request.getUri().getPath());
- if (path.matches("/contactinfo/v1/tenant/{tenant}")) return postContactInfo(path.get("tenant"), request);
- return ErrorResponse.notFoundError("Nothing at " + path);
- }
-
- private HttpResponse getContactInfo(String tenantName) {
- Optional<AthenzTenant> tenant = controller.tenants().athenzTenant(TenantName.from(tenantName));
- if (!tenant.isPresent()) {
- return ErrorResponse.notFoundError("Invalid tenant " + tenantName);
- }
- Optional<Contact> contact = tenant.get().contact();
- if (contact.isPresent()) {
- return new SlimeJsonResponse(contactToSlime(contact.get()));
- }
- return ErrorResponse.notFoundError("Could not find contact info for " + tenantName);
- }
-
- private HttpResponse postContactInfo(String tenantName, HttpRequest request) {
- try {
- Contact contact = getContactFromRequest(request);
- controller.tenants().lockIfPresent(TenantName.from(tenantName),
- lockedTenant -> controller.tenants().store(lockedTenant.with(contact)));
- return new StringResponse("Added contact info for " + tenantName + " - " + contact.toString());
- }
- catch (IOException e) {
- return ErrorResponse.notFoundError("Unable to create Contact object from request data");
- }
- }
-
- private Contact getContactFromRequest(HttpRequest request) throws IOException {
- Slime slime = SlimeUtils.jsonToSlime(IOUtils.readBytes(request.getData(), 1000 * 1000));
- return contactFromSlime(slime);
- }
-
- protected static Slime contactToSlime(Contact contact) {
- Slime slime = new Slime();
- Cursor cursor = slime.setObject();
- cursor.setString("url", contact.url().toString());
- cursor.setString("issueTrackerUrl", contact.issueTrackerUrl().toString());
- cursor.setString("propertyUrl", contact.propertyUrl().toString());
- Cursor personsCursor = cursor.setArray("persons");
- for (List<String> personList : contact.persons()) {
- Cursor sublist = personsCursor.addArray();
- for(String person : personList) {
- sublist.addString(person);
- }
- }
- cursor.setString("queue", contact.queue());
- contact.component().ifPresent(component -> cursor.setString("component", component));
- return slime;
- }
-
- protected static Contact contactFromSlime(Slime slime) {
- Inspector inspector = slime.get();
- URI propertyUrl = URI.create(inspector.field("propertyUrl").asString());
- URI url = URI.create(inspector.field("url").asString());
- URI issueTrackerUrl = URI.create(inspector.field("issueTrackerUrl").asString());
- String queue = inspector.field("queue").asString();
- Optional<String> component = inspector.field("component").valid() ? Optional.of(inspector.field("component").asString()) : Optional.empty();
- Inspector personInspector = inspector.field("persons");
- List<List<String>> personList = new ArrayList<>();
- personInspector.traverse((ArrayTraverser) (index, entry) -> {
- List<String> subList = new ArrayList<>();
- entry.traverse((ArrayTraverser) (idx, subEntry) -> {
- subList.add(subEntry.asString());
- });
- personList.add(subList);
- });
- return new Contact(url, propertyUrl, issueTrackerUrl, personList, queue, component);
- }
-
-}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/metrics/MetricForwardingApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/metrics/MetricForwardingApiHandler.java
deleted file mode 100644
index f3112b09173..00000000000
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/metrics/MetricForwardingApiHandler.java
+++ /dev/null
@@ -1,156 +0,0 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.controller.restapi.metrics;
-
-import com.yahoo.config.provision.ApplicationId;
-import com.yahoo.config.provision.ClusterSpec;
-import com.yahoo.container.jdisc.HttpRequest;
-import com.yahoo.container.jdisc.HttpResponse;
-import com.yahoo.container.jdisc.LoggingRequestHandler;
-import com.yahoo.io.IOUtils;
-import com.yahoo.restapi.Path;
-import com.yahoo.slime.ArrayTraverser;
-import com.yahoo.slime.Inspector;
-import com.yahoo.slime.Slime;
-import com.yahoo.vespa.config.SlimeUtils;
-import com.yahoo.vespa.hosted.controller.ApplicationController;
-import com.yahoo.vespa.hosted.controller.Controller;
-import com.yahoo.config.provision.HostName;
-import com.yahoo.vespa.hosted.controller.api.integration.MetricsService;
-import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId;
-import com.yahoo.vespa.hosted.controller.application.ClusterUtilization;
-import com.yahoo.vespa.hosted.controller.application.DeploymentMetrics;
-import com.yahoo.vespa.hosted.controller.application.RotationStatus;
-import com.yahoo.vespa.hosted.controller.restapi.ErrorResponse;
-import com.yahoo.vespa.hosted.controller.restapi.StringResponse;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-
-/**
- * This implements the metricforwarding/v1 API which allows feeding
- * MetricsService data.
- * @author olaa
- */
-public class MetricForwardingApiHandler extends LoggingRequestHandler {
-
- private final Controller controller;
-
- public MetricForwardingApiHandler(Context ctx, Controller controller) {
- super(ctx);
- this.controller = controller;
- }
-
- @Override
- public HttpResponse handle(HttpRequest request) {
- switch (request.getMethod()) {
- case POST:
- return post(request);
- default:
- return ErrorResponse.methodNotAllowed("Method '" + request.getMethod() + "' is unsupported");
- }
- }
-
- private HttpResponse post(HttpRequest request) {
- Path path = new Path(request.getUri().getPath());
- if (path.matches("/metricforwarding/v1/clusterutilization")) return updateClusterUtilization(request);
- if (path.matches("/metricforwarding/v1/deploymentmetrics")) return updateDeploymentMetrics(request);
- return ErrorResponse.notFoundError("Nothing at " + path);
- }
-
- private HttpResponse updateClusterUtilization(HttpRequest request) {
- try {
- Slime slime = SlimeUtils.jsonToSlime(IOUtils.readBytes(request.getData(), 1000 * 1000));
- Inspector inspector = slime.get();
- inspector.traverse((ArrayTraverser) (index, entry) -> {
- ApplicationId applicationId = ApplicationId.fromSerializedForm(entry.field("applicationId").asString());
- entry.field("deployments").traverse((ArrayTraverser) (i, deployment) -> {
- ZoneId zoneId = ZoneId.from(deployment.field("zoneId").asString());
- Map<ClusterSpec.Id, ClusterUtilization> clusterUtilization = getClusterUtilizationsFromInspector(deployment.field("clusterUtil"));
- controller.applications().lockIfPresent(applicationId, lockedApplication ->
- controller.applications().store(lockedApplication.withClusterUtilization(zoneId, clusterUtilization)));
- });
- });
- } catch (IOException e) {
- log.log(Level.WARNING, "Unable to parse request for cluster utilization metrics", e);
- return ErrorResponse.badRequest("Unable to parse request for cluster utilization metrics - " + e.getMessage());
- }
- return new StringResponse("Added cluster utilization metrics");
- }
-
- private HttpResponse updateDeploymentMetrics(HttpRequest request) {
- try {
- Slime slime = SlimeUtils.jsonToSlime(IOUtils.readBytes(request.getData(), 1000 * 1000));
- Inspector inspector = slime.get();
- inspector.traverse((ArrayTraverser) (index, applicationEntry) -> {
- ApplicationId applicationId = ApplicationId.fromSerializedForm(applicationEntry.field("applicationId").asString());
- MetricsService.ApplicationMetrics applicationMetrics = getApplicationMetricsFromInspector(applicationEntry);
- ApplicationController applications = controller.applications();
- applications.lockIfPresent(applicationId, lockedApplication ->
- applications.store(lockedApplication.with(applicationMetrics)));
-
- Map<HostName, RotationStatus> rotationStatusMap = getRotationStatusFromInspector(applicationEntry);
- applications.lockIfPresent(applicationId, lockedApplication ->
- applications.store(lockedApplication.withRotationStatus(rotationStatusMap)));
-
- for (Map.Entry<ZoneId, DeploymentMetrics> entry : getDeploymentMetricsFromInspector(applicationEntry).entrySet()) {
- applications.lockIfPresent(applicationId, lockedApplication ->
- applications.store(lockedApplication.with(entry.getKey(), entry.getValue())
- .recordActivityAt(controller.clock().instant(), entry.getKey())));
- }
- });
- } catch (IOException e) {
- log.log(Level.WARNING, "Unable to parse request for deployment metrics", e);
- return ErrorResponse.badRequest("Unable to parse request for deployment metrics - " + e.getMessage());
- }
- return new StringResponse("Added deployment metrics");
- }
-
- private Map<ClusterSpec.Id, ClusterUtilization> getClusterUtilizationsFromInspector(Inspector inspector) {
- Map<ClusterSpec.Id, ClusterUtilization> clusterUtilizationMap = new HashMap<>();
- inspector.traverse((ArrayTraverser) (index, entry) -> {
- ClusterSpec.Id id = ClusterSpec.Id.from(entry.field("clusterSpecId").asString());
- double memory = entry.field("memory").asDouble();
- double cpu = entry.field("cpu").asDouble();
- double disk = entry.field("disk").asDouble();
- double diskBusy = entry.field("diskBusy").asDouble();
- clusterUtilizationMap.put(id, new ClusterUtilization(memory, cpu, disk, diskBusy));
- });
- return clusterUtilizationMap;
- }
-
- private Map<ZoneId, DeploymentMetrics> getDeploymentMetricsFromInspector(Inspector inspector){
- Map<ZoneId, DeploymentMetrics> deploymentMetricsMap = new HashMap<>();
- inspector = inspector.field("deploymentMetrics");
- inspector.traverse((ArrayTraverser) (index, entry) -> {
- ZoneId zoneId = ZoneId.from(entry.field("zoneId").asString());
- double queriesPerSecond = entry.field("queriesPerSecond").asDouble();
- double writesPerSecond = entry.field("writesPerSecond").asDouble();
- double documentCount = entry.field("documentCount").asDouble();
- double queryLatencyMillis = entry.field("queryLatencyMillis").asDouble();
- double writeLatencyMillis = entry.field("writeLatencyMillis").asDouble();
- DeploymentMetrics metrics = new DeploymentMetrics(queriesPerSecond, writesPerSecond, documentCount, queryLatencyMillis, writeLatencyMillis);
- deploymentMetricsMap.put(zoneId, metrics);
- });
- return deploymentMetricsMap;
- }
-
- private MetricsService.ApplicationMetrics getApplicationMetricsFromInspector(Inspector inspector){
- inspector = inspector.field("applicationMetrics");
- double queryServiceQuality = inspector.field("queryServiceQuality").asDouble();
- double writeServiceQuality = inspector.field("writeServiceQuality").asDouble();
- return new MetricsService.ApplicationMetrics(queryServiceQuality, writeServiceQuality);
- }
-
- private Map<HostName, RotationStatus> getRotationStatusFromInspector(Inspector inspector) {
- Map<HostName, RotationStatus> rotationStatusMap = new HashMap<>();
- inspector = inspector.field("rotationStatus");
- inspector.traverse((ArrayTraverser) (index, entry) -> {
- HostName hostName = HostName.from(entry.field("hostname").asString());
- RotationStatus rotationStatus = RotationStatus.valueOf(entry.field("rotationStatus").asString());
- rotationStatusMap.put(hostName, rotationStatus);
- });
- return rotationStatusMap;
- }
-}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java
index f0a26bb2dd4..f051818a12f 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java
@@ -96,12 +96,6 @@ public class ControllerContainerTest {
" <handler id='com.yahoo.vespa.hosted.controller.restapi.application.ApplicationApiHandler'>\n" +
" <binding>http://*/application/v4/*</binding>\n" +
" </handler>\n" +
- " <handler id='com.yahoo.vespa.hosted.controller.restapi.contactinfo.ContactInfoHandler'>\n" +
- " <binding>http://*/contactinfo/v1/*</binding>\n" +
- " </handler>\n" +
- " <handler id='com.yahoo.vespa.hosted.controller.restapi.metrics.MetricForwardingApiHandler'>\n" +
- " <binding>http://*/metricforwarding/v1/*</binding>\n" +
- " </handler>\n" +
" <handler id='com.yahoo.vespa.hosted.controller.restapi.deployment.DeploymentApiHandler'>\n" +
" <binding>http://*/deployment/v1/*</binding>\n" +
" </handler>\n" +
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/contactinfo/ContactInfoHandlerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/contactinfo/ContactInfoHandlerTest.java
deleted file mode 100644
index 24506fda31a..00000000000
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/contactinfo/ContactInfoHandlerTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.yahoo.vespa.hosted.controller.restapi.contactinfo;
-
-import com.yahoo.application.container.handler.Request;
-import com.yahoo.application.container.handler.Response;
-import com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester;
-import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class ContactInfoHandlerTest extends ControllerContainerTest {
-
- private ContainerControllerTester tester;
-
- @Before
- public void before() {
- tester = new ContainerControllerTester(container, null);
- }
-
- @Test
- public void testGettingAndFeedingContactInfo() {
- tester.createApplication();
-
- // No contact information available yet
- String notFoundMessage = "{\"error-code\":\"NOT_FOUND\",\"message\":\"Could not find contact info for tenant1\"}";
- assertResponse(new Request("http://localhost:8080/contactinfo/v1/tenant/tenant1"), 404, notFoundMessage);
-
- // Feed contact information for tenant1
- String contactInfo = "{\"url\":\"https://url:4444/\",\"issueTrackerUrl\":\"https://issueTrackerUrl:4444/\",\"propertyUrl\":\"https://propertyUrl:4444/\",\"persons\":[[\"foo\",\"bar\"]],\"queue\":\"queue\",\"component\":\"component\"}";
- String expectedResponseMessage = "Added contact info for tenant1 - Contact{url=https://url:4444/, propertyUrl=https://propertyUrl:4444/, issueTrackerUrl=https://issueTrackerUrl:4444/, persons=[[foo, bar]], queue=queue, component=component}";
- assertResponse(new Request("http://localhost:8080/contactinfo/v1/tenant/tenant1", contactInfo, Request.Method.POST), 200, expectedResponseMessage);
-
- // Get contact information for tenant1
- Response response = container.handleRequest(new Request("http://localhost:8080/contactinfo/v1/tenant/tenant1"));
- String actualContactInfo = new String(response.getBody());
- assertEquals(contactInfo, actualContactInfo);
- }
-
-} \ No newline at end of file
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/metrics/MetricForwardingApiHandlerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/metrics/MetricForwardingApiHandlerTest.java
deleted file mode 100644
index 551644377fb..00000000000
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/metrics/MetricForwardingApiHandlerTest.java
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.controller.restapi.metrics;
-
-import com.yahoo.application.container.handler.Request;
-import com.yahoo.config.provision.ClusterSpec;
-import com.yahoo.config.provision.Environment;
-import com.yahoo.config.provision.HostName;
-import com.yahoo.config.provision.RegionName;
-import com.yahoo.vespa.hosted.controller.Application;
-import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType;
-import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId;
-import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
-import com.yahoo.vespa.hosted.controller.application.ClusterUtilization;
-import com.yahoo.vespa.hosted.controller.application.Deployment;
-import com.yahoo.vespa.hosted.controller.application.RotationStatus;
-import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder;
-import com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester;
-import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest;
-import org.junit.Before;
-import org.junit.Test;
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-/**
- * @author olaa
- */
-public class MetricForwardingApiHandlerTest extends ControllerContainerTest {
-
- private static final double DELTA = 0.00001;
- private ContainerControllerTester tester;
-
- @Before
- public void before() {
- tester = new ContainerControllerTester(container, null);
- }
-
- @Test
- public void testUpdatingDeploymentMetrics() {
- ZoneId zoneId = ZoneId.from(Environment.test, RegionName.from("us-east-1"));
- deployApplication(zoneId);
- Application application = getUpdatedApplication();
- Deployment deployment = application.deployments().get(zoneId);
-
- // Verify deployment and system metrics are initially 0
- assertEquals(0, application.metrics().queryServiceQuality(), DELTA);
- assertEquals(0, application.metrics().writeServiceQuality(), DELTA);
- assertEquals(0, deployment.metrics().documentCount(), DELTA);
- assertEquals(0, deployment.metrics().queriesPerSecond(), DELTA);
- assertEquals(0, deployment.metrics().queryLatencyMillis(), DELTA);
- assertEquals(0, deployment.metrics().writeLatencyMillis(), DELTA);
- assertEquals(0, deployment.metrics().writesPerSecond(), DELTA);
- assertFalse(application.rotationStatus().containsKey(HostName.from("host1")));
- assertFalse(application.rotationStatus().containsKey(HostName.from("host2")));
-
- String deploymentMetrics = "[{\"applicationId\":\"tenant1:application1:default\"," +
- "\"applicationMetrics\":{" +
- " \"queryServiceQuality\":0.5," +
- " \"writeServiceQuality\":0.7}," +
- "\"rotationStatus\":[" +
- " {" +
- " \"hostname\":\"proxy.prod.us-east-3.vip.test\"," +
- " \"rotationStatus\":\"out\"" +
- " }," +
- " {" +
- " \"hostname\":\"proxy.prod.us-east-1.vip.test\"," +
- " \"rotationStatus\":\"in\"" +
- " }]," +
- "\"deploymentMetrics\":[" +
- " {" +
- " \"zoneId\":\"test.us-east-1\"," +
- " \"queriesPerSecond\":1.0," +
- " \"writesPerSecond\":2.0," +
- " \"documentCount\":3.0," +
- " \"queryLatencyMillis\":4.0," +
- " \"writeLatencyMillis\":5.0" +
- " }" +
- "]}]";
- String expectedResponseMessage = "Added deployment metrics";
- assertResponse(new Request("http://localhost:8080/metricforwarding/v1/deploymentmetrics", deploymentMetrics, Request.Method.POST), 200, expectedResponseMessage);
-
- // Verify that deployment metrics are updated
- application = getUpdatedApplication();
- assertEquals(0.5, application.metrics().queryServiceQuality(), DELTA);
- assertEquals(0.7, application.metrics().writeServiceQuality(), DELTA);
-
- deployment = application.deployments().get(zoneId);
- assertEquals(3.0, deployment.metrics().documentCount(), DELTA);
- assertEquals(1.0, deployment.metrics().queriesPerSecond(), DELTA);
- assertEquals(4.0, deployment.metrics().queryLatencyMillis(), DELTA);
- assertEquals(5.0, deployment.metrics().writeLatencyMillis(), DELTA);
- assertEquals(2, deployment.metrics().writesPerSecond(), DELTA);
- assertEquals(RotationStatus.in, application.rotationStatus().get(HostName.from("proxy.prod.us-east-1.vip.test")));
- assertEquals(RotationStatus.out, application.rotationStatus().get(HostName.from("proxy.prod.us-east-3.vip.test")));
-
- }
-
- @Test
- public void testUpdatingSystemMetrics() {
- ZoneId zoneId = ZoneId.from(Environment.test, RegionName.from("us-east-1"));
- deployApplication(zoneId);
- Application application = getUpdatedApplication();
- Deployment deployment = application.deployments().get(zoneId);
- assertFalse(deployment.clusterUtils().containsKey(ClusterSpec.Id.from("cluster1")));
- assertFalse(deployment.clusterUtils().containsKey(ClusterSpec.Id.from("cluster2")));
- String systemMetrics = "[{\"applicationId\":\"tenant1:application1:default\"," +
- "\"deployments\":[{\"zoneId\":\"test.us-east-1\",\"clusterUtil\":[" +
- "{" +
- " \"clusterSpecId\":\"default\"," +
- " \"cpu\":0.5554," +
- " \"memory\":0.6990000000000001," +
- " \"disk\":0.34590000000000004," +
- " \"diskBusy\":0.0" +
- "}," +
- "{" +
- " \"clusterSpecId\":\"cluster2\"," +
- " \"cpu\":0.6," +
- " \"memory\":0.8," +
- " \"disk\":0.5," +
- " \"diskBusy\":0.1" +
- "}" +
- "]}]}]";
- String expectedResponseMessage = "Added cluster utilization metrics";
- assertResponse(new Request("http://localhost:8080/metricforwarding/v1/clusterutilization", systemMetrics, Request.Method.POST), 200, expectedResponseMessage);
- deployment = getUpdatedApplication().deployments().get(zoneId);
-
- ClusterUtilization clusterUtilization = deployment.clusterUtils().get(ClusterSpec.Id.from("default"));
- assertEquals(0.5554, clusterUtilization.getCpu(), DELTA);
- assertEquals(0.699, clusterUtilization.getMemory(), DELTA);
- assertEquals(0.3459, clusterUtilization.getDisk(), DELTA);
- assertEquals(0.0, clusterUtilization.getDiskBusy(), DELTA);
- clusterUtilization = deployment.clusterUtils().get(ClusterSpec.Id.from("cluster2"));
- assertEquals(0.6, clusterUtilization.getCpu(), DELTA);
- assertEquals(0.8, clusterUtilization.getMemory(), DELTA);
- assertEquals(0.5, clusterUtilization.getDisk(), DELTA);
- assertEquals(0.1, clusterUtilization.getDiskBusy(), DELTA);
- }
-
- private Application getUpdatedApplication() {
- return tester.controller().applications().asList().get(0);
- }
-
- private void deployApplication(ZoneId zoneId) {
- ApplicationPackage applicationPackage = new ApplicationPackageBuilder()
- .environment(zoneId.environment())
- .region(zoneId.region().value())
- .build();
- Application application = tester.createApplication();
- tester.jobCompletion(JobType.component)
- .application(application)
- .projectId(123L)
- .uploadArtifact(applicationPackage)
- .submit();
- tester.deploy(application, applicationPackage, zoneId);
- }
-} \ No newline at end of file