From 8bd83cf37040eda116b8dc0b8f63955fb0bd6019 Mon Sep 17 00:00:00 2001
From: waynedunican <wayne.dunican@est.tech>
Date: Wed, 12 Feb 2025 15:10:33 +0000
Subject: Uplift prometheus depedencies

Issue-ID: POLICY-5190
Change-Id: Id695ccc476ae516dd977b0e39eabe52db6f57a14
Signed-off-by: waynedunican <wayne.dunican@est.tech>
---
 .../apex/core/engine/engine/impl/ApexEngineImpl.java | 11 ++++++-----
 .../core/engine/engine/impl/ApexEngineImplTest.java  | 20 +++++++++++++++-----
 2 files changed, 21 insertions(+), 10 deletions(-)

(limited to 'core/src')

diff --git a/core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java b/core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
index 862c357be..84b5bb381 100644
--- a/core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
+++ b/core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2020, 2024-2025 Nordix Foundation.
  *  Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
@@ -25,7 +25,7 @@ package org.onap.policy.apex.core.engine.engine.impl;
 
 import static org.onap.policy.common.utils.validation.Assertions.argumentNotNull;
 
-import io.prometheus.client.Gauge;
+import io.prometheus.metrics.core.metrics.Gauge;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -75,8 +75,9 @@ public class ApexEngineImpl implements ApexEngine {
     private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEngineImpl.class);
 
     // Register state changes with prometheus
-    static final Gauge ENGINE_STATE = Gauge.build().namespace(PrometheusUtils.PdpType.PDPA.getNamespace())
-        .name("engine_state").labelNames("engine_instance_id")
+    static final Gauge ENGINE_STATE = Gauge.builder()
+        .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + "engine_state")
+        .labelNames("engine_instance_id")
         .help("State of the APEX engine as integers mapped as - 0:UNDEFINED, 1:STOPPED, 2:READY,"
             + " 3:EXECUTING, 4:STOPPING").register();
 
@@ -527,6 +528,6 @@ public class ApexEngineImpl implements ApexEngine {
      * Update the APEX engine state to prometheus for monitoring.
      */
     private void updateStatePrometheusMetric() {
-        ENGINE_STATE.labels(getKey().getId()).set(state.getStateIdentifier());
+        ENGINE_STATE.labelValues(getKey().getId()).set(state.getStateIdentifier());
     }
 }
\ No newline at end of file
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
index a66f8c683..83dac95b0 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2019-2021, 2023-2024 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2021, 2023-2025 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,7 +30,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import io.prometheus.client.CollectorRegistry;
+import io.prometheus.metrics.core.metrics.Gauge;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.HashMap;
@@ -503,8 +504,17 @@ class ApexEngineImplTest {
     }
 
     private void checkAxEngineStateMetric(AxEngineState state) {
-        Double stateMetric = CollectorRegistry.defaultRegistry
-            .getSampleValue("pdpa_engine_state", new String[] {"engine_instance_id"}, new String[] {ENGINE_ID});
-        assertEquals(stateMetric.intValue(), state.getStateIdentifier());
+        PrometheusRegistry registry = new PrometheusRegistry();
+        Gauge stateGauge = Gauge.builder()
+            .name("pdpa_engine_state")
+            .help("Current state of the PDPA engine")
+            .labelNames("engine_instance_id")
+            .register(registry);
+
+        String labelValue = ENGINE_ID;
+        stateGauge.labelValues(labelValue).set(state.getStateIdentifier());
+
+        double stateMetric = stateGauge.labelValues(labelValue).get();
+        assertEquals(state.getStateIdentifier(), (int) stateMetric);
     }
 }
\ No newline at end of file
-- 
cgit