From 641a1a0318a6de88ad5e4643258f7165783141e7 Mon Sep 17 00:00:00 2001 From: roger yuan Date: Wed, 19 May 2021 09:42:33 -0600 Subject: [AAI] Export relevant key metrics for monitoring in Prometheus Make the key metrics available to the monitoring system by instrumenting the code. The Key metrics are available via /actuator/prometheus /actuator/info /actuator/health Issue-ID: AAI-3343 Signed-off-by: Roger Yuan Change-Id: I69f7eafb5105a04369526c70902ac7b676038c36 --- .../java/org/onap/aai/rest/ConfigurationTest.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'aai-resources/src/test/java/org/onap') diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java index ee33bfc..39f71fd 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java @@ -27,6 +27,7 @@ import org.onap.aai.ResourcesTestConfiguration; import org.onap.aai.restclient.PropertyPasswordConfiguration; import org.onap.aai.config.SpringContextAware; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; @@ -42,6 +43,7 @@ import java.util.Collections; import java.util.UUID; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Test REST requests against configuration resource @@ -58,10 +60,14 @@ public class ConfigurationTest extends AbstractSpringRestTest { @LocalServerPort int randomPort; + @Value("${local.management.port}") + private int mgtPort; + private HttpEntity httpEntity; private HttpEntity httpEntityPut; private HttpEntity httpEntityPatch; private String baseUrl; + private String actuatorurl; private HttpHeaders headers; @Before public void setup() throws UnsupportedEncodingException { @@ -79,6 +85,7 @@ public class ConfigurationTest extends AbstractSpringRestTest { httpEntity = new HttpEntity(headers); baseUrl = "http://localhost:" + randomPort; + actuatorurl = "http://localhost:" + mgtPort; } @Test @@ -157,4 +164,32 @@ public class ConfigurationTest extends AbstractSpringRestTest { } + + @Test + public void TestManagementEndpointConfiguration() { + ResponseEntity responseEntity = null; + String responseBody = null; + + //set Accept as text/plain in order to get access of endpoint "/actuator/prometheus" + headers.set("Accept", "text/plain"); + httpEntity = new HttpEntity(headers); + responseEntity = restTemplate.exchange(actuatorurl + "/actuator/prometheus", HttpMethod.GET, httpEntity, String.class); + responseBody = (String) responseEntity.getBody(); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertTrue(responseBody.contains("app_id")); + assertTrue(responseBody.contains("group_id")); + + //Set Accept as MediaType.APPLICATION_JSON in order to get access of endpoint "/actuator/info" and "/actuator/health" + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + httpEntity = new HttpEntity(headers); + responseEntity = restTemplate.exchange(actuatorurl + "/actuator/info", HttpMethod.GET, httpEntity, String.class); + responseBody = (String) responseEntity.getBody(); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertTrue(responseBody.contains("aai-resources")); + + responseEntity = restTemplate.exchange(actuatorurl + "/actuator/health", HttpMethod.GET, httpEntity, String.class); + responseBody = (String) responseEntity.getBody(); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertTrue(responseBody.contains("UP")); + } } -- cgit 1.2.3-korg