diff options
author | roger yuan <roger.yuan@yoppworks.com> | 2021-05-19 09:42:33 -0600 |
---|---|---|
committer | roger yuan <roger.yuan@yoppworks.com> | 2021-05-19 12:21:05 -0600 |
commit | 641a1a0318a6de88ad5e4643258f7165783141e7 (patch) | |
tree | c1e6564111d6a21c5d4b1af9fd52818707b07802 /aai-resources/src/test/java/org/onap | |
parent | f64cb0565a5856f8824d3496aa934f413df77e56 (diff) |
[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 <roger.yuan@yoppworks.com>
Change-Id: I69f7eafb5105a04369526c70902ac7b676038c36
Diffstat (limited to 'aai-resources/src/test/java/org/onap')
-rw-r--r-- | aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java | 35 |
1 files changed, 35 insertions, 0 deletions
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<String> httpEntity; private HttpEntity<String> httpEntityPut; private HttpEntity<String> 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<String>(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<String>(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<String>(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")); + } } |