diff options
author | roger yuan <roger.yuan@yoppworks.com> | 2021-05-19 10:02:03 -0600 |
---|---|---|
committer | roger yuan <roger.yuan@yoppworks.com> | 2021-05-19 12:22:31 -0600 |
commit | 6180838e24698c885091d65603c6ce19c54853f4 (patch) | |
tree | 6ae837a5f437403adfcbb1c52c37c53140117534 /aai-traversal/src/test/java | |
parent | 7b0b01a41e7eacd40ba296dda474b7fcbc54a1cd (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: If72858484231d95a39c938bacfc1773430806e5a
Diffstat (limited to 'aai-traversal/src/test/java')
-rw-r--r-- | aai-traversal/src/test/java/org/onap/aai/rest/ConfigurationTest.java | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/ConfigurationTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/ConfigurationTest.java new file mode 100644 index 0000000..891956d --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/ConfigurationTest.java @@ -0,0 +1,105 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.rest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.TraversalApp; +import org.onap.aai.TraversalTestConfiguration; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.restclient.PropertyPasswordConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.http.*; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.web.client.RestTemplate; + +import java.io.UnsupportedEncodingException; +import java.util.Base64; +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Test REST requests against configuration resource + */ +@TestPropertySource(locations = "classpath:application-test.properties") +@ContextConfiguration(initializers = PropertyPasswordConfiguration.class, classes = {SpringContextAware.class}) +@Import(TraversalTestConfiguration.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {SpringContextAware.class, TraversalApp.class}) +public class ConfigurationTest extends AbstractSpringRestTest { + @Autowired + RestTemplate restTemplate; + + @Value("${local.management.port}") + private int mgtPort; + + private HttpEntity<String> httpEntity; + private String actuatorurl; + private HttpHeaders headers; + @Before + public void setup() throws UnsupportedEncodingException { + + headers = new HttpHeaders(); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.set("Accept", "text/plain"); + headers.add("Real-Time", "true"); + headers.add("X-FromAppId", "JUNIT"); + headers.add("X-TransactionId", "JUNIT"); + + String authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8")); + headers.add("Authorization", "Basic " + authorization); + + httpEntity = new HttpEntity<String>(headers); + baseUrl = "http://localhost:" + randomPort; + actuatorurl = "http://localhost:" + mgtPort; + } + + @Test + public void TestManagementEndpointConfiguration() { + ResponseEntity responseEntity = null; + String responseBody = null; + + //set Accept as text/plain in order to get access of endpoint "/actuator/prometheus" + 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-traversal")); + + responseEntity = restTemplate.exchange(actuatorurl + "/actuator/health", HttpMethod.GET, httpEntity, String.class); + responseBody = (String) responseEntity.getBody(); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertTrue(responseBody.contains("UP")); + } +} |