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 --- .../etc/ElementParticipantParameters.yaml | 6 +++ .../resources/etc/HttpParticipantParameters.yaml | 8 ++++ .../etc/KubernetesParticipantParameters.yaml | 10 ++++- .../resources/etc/PolicyParticipantParameters.yaml | 7 ++++ .../participant/http/config/MicrometerConfig.java | 46 ++++++++++++++++++++++ .../src/main/resources/config/application.yaml | 12 +++++- .../http/utils/CommonActuatorController.java | 7 ++-- .../configurations/MicrometerConfig.java | 46 ++++++++++++++++++++++ .../src/main/resources/config/application.yaml | 10 ++++- .../kubernetes/rest/ChartControllerTest.java | 4 ++ .../kubernetes/utils/CommonActuatorController.java | 7 ++-- .../policy/config/MicrometerConfig.java | 46 ++++++++++++++++++++++ .../src/main/resources/config/application.yaml | 7 ++++ .../main/utils/CommonActuatorController.java | 7 ++-- .../comm/ParticipantMessagePublisher.java | 38 +++++++++--------- .../intermediary/handler/ParticipantHandler.java | 13 ++++++ 16 files changed, 240 insertions(+), 34 deletions(-) create mode 100644 participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/config/MicrometerConfig.java create mode 100644 participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/configurations/MicrometerConfig.java create mode 100644 participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/config/MicrometerConfig.java diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/ElementParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/ElementParticipantParameters.yaml index 4d7710304..ee13c4cc5 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/ElementParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/ElementParticipantParameters.yaml @@ -3,6 +3,12 @@ spring: user: name: ${REST_USER:acmUser} password: ${REST_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 server: port: ${PORT:8084} diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml index 529b095a1..41c9f99be 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml @@ -3,6 +3,13 @@ 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 + security: enable-csrf: false participant: @@ -32,6 +39,7 @@ participant: management: endpoints: web: + base-path: / exposure: include: health, metrics, prometheus server: diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml index ad1669c66..06a1b7c08 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml @@ -3,6 +3,13 @@ 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 + security: enable-csrf: false @@ -38,6 +45,7 @@ participant: management: endpoints: web: + base-path: / exposure: include: health, metrics, prometheus server: @@ -72,4 +80,4 @@ helm: protocols: - http - - https \ No newline at end of file + - https diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml index 1cb4e6dc7..9cd06ad26 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.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 @@ -51,6 +57,7 @@ participant: management: endpoints: web: + base-path: / exposure: include: health, metrics, prometheus server: diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/config/MicrometerConfig.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/config/MicrometerConfig.java new file mode 100644 index 000000000..06cecc6f5 --- /dev/null +++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/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.http.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-http/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml index 8a3d0fbf2..44cdf95a6 100644 --- a/participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml +++ b/participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml @@ -3,6 +3,13 @@ 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 + security: enable-csrf: false participant: @@ -19,17 +26,18 @@ participant: topicSources: - topic: POLICY-ACRUNTIME-PARTICIPANT servers: - - ${topicServer:message-router} + - ${topicServer:localhost} topicCommInfrastructure: dmaap fetchTimeout: 15000 topicSinks: - topic: POLICY-ACRUNTIME-PARTICIPANT servers: - - ${topicServer:message-router} + - ${topicServer:localhost} topicCommInfrastructure: dmaap management: endpoints: web: + base-path: / exposure: include: health, metrics, prometheus server: diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java index fad467f63..d6f558d61 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/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/httpparticipant"; - public static final String ACTUATOR_ENDPOINT = CONTEXT_PATH + "/actuator/"; + public static final String CONTEXT_PATH = "onap/policy/clamp/acm/httpparticipant/"; 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); } /** diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/configurations/MicrometerConfig.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/configurations/MicrometerConfig.java new file mode 100644 index 000000000..0532dc97d --- /dev/null +++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/configurations/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.kubernetes.configurations; + +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-kubernetes/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml index 0f8c49547..0158c2c63 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml +++ b/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml @@ -3,6 +3,13 @@ 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 + security: enable-csrf: false @@ -36,6 +43,7 @@ participant: management: endpoints: web: + base-path: / exposure: include: health, metrics, prometheus server: @@ -70,4 +78,4 @@ helm: protocols: - http - - https \ No newline at end of file + - https diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/rest/ChartControllerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/rest/ChartControllerTest.java index c57684fd7..e1cf3cf08 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/rest/ChartControllerTest.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/rest/ChartControllerTest.java @@ -49,9 +49,12 @@ import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -64,6 +67,7 @@ import org.springframework.web.context.WebApplicationContext; @ExtendWith(SpringExtension.class) @WebMvcTest(value = ChartController.class, properties = "chart.api.enabled=true") +@Import({MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class}) @EnableConfigurationProperties(value = ParticipantK8sParameters.class) class ChartControllerTest { diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java index 8b716a5fd..23f591f0f 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/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/k8sparticipant"; - public static final String ACTUATOR_ENDPOINT = CONTEXT_PATH + "/actuator/"; + public static final String CONTEXT_PATH = "onap/policy/clamp/acm/k8sparticipant/"; 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); } /** 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); } /** diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java index 67814a4e6..11f277885 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,6 +21,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.comm; +import io.micrometer.core.annotation.Timed; import java.util.List; import javax.ws.rs.core.Response.Status; import org.onap.policy.clamp.acm.participant.intermediary.handler.Publisher; @@ -67,10 +68,9 @@ public class ParticipantMessagePublisher implements Publisher { * * @param participantStatus the Participant Status */ + @Timed(value = "publisher.participant_status", description = "PARTICIPANT_STATUS messages published") public void sendParticipantStatus(final ParticipantStatus participantStatus) { - if (!active) { - throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT); - } + validate(); topicSinkClient.send(participantStatus); LOGGER.debug("Sent Participant Status message to CLAMP - {}", participantStatus); } @@ -80,10 +80,9 @@ public class ParticipantMessagePublisher implements Publisher { * * @param participantRegister the Participant Status */ + @Timed(value = "publisher.participant_register", description = "PARTICIPANT_REGISTER messages published") public void sendParticipantRegister(final ParticipantRegister participantRegister) { - if (!active) { - throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT); - } + validate(); topicSinkClient.send(participantRegister); LOGGER.debug("Sent Participant Register message to CLAMP - {}", participantRegister); } @@ -93,10 +92,9 @@ public class ParticipantMessagePublisher implements Publisher { * * @param participantDeregister the Participant Status */ + @Timed(value = "publisher.participant_deregister", description = "PARTICIPANT_DEREGISTER messages published") public void sendParticipantDeregister(final ParticipantDeregister participantDeregister) { - if (!active) { - throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT); - } + validate(); topicSinkClient.send(participantDeregister); LOGGER.debug("Sent Participant Deregister message to CLAMP - {}", participantDeregister); } @@ -106,10 +104,9 @@ public class ParticipantMessagePublisher implements Publisher { * * @param participantUpdateAck the Participant Update Ack */ + @Timed(value = "publisher.participant_update_ack", description = "PARTICIPANT_UPDATE_ACK messages published") public void sendParticipantUpdateAck(final ParticipantUpdateAck participantUpdateAck) { - if (!active) { - throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT); - } + validate(); topicSinkClient.send(participantUpdateAck); LOGGER.debug("Sent Participant Update Ack message to CLAMP - {}", participantUpdateAck); } @@ -119,10 +116,10 @@ public class ParticipantMessagePublisher implements Publisher { * * @param automationCompositionAck AutomationComposition Update/StateChange Ack */ + @Timed(value = "publisher.automation_composition_update_ack", + description = "AUTOMATION_COMPOSITION_UPDATE_ACK/AUTOMATION_COMPOSITION_STATECHANGE_ACK messages published") public void sendAutomationCompositionAck(final AutomationCompositionAck automationCompositionAck) { - if (!active) { - throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT); - } + validate(); topicSinkClient.send(automationCompositionAck); LOGGER.debug("Sent AutomationComposition Update/StateChange Ack to runtime - {}", automationCompositionAck); } @@ -132,12 +129,17 @@ public class ParticipantMessagePublisher implements Publisher { * * @param participantStatus the Participant Status */ + @Timed(value = "publisher.participant_status", description = "PARTICIPANT_STATUS messages published") public void sendHeartbeat(final ParticipantStatus participantStatus) { + validate(); + topicSinkClient.send(participantStatus); + LOGGER.debug("Sent Participant heartbeat to CLAMP - {}", participantStatus); + } + + private void validate() { if (!active) { throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT); } - topicSinkClient.send(participantStatus); - LOGGER.debug("Sent Participant heartbeat to CLAMP - {}", participantStatus); } @Override diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java index 3362f10d3..d29186844 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java @@ -22,6 +22,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler; +import io.micrometer.core.annotation.Timed; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -99,6 +100,8 @@ public class ParticipantHandler { * * @param participantStatusReqMsg participant participantStatusReq message */ + @Timed(value = "listener.participant_status_req", + description = "PARTICIPANT_STATUS_REQ messages received") public void handleParticipantStatusReq(final ParticipantStatusReq participantStatusReqMsg) { var participantStatus = makeHeartbeat(true); publisher.sendParticipantStatus(participantStatus); @@ -109,6 +112,8 @@ public class ParticipantHandler { * * @param updateMsg the update message */ + @Timed(value = "listener.automation_composition_update", + description = "AUTOMATION_COMPOSITION_UPDATE messages received") public void handleAutomationCompositionUpdate(AutomationCompositionUpdate updateMsg) { automationCompositionHandler.handleAutomationCompositionUpdate(updateMsg, acElementDefsOnThisParticipant); } @@ -118,6 +123,8 @@ public class ParticipantHandler { * * @param stateChangeMsg the state change message */ + @Timed(value = "listener.automation_composition_state_change", + description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages received") public void handleAutomationCompositionStateChange(AutomationCompositionStateChange stateChangeMsg) { automationCompositionHandler.handleAutomationCompositionStateChange(stateChangeMsg, acElementDefsOnThisParticipant); @@ -223,6 +230,8 @@ public class ParticipantHandler { * * @param participantRegisterAckMsg the participantRegisterAck message */ + @Timed(value = "listener.participant_register_ack", + description = "PARTICIPANT_REGISTER_ACK messages received") public void handleParticipantRegisterAck(ParticipantRegisterAck participantRegisterAckMsg) { LOGGER.debug("ParticipantRegisterAck message received as responseTo {}", participantRegisterAckMsg.getResponseTo()); @@ -257,6 +266,8 @@ public class ParticipantHandler { * * @param participantDeregisterAckMsg the participantDeregisterAck message */ + @Timed(value = "listener.participant_deregister_ack", + description = "PARTICIPANT_DEREGISTER_ACK messages received") public void handleParticipantDeregisterAck(ParticipantDeregisterAck participantDeregisterAckMsg) { LOGGER.debug("ParticipantDeregisterAck message received as responseTo {}", participantDeregisterAckMsg.getResponseTo()); @@ -267,6 +278,8 @@ public class ParticipantHandler { * * @param participantUpdateMsg the ParticipantUpdate message */ + @Timed(value = "listener.participant_update", + description = "PARTICIPANT_UPDATE messages received") public void handleParticipantUpdate(ParticipantUpdate participantUpdateMsg) { LOGGER.debug("ParticipantUpdate message received for participantId {}", participantUpdateMsg.getParticipantId()); -- cgit 1.2.3-korg