diff options
author | gjoranv <gv@verizonmedia.com> | 2020-01-17 14:33:13 +0100 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2020-01-17 14:33:13 +0100 |
commit | 051d7d700d83f8b77ffa0efc8efd8319758d9b10 (patch) | |
tree | cba10cab11769a64b383b2d4e2097b819601a1de /metrics-proxy | |
parent | ada10218a6190254cfcfa367c242ae239b592397 (diff) |
Expose hostname, and rename nodeId -> role.
Diffstat (limited to 'metrics-proxy')
8 files changed, 32 insertions, 37 deletions
diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/Node.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/Node.java index 07070027f96..c8a8e65be5d 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/Node.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/Node.java @@ -13,31 +13,27 @@ import java.util.Objects; */ public class Node { - final String nodeId; - final String host; - final int port; - final String path; + public final String role; + public final String hostname; + private final int port; + private final String path; private final String metricsUriBase; public Node(MetricsNodesConfig.Node nodeConfig) { - this(nodeConfig.nodeId(), nodeConfig.hostname(), nodeConfig.metricsPort() , nodeConfig.metricsPath()); + this(nodeConfig.role(), nodeConfig.hostname(), nodeConfig.metricsPort() , nodeConfig.metricsPath()); } - public Node(String nodeId, String host, int port, String path) { - Objects.requireNonNull(nodeId, "Null configId is not allowed"); - Objects.requireNonNull(host, "Null host is not allowed"); + public Node(String role, String hostname, int port, String path) { + Objects.requireNonNull(role, "Null configId is not allowed"); + Objects.requireNonNull(hostname, "Null hostname is not allowed"); Objects.requireNonNull(path, "Null path is not allowed"); - this.nodeId = nodeId; - this.host = host; + this.role = role; + this.hostname = hostname; this.port = port; this.path = path; - metricsUriBase = "http://" + host + ":" + port + path; - } - - public String getName() { - return nodeId; + metricsUriBase = "http://" + hostname + ":" + port + path; } URI metricsUri(ConsumerId consumer) { @@ -50,12 +46,13 @@ public class Node { if (o == null || getClass() != o.getClass()) return false; Node node = (Node) o; return port == node.port && - nodeId.equals(node.nodeId) && - host.equals(node.host); + path.equals(node.path) && + role.equals(node.role) && + hostname.equals(node.hostname); } @Override public int hashCode() { - return Objects.hash(nodeId, host, port); + return Objects.hash(role, hostname, port, path); } } diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/GenericJsonModel.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/GenericJsonModel.java index bd17a238607..83a69a38a87 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/GenericJsonModel.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/GenericJsonModel.java @@ -19,11 +19,11 @@ import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_ABSENT; */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(NON_ABSENT) -@JsonPropertyOrder({ "name", "node", "services" }) +@JsonPropertyOrder({ "hostname", "node", "services" }) public class GenericJsonModel { - @JsonProperty("name") - public String name; + @JsonProperty("hostname") + public String hostname; @JsonProperty("node") public GenericNode node; diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/GenericJsonUtil.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/GenericJsonUtil.java index 437d6d300ef..8ff86d8a821 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/GenericJsonUtil.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/GenericJsonUtil.java @@ -12,7 +12,6 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -72,7 +71,7 @@ public class GenericJsonUtil { .get(); if (VESPA_NODE_SERVICE_ID.equals(serviceId)) { jsonModel.node = new GenericNode(genericService.timestamp, genericService.metrics); - jsonModel.name = node == null ? null : node.getName(); + jsonModel.hostname = node == null ? null : node.hostname; } else { genericServices.add(genericService); diff --git a/metrics-proxy/src/main/resources/configdefinitions/metrics-nodes.def b/metrics-proxy/src/main/resources/configdefinitions/metrics-nodes.def index 0de2f21d972..4feceb338b3 100644 --- a/metrics-proxy/src/main/resources/configdefinitions/metrics-nodes.def +++ b/metrics-proxy/src/main/resources/configdefinitions/metrics-nodes.def @@ -1,7 +1,7 @@ # Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package=ai.vespa.metricsproxy.http.application -node[].nodeId string node[].hostname string +node[].role string node[].metricsPort int node[].metricsPath string diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java index d1224e79e45..959b73d5682 100644 --- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java @@ -43,7 +43,8 @@ import static org.junit.Assert.fail; @SuppressWarnings("UnstableApiUsage") public class ApplicationMetricsHandlerTest { - private static final String URI_BASE = "http://localhost"; + private static final String HOST = "localhost"; + private static final String URI_BASE = "http://" + HOST; private static final String APP_METRICS_V1_URI = URI_BASE + V1_PATH; private static final String APP_METRICS_VALUES_URI = URI_BASE + VALUES_PATH; @@ -117,7 +118,7 @@ public class ApplicationMetricsHandlerTest { assertEquals(1, jsonModel.nodes.size()); GenericJsonModel nodeModel = jsonModel.nodes.get(0); - assertEquals(MOCK_METRICS_PATH, nodeModel.name); + assertEquals(HOST, nodeModel.hostname); assertEquals(2, nodeModel.node.metrics.size()); assertEquals(16.222, nodeModel.node.metrics.get(0).values.get(CPU_METRIC), 0.0001d); } @@ -171,7 +172,7 @@ public class ApplicationMetricsHandlerTest { private MetricsNodesConfig.Node.Builder nodeConfig(String path) { return new MetricsNodesConfig.Node.Builder() - .nodeId(path) + .role(path) .hostname("localhost") .metricsPath(path) .metricsPort(port); diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsRetrieverTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsRetrieverTest.java index 5ff6b580988..1f2852e3526 100644 --- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsRetrieverTest.java +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsRetrieverTest.java @@ -157,7 +157,7 @@ public class ApplicationMetricsRetrieverTest { private MetricsNodesConfig.Node.Builder nodeConfig(String path) { return new MetricsNodesConfig.Node.Builder() - .nodeId(path) + .role(path) .hostname(HOST) .metricsPath(path) .metricsPort(port); diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/model/json/GenericApplicationModelTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/model/json/GenericApplicationModelTest.java index c0abc3efb86..73b6c014b92 100644 --- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/model/json/GenericApplicationModelTest.java +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/model/json/GenericApplicationModelTest.java @@ -33,7 +33,7 @@ public class GenericApplicationModelTest { // Do some sanity checking assertEquals(2, model.nodes.size()); GenericJsonModel node0Model = model.nodes.get(0); - assertEquals("node0", node0Model.name); + assertEquals("node0", node0Model.hostname); assertEquals(1, node0Model.services.size()); GenericService service = node0Model.services.get(0); assertEquals(1, service.metrics.size()); @@ -41,7 +41,7 @@ public class GenericApplicationModelTest { GenericJsonModel node1Model = model.nodes.get(1); GenericNode node1 = node1Model.node; - assertEquals("node1", node1Model.name); + assertEquals("node1", node1Model.hostname); assertEquals(32.444, node1.metrics.get(0).values.get("cpu.util"), 0.001d); assertThatSerializedModelEqualsTestFile(model); @@ -63,13 +63,14 @@ public class GenericApplicationModelTest { .build(); - var metricsByNode = Map.of(toNode("node0"), List.of(nodePacket, servicePacket)); + var metricsByNode = Map.of(new Node("my-role", "hostname", 0, "path"), + List.of(nodePacket, servicePacket)); GenericApplicationModel model = GenericJsonUtil.toGenericApplicationModel(metricsByNode); GenericJsonModel nodeModel = model.nodes.get(0); assertNotNull(nodeModel.node); - assertEquals("node0", nodeModel.name); + assertEquals("hostname", nodeModel.hostname); assertEquals(1, nodeModel.node.metrics.size()); GenericMetrics nodeMetrics = nodeModel.node.metrics.get(0); assertEquals(1.234, nodeMetrics.values.get("node-metric"), 0.001d); @@ -112,7 +113,4 @@ public class GenericApplicationModelTest { return mapper.readValue(getFileContents(TEST_FILE), GenericApplicationModel.class); } - private static Node toNode(String name) { - return new Node(name, "host", 0, "path"); - } } diff --git a/metrics-proxy/src/test/resources/generic-application.json b/metrics-proxy/src/test/resources/generic-application.json index 5ddd11962be..377293a1d3b 100644 --- a/metrics-proxy/src/test/resources/generic-application.json +++ b/metrics-proxy/src/test/resources/generic-application.json @@ -1,7 +1,7 @@ { "nodes": [ { - "name": "node0", + "hostname": "node0", "node": { "timestamp": 1234, "metrics": [ @@ -36,7 +36,7 @@ ] }, { - "name": "node1", + "hostname": "node1", "node": { "timestamp": 1234, "metrics": [ |