diff options
Diffstat (limited to 'controller-api')
-rw-r--r-- | controller-api/pom.xml | 6 | ||||
-rw-r--r-- | controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/ConfigServerMetricsService.java | 68 | ||||
-rw-r--r-- | controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/MetricsService.java (renamed from controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java) | 2 | ||||
-rw-r--r-- | controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/ConfigServerMetricsServiceTest.java | 81 |
4 files changed, 156 insertions, 1 deletions
diff --git a/controller-api/pom.xml b/controller-api/pom.xml index 15098a04787..eeb6425bc25 100644 --- a/controller-api/pom.xml +++ b/controller-api/pom.xml @@ -70,6 +70,12 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + </dependencies> <build> diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/ConfigServerMetricsService.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/ConfigServerMetricsService.java new file mode 100644 index 00000000000..a47e2165291 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/ConfigServerMetricsService.java @@ -0,0 +1,68 @@ +package com.yahoo.vespa.hosted.controller.api.integration.metrics; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.HostName; +import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.hosted.controller.api.application.v4.model.ClusterMetrics; +import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId; +import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServer; +import com.yahoo.vespa.hosted.controller.api.integration.routing.RotationStatus; + +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +/** + * Retrieves metrics from the configuration server. + * + * @author ogronnesby + */ +public class ConfigServerMetricsService implements MetricsService { + private final ConfigServer configServerClient; + + public ConfigServerMetricsService(ConfigServer configServerClient) { + this.configServerClient = configServerClient; + } + + @Override + public ApplicationMetrics getApplicationMetrics(ApplicationId application) { + // TODO(ogronnesby): How to produce these values in Public context? + return new ApplicationMetrics(0.0, 0.0); + } + + @Override + public DeploymentMetrics getDeploymentMetrics(ApplicationId application, ZoneId zone) { + var deploymentId = new DeploymentId(application, zone); + var metrics = configServerClient.getMetrics(deploymentId); + + // TODO(ogronnesby): We probably want something more intelligent than just using .sum(), but it's better to + // TODO(ogronnesby): get some values populated and then fix the formula later. + + // The field names here come from the MetricsResponse class. + + return new DeploymentMetrics( + doubleStream(metrics, "queriesPerSecond").mapToDouble(Double::doubleValue).sum(), + doubleStream(metrics, "feedPerSecond").mapToDouble(Double::doubleValue).sum(), + doubleStream(metrics, "documentCount").mapToLong(Double::longValue).sum(), + doubleStream(metrics, "queryLatency").mapToDouble(Double::doubleValue).sum(), + doubleStream(metrics, "feedLatency").mapToDouble(Double::doubleValue).sum() + ); + } + + @Override + public Map<HostName, RotationStatus> getRotationStatus(String rotationName) { + // TODO(ogronnesby): getRotationStatus doesn't really belong in this interface, and global + // TODO(ogronnesby): endpoints does not work in public yet. + return Map.of(); + } + + @Override + public Map<String, SystemMetrics> getSystemMetrics(ApplicationId application, ZoneId zone) { + // TODO(ogronnesby): Need a backing source for this data + return Map.of(); + } + + private Stream<Double> doubleStream(List<ClusterMetrics> metrics, String name) { + return metrics.stream().map(m -> m.getMetrics().getOrDefault(name, 0.0)); + } +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/MetricsService.java index 32e94625c5a..a6d7c5d0688 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/MetricsService.java @@ -1,5 +1,5 @@ // 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.api.integration; +package com.yahoo.vespa.hosted.controller.api.integration.metrics; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostName; diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/ConfigServerMetricsServiceTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/ConfigServerMetricsServiceTest.java new file mode 100644 index 00000000000..9c14bc641c7 --- /dev/null +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/metrics/ConfigServerMetricsServiceTest.java @@ -0,0 +1,81 @@ +package com.yahoo.vespa.hosted.controller.api.integration.metrics; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.hosted.controller.api.application.v4.model.ClusterMetrics; +import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId; +import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServer; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ConfigServerMetricsServiceTest { + + private final ApplicationId applicationId = new ApplicationId.Builder() + .tenant("foo") + .applicationName("bar") + .instanceName("default") + .build(); + + private final ZoneId zoneId = ZoneId.from("prod", "us-west-1"); + + private ConfigServer configServer; + private ConfigServerMetricsService service; + + @Before + public void before() { + configServer = Mockito.mock(ConfigServer.class); + service = new ConfigServerMetricsService(configServer); + } + + @Test + public void test_returning_metrics() { + // + // Wire up the test + // + var deploymentId = new DeploymentId(applicationId, zoneId); + + var clusterMetrics1 = new ClusterMetrics("niceCluster", ClusterMetrics.ClusterType.container) {{ + addMetric("queriesPerSecond", 23.0); + addMetric("queryLatency", 1337.0); + }}; + + var clusterMetrics2 = new ClusterMetrics("alsoNiceCluster", ClusterMetrics.ClusterType.container) {{ + addMetric("queriesPerSecond", 11.0); + addMetric("queryLatency", 12.0); + }}; + + var response = List.of(clusterMetrics1, clusterMetrics2); + + Mockito.when(configServer.getMetrics(deploymentId)).thenReturn(response); + + // + // Now we can actually test stuff :( + // + var deploymentMetrics = service.getDeploymentMetrics(applicationId, zoneId); + + assertEquals(23.0 + 11.0, deploymentMetrics.queriesPerSecond(), 0.001); + assertEquals(1337.0 + 12.0, deploymentMetrics.queryLatencyMillis(), 0.001); // TODO: again, this definition of combined latency makes no sense + assertEquals(0, deploymentMetrics.documentCount()); + assertEquals(0.0, deploymentMetrics.writeLatencyMillis(), 0.001); + assertEquals(0.0, deploymentMetrics.writesPerSecond(), 0.001); + } + + @Test + public void test_not_implemented_application_metrics() { + var applicationMetrics = service.getApplicationMetrics(applicationId); + assertEquals(0.0, applicationMetrics.queryServiceQuality(), 0.001); + assertEquals(0.0, applicationMetrics.writeServiceQuality(), 0.001); + } + + @Test + public void test_not_implemented_metrics() { + assertTrue(service.getRotationStatus("foo").isEmpty()); + assertTrue(service.getSystemMetrics(applicationId, zoneId).isEmpty()); + } +} |