From 01a680b7867db965dc5467d44a1f5d7746337de0 Mon Sep 17 00:00:00 2001 From: "adheli.tavares" Date: Mon, 11 Aug 2025 16:15:15 +0100 Subject: [PATCH] Using health from spring as readiness indicator - adding a HealthIndicator for custom kafka implementation - enabling k8s probes Issue-ID: POLICY-5443 Change-Id: I6f72bee2468e4d3b48913bf9659bf38bf3f0b918 Signed-off-by: adheli.tavares --- .../resources/etc/A1pmsParticipantParameters.yaml | 7 ++++ .../main/resources/etc/AcRuntimeParameters.yaml | 6 +++ .../etc/ElementParticipantParameters.yaml | 6 +++ .../resources/etc/HttpParticipantParameters.yaml | 7 ++++ .../resources/etc/KserveParticipantParameters.yaml | 7 ++++ .../etc/KubernetesParticipantParameters.yaml | 7 ++++ .../resources/etc/PolicyParticipantParameters.yaml | 7 ++++ .../etc/SimulatorParticipantParameters.yaml | 7 ++++ runtime-acm/pom.xml | 1 - .../config/health/KafkaHealthIndicator.java | 49 ++++++++++++++++++++++ runtime-acm/src/main/resources/application.yaml | 6 +++ .../runtime/main/rest/ActuatorControllerTest.java | 16 ++++++- 12 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/health/KafkaHealthIndicator.java diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/A1pmsParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/A1pmsParticipantParameters.yaml index 01fd439ee..787dc9b94 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/A1pmsParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/A1pmsParticipantParameters.yaml @@ -57,6 +57,13 @@ management: base-path: / exposure: include: health, metrics, prometheus + endpoint: + health: + show-details: always + probes: + enabled: true + show-components: always + server: port: 8086 servlet: diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml index 0c6d942f3..28938c0e6 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml @@ -75,3 +75,9 @@ management: base-path: / exposure: include: health, metrics, prometheus + endpoint: + health: + show-details: always + probes: + enabled: true + show-components: always 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 ee13c4cc5..a97ad9021 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/ElementParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/ElementParticipantParameters.yaml @@ -25,3 +25,9 @@ management: base-path: / exposure: include: health, metrics, prometheus + endpoint: + health: + show-details: always + probes: + enabled: true + show-components: always 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 58105ad71..376ee4255 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml @@ -51,6 +51,13 @@ management: base-path: / exposure: include: health, metrics, prometheus + endpoint: + health: + show-details: always + probes: + enabled: true + show-components: always + server: port: 8084 servlet: diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/KserveParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/KserveParticipantParameters.yaml index 79756b7ca..f4b9aa720 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/KserveParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/KserveParticipantParameters.yaml @@ -61,6 +61,13 @@ management: base-path: / exposure: include: health, metrics, prometheus + endpoint: + health: + show-details: always + probes: + enabled: true + show-components: always + server: port: 8087 servlet: 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 1bab3b7c6..eed8c74ca 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml @@ -57,6 +57,13 @@ management: base-path: / exposure: include: health, metrics, prometheus + endpoint: + health: + show-details: always + probes: + enabled: true + show-components: always + server: port: 8083 servlet: 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 1b85548f0..ea7ccf153 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml @@ -70,6 +70,13 @@ management: base-path: / exposure: include: health, metrics, prometheus + endpoint: + health: + show-details: always + probes: + enabled: true + show-components: always + server: port: 8085 servlet: diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/SimulatorParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/SimulatorParticipantParameters.yaml index fd8efaece..69f2d473b 100644 --- a/packages/policy-clamp-tarball/src/main/resources/etc/SimulatorParticipantParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/SimulatorParticipantParameters.yaml @@ -52,6 +52,13 @@ management: base-path: / exposure: include: health, metrics, prometheus + endpoint: + health: + show-details: always + probes: + enabled: true + show-components: always + server: port: 8087 servlet: diff --git a/runtime-acm/pom.xml b/runtime-acm/pom.xml index a3faee7f2..de21a0916 100644 --- a/runtime-acm/pom.xml +++ b/runtime-acm/pom.xml @@ -223,7 +223,6 @@ org.springframework.boot spring-boot-starter-actuator - runtime org.springframework.boot diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/health/KafkaHealthIndicator.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/health/KafkaHealthIndicator.java new file mode 100644 index 000000000..baeac5671 --- /dev/null +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/health/KafkaHealthIndicator.java @@ -0,0 +1,49 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2025 OpenInfra Foundation Europe. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.acm.runtime.config.health; + +import org.onap.policy.common.message.bus.event.TopicEndpoint; +import org.onap.policy.common.message.bus.event.TopicEndpointManager; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.stereotype.Component; + +@Component +public class KafkaHealthIndicator implements HealthIndicator { + + private final TopicEndpoint topicEndpoint = TopicEndpointManager.getManager(); + + @Override + public Health getHealth(boolean includeDetails) { + return HealthIndicator.super.getHealth(includeDetails); + } + + @Override + public Health health() { + var healthBuilder = new Health.Builder(); + if (topicEndpoint.isAlive()) { + healthBuilder.withDetail("topicEndpoint", topicEndpoint); + healthBuilder.up(); + } else { + healthBuilder.down(); + } + return healthBuilder.build(); + } +} diff --git a/runtime-acm/src/main/resources/application.yaml b/runtime-acm/src/main/resources/application.yaml index 1edf36e11..84d805df7 100644 --- a/runtime-acm/src/main/resources/application.yaml +++ b/runtime-acm/src/main/resources/application.yaml @@ -71,3 +71,9 @@ management: base-path: / exposure: include: health, metrics, prometheus + endpoint: + health: + show-details: always + probes: + enabled: true + show-components: always diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java index 4b3e8ed7a..ce3d8dc80 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2025 Nordix Foundation. + * Copyright (C) 2021-2025 OpenInfra Foundation Europe. 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. @@ -25,6 +25,8 @@ import static org.springframework.http.MediaType.TEXT_PLAIN; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.onap.policy.common.message.bus.event.TopicEndpoint; +import org.onap.policy.common.message.bus.event.TopicEndpointManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; @@ -58,7 +60,17 @@ class ActuatorControllerTest { @Test void testGetHealth() { webClient.get().uri("/health").accept(APPLICATION_JSON) - .exchange().expectStatus().isOk(); + .exchange().expectStatus().isOk() + .expectBody().jsonPath("$.status.code").isEqualTo("UP"); + + TopicEndpoint topicEndpoint = TopicEndpointManager.getManager(); + topicEndpoint.stop(); + + webClient.get().uri("/health").accept(APPLICATION_JSON) + .exchange().expectStatus().is5xxServerError() + .expectBody().jsonPath("$.status.code").isEqualTo("DOWN"); + + topicEndpoint.start(); } @Test -- 2.16.6