ApplicationMetricsRetriever extends AbstractComponent { public Map<Node, List<MetricsPacket>> getMetrics() { return getMetrics(defaultMetricsConsumerId); } @Inject  ApplicationMetricsRetriever(MetricsNodesConfig nodesConfig); @Override void deconstruct(); Map<Node, List<MetricsPacket>> getMetrics(); Map<Node, List<MetricsPacket>> getMetrics(ConsumerId consumer);  }
@Test public void metrics_can_be_retrieved_from_multiple_nodes() { var config = nodesConfig("/node0", "/node1"); Node node0 = new Node(config.node(0)); Node node1 = new Node(config.node(1)); wireMockRule.stubFor(get(urlPathEqualTo(config.node(0).metricsPath())) .willReturn(aResponse().withBody(RESPONSE))); wireMockRule.stubFor(get(urlPathEqualTo(config.node(1).metricsPath())) .willReturn(aResponse().withBody(RESPONSE))); ApplicationMetricsRetriever retriever = new ApplicationMetricsRetriever(config); var metricsByNode = retriever.getMetrics(); assertEquals(2, metricsByNode.size()); assertEquals(4, metricsByNode.get(node0).size()); assertEquals(4, metricsByNode.get(node1).size()); }
@Test public void dead_node_yields_empty_metrics() { var config = nodesConfig("/non-existent"); Node node = new Node(config.node(0)); ApplicationMetricsRetriever retriever = new ApplicationMetricsRetriever(config); var metricsByNode = retriever.getMetrics(); assertEquals(1, metricsByNode.size()); assertEquals(0, metricsByNode.get(node).size()); }
@Test public void metrics_from_good_node_are_returned_even_if_another_node_is_dead() { var config = nodesConfig("/node0", "/node1"); Node node0 = new Node(config.node(0)); Node node1 = new Node(config.node(1)); wireMockRule.stubFor(get(urlPathEqualTo(config.node(1).metricsPath())) .willReturn(aResponse().withBody(RESPONSE))); ApplicationMetricsRetriever retriever = new ApplicationMetricsRetriever(config); var metricsByNode = retriever.getMetrics(); assertEquals(2, metricsByNode.size()); assertEquals(0, metricsByNode.get(node0).size()); assertEquals(4, metricsByNode.get(node1).size()); }