ConfigServerMetrics { public DeploymentMetrics getDeploymentMetrics(ApplicationId application, ZoneId zone) { var deploymentId = new DeploymentId(application, zone); var metrics = configServer.getDeploymentMetrics(deploymentId); return new DeploymentMetrics( metrics.stream().flatMap(m -> m.queriesPerSecond().stream()).mapToDouble(Double::doubleValue).sum(), metrics.stream().flatMap(m -> m.feedPerSecond().stream()).mapToDouble(Double::doubleValue).sum(), metrics.stream().flatMap(m -> m.documentCount().stream()).mapToLong(Double::longValue).sum(), weightedAverageLatency(metrics, ClusterMetrics::queriesPerSecond, ClusterMetrics::queryLatency), weightedAverageLatency(metrics, ClusterMetrics::feedPerSecond, ClusterMetrics::feedLatency) ); } ConfigServerMetrics(ConfigServer configServer); ApplicationMetrics getApplicationMetrics(ApplicationId application); DeploymentMetrics getDeploymentMetrics(ApplicationId application, ZoneId zone);  }
@Test public void test_returning_metrics() { var deploymentId = new DeploymentId(applicationId, zoneId); var clusterMetrics1 = new ClusterMetrics("niceCluster", "container") {{ addMetric("queriesPerSecond", 23.0); addMetric("queryLatency", 1337.0); }}; var clusterMetrics2 = new ClusterMetrics("alsoNiceCluster", "container") {{ addMetric("queriesPerSecond", 11.0); addMetric("queryLatency", 12.0); }}; var response = List.of(clusterMetrics1, clusterMetrics2); configServer.setMetrics(deploymentId, response); var deploymentMetrics = service.getDeploymentMetrics(applicationId, zoneId); assertEquals(23.0 + 11.0, deploymentMetrics.queriesPerSecond(), 0.001); assertEquals(908.323, deploymentMetrics.queryLatencyMillis(), 0.001); assertEquals(0, deploymentMetrics.documentCount()); assertEquals(0.0, deploymentMetrics.writeLatencyMillis(), 0.001); assertEquals(0.0, deploymentMetrics.writesPerSecond(), 0.001); }