Using health from spring as readiness indicator 77/141677/3 master
authoradheli.tavares <adheli.tavares@est.tech>
Mon, 11 Aug 2025 15:15:15 +0000 (16:15 +0100)
committeradheli.tavares <adheli.tavares@est.tech>
Tue, 12 Aug 2025 08:49:12 +0000 (09:49 +0100)
- adding a HealthIndicator for custom kafka implementation
- enabling k8s probes

Issue-ID: POLICY-5443
Change-Id: I6f72bee2468e4d3b48913bf9659bf38bf3f0b918
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
12 files changed:
packages/policy-clamp-tarball/src/main/resources/etc/A1pmsParticipantParameters.yaml
packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml
packages/policy-clamp-tarball/src/main/resources/etc/ElementParticipantParameters.yaml
packages/policy-clamp-tarball/src/main/resources/etc/HttpParticipantParameters.yaml
packages/policy-clamp-tarball/src/main/resources/etc/KserveParticipantParameters.yaml
packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml
packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml
packages/policy-clamp-tarball/src/main/resources/etc/SimulatorParticipantParameters.yaml
runtime-acm/pom.xml
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/health/KafkaHealthIndicator.java [new file with mode: 0644]
runtime-acm/src/main/resources/application.yaml
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java

index 01fd439..787dc9b 100644 (file)
@@ -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:
index 0c6d942..28938c0 100644 (file)
@@ -75,3 +75,9 @@ management:
       base-path: /
       exposure:
         include: health, metrics, prometheus
+  endpoint:
+    health:
+      show-details: always
+      probes:
+        enabled: true
+      show-components: always
index ee13c4c..a97ad90 100644 (file)
@@ -25,3 +25,9 @@ management:
       base-path: /
       exposure:
         include: health, metrics, prometheus
+  endpoint:
+    health:
+      show-details: always
+      probes:
+        enabled: true
+      show-components: always
index 58105ad..376ee42 100644 (file)
@@ -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:
index 79756b7..f4b9aa7 100644 (file)
@@ -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:
index 1bab3b7..eed8c74 100644 (file)
@@ -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:
index 1b85548..ea7ccf1 100644 (file)
@@ -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:
index fd8efae..69f2d47 100644 (file)
@@ -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:
index a3faee7..de21a09 100644 (file)
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
-            <scope>runtime</scope>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
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 (file)
index 0000000..baeac56
--- /dev/null
@@ -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();
+    }
+}
index 1edf36e..84d805d 100644 (file)
@@ -71,3 +71,9 @@ management:
       base-path: /
       exposure:
         include: health, metrics, prometheus
+  endpoint:
+    health:
+      show-details: always
+      probes:
+        enabled: true
+      show-components: always
index 4b3e8ed..ce3d8dc 100644 (file)
@@ -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