From fe43edecef38cc06f7c540eaf43016e38f360227 Mon Sep 17 00:00:00 2001 From: "adheli.tavares" Date: Thu, 9 Jun 2022 10:03:13 +0100 Subject: Fix configuration for Prometheus metrics JVM related metrics were not being exposed due to spring boot bug when loading beans configuration. Issue-ID: POLICY-4146 Change-Id: I334c60b0c0d087c63b28bf44704aa3e909eca646 Signed-off-by: adheli.tavares --- .../acm/runtime/config/ConverterConfiguration.java | 5 ++- .../acm/runtime/config/MetricsConfiguration.java | 40 ++++++++++++++++++++++ .../runtime/main/web/AbstractRestController.java | 5 +-- runtime-acm/src/main/resources/application.yaml | 3 +- 4 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/MetricsConfiguration.java (limited to 'runtime-acm/src/main') diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/ConverterConfiguration.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/ConverterConfiguration.java index f51497266..6776e59a6 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/ConverterConfiguration.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/ConverterConfiguration.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ package org.onap.policy.clamp.acm.runtime.config; -import java.util.Arrays; import java.util.List; import org.onap.policy.clamp.common.acm.rest.CoderHttpMesageConverter; import org.springframework.context.annotation.Configuration; @@ -38,7 +37,7 @@ public class ConverterConfiguration implements WebMvcConfigurer { converters.add(new CoderHttpMesageConverter<>("json")); StringHttpMessageConverter converter = new StringHttpMessageConverter(); - converter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN)); + converter.setSupportedMediaTypes(List.of(MediaType.TEXT_PLAIN)); converters.add(converter); } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/MetricsConfiguration.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/MetricsConfiguration.java new file mode 100644 index 000000000..dca31cdb8 --- /dev/null +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/MetricsConfiguration.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2022 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.acm.runtime.config; + +import io.micrometer.core.instrument.MeterRegistry; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class MetricsConfiguration { + + /** + * Load up the metrics registry. + */ + @Bean + InitializingBean forcePrometheusPostProcessor(BeanPostProcessor meterRegistryPostProcessor, + MeterRegistry registry) { + return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, ""); + } +} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/AbstractRestController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/AbstractRestController.java index 7907de7be..107de58c9 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/AbstractRestController.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/AbstractRestController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,8 @@ import org.springframework.web.bind.annotation.RequestMapping; * Common superclass to provide REST endpoints for the participant simulator. */ // @formatter:off -@RequestMapping(value = "/v2", produces = {MediaType.APPLICATION_JSON, AbstractRestController.APPLICATION_YAML}) +@RequestMapping(value = "/onap/policy/clamp/acm/v2", + produces = {MediaType.APPLICATION_JSON, AbstractRestController.APPLICATION_YAML}) @Api(value = "Automation Composition Commissioning API") @SwaggerDefinition( info = @Info(description = diff --git a/runtime-acm/src/main/resources/application.yaml b/runtime-acm/src/main/resources/application.yaml index 0a5bb8b5d..21c754c1a 100644 --- a/runtime-acm/src/main/resources/application.yaml +++ b/runtime-acm/src/main/resources/application.yaml @@ -32,8 +32,6 @@ security: server: port: 6969 - servlet: - context-path: /onap/policy/clamp/acm error: path: /error @@ -62,5 +60,6 @@ runtime: management: endpoints: web: + base-path: / exposure: include: health, metrics, prometheus -- cgit 1.2.3-korg