summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@oath.com>2019-05-10 17:42:54 +0200
committerOla Aunrønning <olaa@oath.com>2019-05-10 17:42:54 +0200
commit04fe6e57621b51e30ad8ca38c4071c44982afd0f (patch)
treee3bdc0e4dbf69ded08d60f381dc12e6302c041d3
parentbe4a878ffb4005c7796fc52fa8b87157e897b4d1 (diff)
Payload change
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java3
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/MetricsResponse.java (renamed from configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/MetricsRespone.java)5
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/metrics/Metrics.java36
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/metrics/MetricsAggregator.java46
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/metrics/MetricsAggregatorTest.java62
-rw-r--r--configserver/src/test/resources/metrics_response46
6 files changed, 119 insertions, 79 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
index b2c2b85d358..ca13008264f 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
@@ -762,11 +762,12 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
Application application = getApplication(applicationId);
Map<String, List<URI>> clusterHosts = new HashMap<>();
application.getModel().getHosts().stream()
+ .filter(host -> host.getServices().stream().anyMatch(serviceInfo -> serviceInfo.getProperty("clustertype").isPresent()))
.forEach(hostInfo -> {
ServiceInfo serviceInfo = hostInfo.getServices().stream().filter(service -> METRICS_PROXY_CONTAINER.serviceName.equals(service.getServiceType()))
.findFirst().orElseThrow(() -> new IllegalArgumentException("Unable to find services " + METRICS_PROXY_CONTAINER.serviceName.toString()));
String clusterName = serviceInfo.getProperty("clusterinfo").orElse("");
- URI host = URI.create("http://" + hostInfo.getHostname() + ":" + servicePort(serviceInfo) + "/metrics");
+ URI host = URI.create("http://" + hostInfo.getHostname() + ":" + servicePort(serviceInfo) + "/metrics/v1/values");
clusterHosts.computeIfAbsent(clusterName, l -> new ArrayList<URI>()).add(host);
}
);
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/MetricsRespone.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/MetricsResponse.java
index 4d6a2f20cd1..8c8b69d8945 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/MetricsRespone.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/MetricsResponse.java
@@ -16,11 +16,11 @@ import java.util.Map;
/**
* @author olaa
*/
-public class MetricsRespone extends HttpResponse {
+public class MetricsResponse extends HttpResponse {
private final Slime slime = new Slime();
- public MetricsRespone(int status, Map<ApplicationId, Map<String, Metrics>> aggregatedMetrics) {
+ public MetricsResponse(int status, Map<ApplicationId, Map<String, Metrics>> aggregatedMetrics) {
super(status);
Cursor array = slime.setArray();
@@ -37,6 +37,7 @@ public class MetricsRespone extends HttpResponse {
clusterCursor.setDouble("documentCount", metrics.getDocumentCount());
clusterCursor.setDouble("queryLatencyMillis", metrics.getQueryLatencyMillis());
clusterCursor.setDouble("writeLatencyMillis", metrics.getWriteLatencyMills());
+ clusterCursor.setLong("timestamp", metrics.getTimestamp().getEpochSecond());
}
}
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/Metrics.java b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/Metrics.java
index 7216523719a..8532888dc3d 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/Metrics.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/Metrics.java
@@ -1,6 +1,7 @@
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.metrics;
+import java.time.Instant;
import java.util.List;
/**
@@ -8,19 +9,21 @@ import java.util.List;
*/
public class Metrics {
- private double queriesPerSecond;
- private double writesPerSecond;
- private double documentCount;
- private double queryLatencyMillis;
- private double writeLatencyMills;
+ private final double queriesPerSecond;
+ private final double writesPerSecond;
+ private final double documentCount;
+ private final double queryLatencyMillis;
+ private final double writeLatencyMills;
+ private final Instant timestamp;
public Metrics(double queriesPerSecond, double writesPerSecond, double documentCount,
- double queryLatencyMillis, double writeLatencyMills) {
+ double queryLatencyMillis, double writeLatencyMills, Instant timestamp) {
this.queriesPerSecond = queriesPerSecond;
this.writesPerSecond = writesPerSecond;
this.documentCount = documentCount;
this.queryLatencyMillis = queryLatencyMillis;
this.writeLatencyMills = writeLatencyMills;
+ this.timestamp = timestamp;
}
@@ -44,11 +47,8 @@ public class Metrics {
return writeLatencyMills;
}
- public void accumulate(Metrics metrics) {
- this.queriesPerSecond += metrics.getQueriesPerSecond();
- this.writesPerSecond += metrics.getWritesPerSecond();
- this.queryLatencyMillis += metrics.getQueryLatencyMillis();
- this.writeLatencyMills += metrics.getWriteLatencyMills();
+ public Instant getTimestamp() {
+ return timestamp;
}
public static Metrics averagedMetrics(List<Metrics> metrics) {
@@ -57,7 +57,19 @@ public class Metrics {
metrics.stream().mapToDouble(Metrics::getWritesPerSecond).sum() / metrics.size(),
metrics.stream().mapToDouble(Metrics::getDocumentCount).sum() / metrics.size(),
metrics.stream().mapToDouble(Metrics::getQueryLatencyMillis).sum() / metrics.size(),
- metrics.stream().mapToDouble(Metrics::getWriteLatencyMills).sum() / metrics.size()
+ metrics.stream().mapToDouble(Metrics::getWriteLatencyMills).sum() / metrics.size(),
+ metrics.stream().findAny().get().timestamp
+ );
+ }
+
+ public static Metrics accumulatedMetrics(List<Metrics> metrics) {
+ return new Metrics(
+ metrics.stream().mapToDouble(Metrics::getQueriesPerSecond).sum(),
+ metrics.stream().mapToDouble(Metrics::getWritesPerSecond).sum() ,
+ metrics.stream().mapToDouble(Metrics::getDocumentCount).sum(),
+ metrics.stream().mapToDouble(Metrics::getQueryLatencyMillis).sum(),
+ metrics.stream().mapToDouble(Metrics::getWriteLatencyMills).sum(),
+ metrics.stream().findAny().get().timestamp
);
}
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/MetricsAggregator.java b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/MetricsAggregator.java
index bf1618b1696..9b74e46111b 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/MetricsAggregator.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/MetricsAggregator.java
@@ -2,10 +2,12 @@
package com.yahoo.vespa.config.server.metrics;
import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.slime.ArrayTraverser;
import com.yahoo.slime.Inspector;
+import com.yahoo.slime.ObjectTraverser;
import com.yahoo.slime.Slime;
import com.yahoo.vespa.config.SlimeUtils;
-import com.yahoo.vespa.config.server.http.v2.MetricsRespone;
+import com.yahoo.vespa.config.server.http.v2.MetricsResponse;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
@@ -16,6 +18,8 @@ import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URI;
import java.time.Instant;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
@@ -31,16 +35,15 @@ public class MetricsAggregator {
private static final Logger logger = Logger.getLogger(MetricsAggregator.class.getName());
HttpClient httpClient = HttpClientBuilder.create().build();
- public MetricsRespone aggregateAllMetrics(Map<ApplicationId, Map<String, List<URI>>> applicationHosts) {
+ public MetricsResponse aggregateAllMetrics(Map<ApplicationId, Map<String, List<URI>>> applicationHosts) {
Map<ApplicationId, Map<String, Metrics>> aggregatedMetrics = applicationHosts.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e-> aggregateMetricsByCluster(e.getValue())));
- return new MetricsRespone(200, aggregatedMetrics);
+ return new MetricsResponse(200, aggregatedMetrics);
}
private Map<String, Metrics> aggregateMetricsByCluster(Map<String, List<URI>> clusterHosts) {
- logger.log(Level.WARNING, clusterHosts.keySet() +" ");
return clusterHosts.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
@@ -54,8 +57,7 @@ public class MetricsAggregator {
.map(host -> getMetrics(host))
.collect(Collectors.toList());
Metrics.averagedMetrics(metrics);
- logger.log(Level.WARNING, metrics + "");
- return Metrics.averagedMetrics(metrics);
+ return Metrics.accumulatedMetrics(metrics);
}
private Metrics getMetrics(URI hostURI) {
@@ -67,14 +69,30 @@ public class MetricsAggregator {
Slime slime = SlimeUtils.jsonToSlime(is.readAllBytes());
is.close();
- Inspector metrics = slime.get().field("metrics");
- Instant timestamp = Instant.ofEpochSecond(slime.get().field("timestamp").asLong());
- double queriesPerSecond = metrics.field("queriesPerSecond").asDouble();
- double writesPerSecond = metrics.field("writesPerSecond").asDouble();
- double documentCount = metrics.field("documentCount").asDouble();
- double queryLatencyMillis = metrics.field("queryLatencyMillis").asDouble();
- double writeLatencyMills = metrics.field("writeLatencyMills").asDouble();
- return new Metrics(queriesPerSecond, writesPerSecond, documentCount, queryLatencyMillis, writeLatencyMills);
+ Inspector nodeMetrics = slime.get().field("node");
+
+ List<Metrics> metricsList = new ArrayList<>();
+ Inspector services = slime.get().field("services");
+ services.traverse((ArrayTraverser) (i, servicesInspector) -> {
+ String serviceName = servicesInspector.field("name").asString();
+
+ Instant timestamp = Instant.ofEpochSecond(servicesInspector.field("timestamp").asLong());
+ Inspector serviceMetrics = servicesInspector.field("metrics");
+ serviceMetrics.traverse((ArrayTraverser) (j, metrics) -> {
+ Inspector values = metrics.field("values");
+ double queryCount = values.field("queries.count").asDouble();
+ double queryLatency = values.field("query_latency.sum").asDouble();
+ double documentCount = values.field("document.count").asDouble();
+ double writeCount = values.field("write.count").asDouble();
+ double writeLatency = values.field("write_latency.sum").asDouble();
+ logger.log(Level.WARNING, writeLatency + " write latency");
+ Map<String, Double> map = new HashMap<>();
+ values.traverse((ObjectTraverser) (key, value) -> map.put(key, value.asDouble()));
+ metricsList.add(new Metrics(queryCount, writeCount, documentCount, queryLatency, writeLatency, timestamp));
+ });
+
+ });
+ return Metrics.accumulatedMetrics(metricsList);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/metrics/MetricsAggregatorTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/metrics/MetricsAggregatorTest.java
index 52c7cbec43e..9e8dc88773c 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/metrics/MetricsAggregatorTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/metrics/MetricsAggregatorTest.java
@@ -1,15 +1,8 @@
package com.yahoo.vespa.config.server.metrics;
-import com.github.tomakehurst.wiremock.WireMockServer;
-import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
-import com.yahoo.config.model.api.HostInfo;
import com.yahoo.config.provision.ApplicationId;
-import com.yahoo.vespa.config.server.application.Application;
-import com.yahoo.vespa.config.server.application.TenantApplications;
-import com.yahoo.vespa.config.server.http.v2.MetricsRespone;
-import com.yahoo.vespa.config.server.tenant.Tenant;
-import org.junit.Before;
+import com.yahoo.vespa.config.server.http.v2.MetricsResponse;
import org.junit.Rule;
import org.junit.Test;
@@ -18,8 +11,6 @@ import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -28,11 +19,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;import com.yahoo.config.model.api.Model;
/**
@@ -49,8 +36,8 @@ public class MetricsAggregatorTest {
ApplicationId applicationId = ApplicationId.from("tenant", "app", "default");
Map<String, List<URI>> clusterHosts = Map.of(
- "cluster1", List.of(URI.create("http://localhost:8080/1"), URI.create("http://localhost:8080/3")),
- "cluster2", List.of(URI.create("http://localhost:8080/3"), URI.create("http://localhost:8080/3"))
+ "cluster1", List.of(URI.create("http://localhost:8080/1"), URI.create("http://localhost:8080/2")),
+ "cluster2", List.of(URI.create("http://localhost:8080/3"))
);
Map<ApplicationId, Map<String, List<URI>>> applications = Map.of(applicationId, clusterHosts);
@@ -69,21 +56,40 @@ public class MetricsAggregatorTest {
.withStatus(200)
.withBody(metricsString(1,2,3,4,5))));
- MetricsRespone metricsRespone = metricsAggregator.aggregateAllMetrics(applications);
+ MetricsResponse metricsResponse = metricsAggregator.aggregateAllMetrics(applications);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- metricsRespone.render(bos);
- assertEquals(Files.readString(Path.of("src/test/resources/metrics_response")), bos.toString());
+ metricsResponse.render(bos);
+ String expectedResponse = "[\n" +
+ " {\n" +
+ " \"applicationId\": \"tenant:app:default\",\n" +
+ " \"clusters\": [\n" +
+ " {\n" +
+ " \"clusterName\": \"cluster1\",\n" +
+ " \"queriesPerSecond\": 132.0,\n" +
+ " \"writesPerSecond\": 46.0,\n" +
+ " \"documentCount\": 600000.0,\n" +
+ " \"queryLatencyMillis\": 10000.0,\n" +
+ " \"writeLatencyMillis\": 4000.0,\n" +
+ " \"timestamp\": 1557306075\n" +
+ " },\n" +
+ " {\n" +
+ " \"clusterName\": \"cluster2\",\n" +
+ " \"queriesPerSecond\": 66.0,\n" +
+ " \"writesPerSecond\": 23.0,\n" +
+ " \"documentCount\": 300000.0,\n" +
+ " \"queryLatencyMillis\": 5000.0,\n" +
+ " \"writeLatencyMillis\": 2000.0,\n" +
+ " \"timestamp\": 1557306075\n" +
+ " }\n" +
+ " ]\n" +
+ " }\n" +
+ "]\n";
+ assertEquals(expectedResponse, bos.toString());
wireMock.stop();
}
- private String metricsString(double queriesPerSecond, double writesPerSecond, double documentCount, double queryLatencyMillis, double writeLatencyMills) {
- return "{\"metrics\": " +
- "{" +
- " \"queriesPerSecond\": " + queriesPerSecond + "," +
- " \"writesPerSecond\": " + writesPerSecond + "," +
- " \"documentCount\": " + documentCount + "," +
- " \"queryLatencyMillis\": " + queryLatencyMillis + "," +
- " \"writeLatencyMills\": " + writeLatencyMills +
- " }}";
+ private String metricsString(double queriesPerSecond, double writesPerSecond, double documentCount, double queryLatencyMillis, double writeLatencyMills) throws IOException {
+ String responseBody = Files.readString(Path.of("src/test/resources/metrics_response"));
+ return String.format(responseBody, queriesPerSecond, writesPerSecond, documentCount, queryLatencyMillis, writeLatencyMills);
}
} \ No newline at end of file
diff --git a/configserver/src/test/resources/metrics_response b/configserver/src/test/resources/metrics_response
index b400a0538a6..7956a73523f 100644
--- a/configserver/src/test/resources/metrics_response
+++ b/configserver/src/test/resources/metrics_response
@@ -1,23 +1,25 @@
-[
- {
- "applicationId": "tenant:app:default",
- "clusters": [
- {
- "clusterName": "cluster1",
- "queriesPerSecond": 5.5,
- "writesPerSecond": 11.0,
- "documentCount": 18.0,
- "queryLatencyMillis": 22.0,
- "writeLatencyMillis": 27.5
- },
- {
- "clusterName": "cluster2",
- "queriesPerSecond": 1.0,
- "writesPerSecond": 2.0,
- "documentCount": 3.0,
- "queryLatencyMillis": 4.0,
- "writeLatencyMillis": 5.0
- }
+{
+ "services": [
+ {
+ "name":"searchnode",
+ "timestamp": 1557306075,
+ "metrics": [
+ {
+ "values": {
+ "queries.count": 23.0,
+ "query_latency.sum": 2000,
+ "document.count": 300000,
+ "write.count": 23.0,
+ "write_latency.sum": 2000
+ }
+ },
+ {
+ "values": {
+ "queries.count": 43.0,
+ "query_latency.sum": 3000
+ }
+ }
+ ]
+ }
]
- }
-]
+} \ No newline at end of file