servers:
- ${topicServer:message-router}
topicCommInfrastructure: dmaap
+
+management:
+ endpoints:
+ web:
+ exposure:
+ include: health, metrics, prometheus
<parent>
<groupId>org.onap.policy.parent</groupId>
<artifactId>integration</artifactId>
- <version>3.4.0-SNAPSHOT</version>
+ <version>3.4.1-SNAPSHOT</version>
</parent>
<groupId>org.onap.policy.clamp</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${version.springfox}</version>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ <version>${version.springboot}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.micrometer</groupId>
+ <artifactId>micrometer-registry-prometheus</artifactId>
+ <version>${version.io.micrometer}</version>
+ </dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
package org.onap.policy.clamp.controlloop.runtime.config;
+import java.util.Arrays;
import java.util.List;
import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new CoderHttpMesageConverter<>("yaml"));
converters.add(new CoderHttpMesageConverter<>("json"));
+
+ StringHttpMessageConverter converter = new StringHttpMessageConverter();
+ converter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN));
+ converters.add(converter);
}
}
servers:
- ${topicServer:localhost}
topicCommInfrastructure: dmaap
+
+management:
+ endpoints:
+ web:
+ exposure:
+ include: health, metrics, prometheus
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.runtime.main.rest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.core.Response;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController;
+import org.springframework.boot.test.autoconfigure.actuate.metrics.AutoConfigureMetrics;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+@AutoConfigureMetrics
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+@TestPropertySource(locations = {"classpath:application_test.properties"})
+class ActuatorControllerTest extends CommonRestController {
+
+ private static final String HEALTH_ENDPOINT = "health";
+ private static final String METRICS_ENDPOINT = "metrics";
+ private static final String PROMETHEUS_ENDPOINT = "prometheus";
+
+ @LocalServerPort
+ private int randomServerPort;
+
+ @BeforeEach
+ public void setUpPort() {
+ super.setHttpPrefix(randomServerPort);
+ }
+
+ @Test
+ void testGetHealth_Unauthorized() throws Exception {
+ assertUnauthorizedActGet(HEALTH_ENDPOINT);
+ }
+
+ @Test
+ void testGetMetrics_Unauthorized() throws Exception {
+ assertUnauthorizedActGet(METRICS_ENDPOINT);
+ }
+
+ @Test
+ void testGetPrometheus_Unauthorized() throws Exception {
+ assertUnauthorizedActGet(PROMETHEUS_ENDPOINT);
+ }
+
+ @Test
+ void testGetHealth() throws Exception {
+ Invocation.Builder invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT);
+ Response rawresp = invocationBuilder.buildGet().invoke();
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ }
+
+ @Test
+ void testGetMetrics() throws Exception {
+ Invocation.Builder invocationBuilder = super.sendActRequest(METRICS_ENDPOINT);
+ Response rawresp = invocationBuilder.buildGet().invoke();
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ }
+
+ @Test
+ void testGePrometheus() throws Exception {
+ Invocation.Builder invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT);
+ Response rawresp = invocationBuilder.buildGet().invoke();
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ }
+}
public class CommonRestController {
public static final String SELF = NetworkUtil.getHostname();
- public static final String ENDPOINT_PREFIX = "onap/controlloop/v2/";
+ public static final String CONTEXT_PATH = "onap/controlloop";
+ public static final String ENDPOINT_PREFIX = CONTEXT_PATH + "/v2/";
+ public static final String ACTUATOR_ENDPOINT = CONTEXT_PATH + "/actuator/";
private static String httpPrefix;
}
/**
- * Sends a request to an endpoint, without any authorization header.
+ * Sends a request to an actuator endpoint.
+ *
+ * @param endpoint the target endpoint
+ * @return a request builder
+ * @throws Exception if an error occurs
+ */
+ protected Invocation.Builder sendActRequest(final String endpoint) throws Exception {
+ return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + endpoint, true);
+ }
+
+ /**
+ * Sends a request to an Rest Api endpoint, without any authorization header.
*
* @param endpoint the target endpoint
* @return a request builder
return sendFqeRequest(httpPrefix + ENDPOINT_PREFIX + endpoint, false);
}
+ /**
+ * Sends a request to an actuator endpoint, without any authorization header.
+ *
+ * @param endpoint the target endpoint
+ * @return a request builder
+ * @throws Exception if an error occurs
+ */
+ protected Invocation.Builder sendNoAuthActRequest(final String endpoint) throws Exception {
+ return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + endpoint, false);
+ }
+
/**
* Sends a request to a fully qualified endpoint.
*
final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
- return webTarget.request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON);
+ return webTarget.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN);
}
/**
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
+ /**
+ * Assert that GET call to actuator endpoint is Unauthorized.
+ *
+ * @param endPoint the endpoint
+ * @throws Exception if an error occurs
+ */
+ protected void assertUnauthorizedActGet(final String endPoint) throws Exception {
+ Response rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
+ assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
+ }
+
/**
* Assert that DELETE call is Unauthorized.
*
protected void setHttpPrefix(int port) {
httpPrefix = "http://" + SELF + ":" + port + "/";
}
+
+ protected String getHttpPrefix() {
+ return httpPrefix;
+ }
}
runtime.topicParameterGroup.topicSinks[0].topic=POLICY-CLRUNTIME-PARTICIPANT
runtime.topicParameterGroup.topicSinks[0].servers[0]=localhost
runtime.topicParameterGroup.topicSinks[0].topicCommInfrastructure=dmaap
+
+management.endpoints.web.exposure.include=health,metrics,prometheus