aboutsummaryrefslogtreecommitdiffstats
path: root/aai-resources/src/test
diff options
context:
space:
mode:
authorroger yuan <roger.yuan@yoppworks.com>2021-05-19 09:42:33 -0600
committerroger yuan <roger.yuan@yoppworks.com>2021-05-19 12:21:05 -0600
commit641a1a0318a6de88ad5e4643258f7165783141e7 (patch)
treec1e6564111d6a21c5d4b1af9fd52818707b07802 /aai-resources/src/test
parentf64cb0565a5856f8824d3496aa934f413df77e56 (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')
-rw-r--r--aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java35
-rw-r--r--aai-resources/src/test/resources/application-test.properties8
2 files changed, 42 insertions, 1 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"));
+ }
}
diff --git a/aai-resources/src/test/resources/application-test.properties b/aai-resources/src/test/resources/application-test.properties
index b96b9ce..8aee5e1 100644
--- a/aai-resources/src/test/resources/application-test.properties
+++ b/aai-resources/src/test/resources/application-test.properties
@@ -15,7 +15,8 @@ spring.autoconfigure.exclude=\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
org.keycloak.adapters.springboot.KeycloakAutoConfiguration,\
- org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
+ org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\
+ org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
spring.profiles.active=production
#The max number of active threads in this pool
@@ -72,3 +73,8 @@ schema.version.edge.label.start=v12
schema.version.api.default=v15
schema.translator.list=config
+#To expose the Prometheus scraping endpoint in unit test
+management.server.port=0
+management.endpoints.enabled-by-default=true
+management.endpoints.web.exposure.include=info, health, prometheus
+management.metrics.web.server.auto-time-requests=false