use of com.alibaba.nacos.api.config.remote.response.ClientConfigMetricResponse in project nacos by alibaba.
the class ClientMetricsControllerTest method testGetCurrentMetric.
@Test
public void testGetCurrentMetric() throws Exception {
ClientConfigMetricResponse response = new ClientConfigMetricResponse();
response.putMetric("test", "test");
Connection connection = Mockito.mock(Connection.class);
when(connection.request(any(), anyLong())).thenReturn(response);
List<Connection> connections = new ArrayList<>();
connections.add(connection);
when(connectionManager.getConnectionByIp(eq("127.0.0.1"))).thenReturn(connections);
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.METRICS_CONTROLLER_PATH + "/current").param("ip", "127.0.0.1").param("tenant", "test").param("dataId", "test").param("group", "test");
String actualValue = mockMvc.perform(builder).andReturn().getResponse().getContentAsString();
Assert.assertEquals("{\"test\":\"test\"}", actualValue);
}
use of com.alibaba.nacos.api.config.remote.response.ClientConfigMetricResponse in project nacos by alibaba.
the class ClientMetricsController method getClientMetrics.
/**
* Get client config listener lists of subscriber in local machine.
*/
@GetMapping("/current")
public Map<String, Object> getClientMetrics(@RequestParam("ip") String ip, @RequestParam(value = "dataId", required = false) String dataId, @RequestParam(value = "group", required = false) String group, @RequestParam(value = "tenant", required = false) String tenant) {
Map<String, Object> metrics = new HashMap<>(16);
List<Connection> connectionsByIp = connectionManager.getConnectionByIp(ip);
for (Connection connectionByIp : connectionsByIp) {
try {
ClientConfigMetricRequest clientMetrics = new ClientConfigMetricRequest();
if (StringUtils.isNotBlank(dataId)) {
clientMetrics.getMetricsKeys().add(ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, GroupKey2.getKey(dataId, group, tenant)));
clientMetrics.getMetricsKeys().add(ClientConfigMetricRequest.MetricsKey.build(SNAPSHOT_DATA, GroupKey2.getKey(dataId, group, tenant)));
}
ClientConfigMetricResponse request1 = (ClientConfigMetricResponse) connectionByIp.request(clientMetrics, 1000L);
metrics.putAll(request1.getMetrics());
} catch (Exception e) {
Loggers.CORE.error("Get config metrics error from client ip={},dataId={},group={},tenant={},error={}", ip, dataId, group, tenant, e);
}
}
return metrics;
}
Aggregations