From a01b2d8fa0e6ed8138b0edf85964d70b5c08fa92 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Mon, 29 Aug 2022 10:15:45 +0100 Subject: Add Prometheus metric messages for ACM participants Issue-ID: POLICY-4433 Change-Id: I625c9ee26bb2451e0dcfbb4bbf7288dcc0effb50 Signed-off-by: FrancescoFioraEst --- .../policy/config/MicrometerConfig.java | 46 ++++++++++++++++++++++ .../src/main/resources/config/application.yaml | 7 ++++ .../main/utils/CommonActuatorController.java | 7 ++-- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/MicrometerConfig.java (limited to 'participant/participant-impl/participant-impl-policy') diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/MicrometerConfig.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/MicrometerConfig.java new file mode 100644 index 000000000..2f942eaa8 --- /dev/null +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/MicrometerConfig.java @@ -0,0 +1,46 @@ +/*- + * ============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.participant.policy.config; + +import io.micrometer.core.aop.TimedAspect; +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 MicrometerConfig { + + /** + * Load up the metrics registry. + */ + @Bean + public InitializingBean forcePrometheusPostProcessor(BeanPostProcessor meterRegistryPostProcessor, + MeterRegistry registry) { + return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, ""); + } + + @Bean + public TimedAspect timedAspect(MeterRegistry registry) { + return new TimedAspect(registry); + } +} diff --git a/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml index c3338a993..a1fea4d1b 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml +++ b/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml @@ -3,6 +3,12 @@ spring: user: name: participantUser password: zb!XztG34 + autoconfigure: + exclude: + - org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration + - org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration + - org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration participant: pdpGroup: defaultGroup @@ -49,6 +55,7 @@ participant: management: endpoints: web: + base-path: / exposure: include: health, metrics, prometheus server: diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java index f83184024..41f091cbf 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java @@ -40,8 +40,7 @@ import org.onap.policy.common.utils.network.NetworkUtil; public class CommonActuatorController { public static final String SELF = NetworkUtil.getHostname(); - public static final String CONTEXT_PATH = "onap/policy/clamp/acm/policyparticipant"; - public static final String ACTUATOR_ENDPOINT = CONTEXT_PATH + "/actuator/"; + public static final String CONTEXT_PATH = "onap/policy/clamp/acm/policyparticipant/"; private static String httpPrefix; @@ -52,7 +51,7 @@ public class CommonActuatorController { * @return a request builder */ protected Invocation.Builder sendActRequest(final String endpoint) { - return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + endpoint, true); + return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, true); } /** @@ -62,7 +61,7 @@ public class CommonActuatorController { * @return a request builder */ protected Invocation.Builder sendNoAuthActRequest(final String endpoint) { - return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + endpoint, false); + return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, false); } /** -- cgit 1.2.3-korg