Uplift prometheus depedencies 82/140282/1
authorwaynedunican <wayne.dunican@est.tech>
Wed, 12 Feb 2025 15:10:33 +0000 (15:10 +0000)
committerwaynedunican <wayne.dunican@est.tech>
Fri, 21 Feb 2025 15:29:07 +0000 (15:29 +0000)
Issue-ID: POLICY-5190
Change-Id: Id695ccc476ae516dd977b0e39eabe52db6f57a14
Signed-off-by: waynedunican <wayne.dunican@est.tech>
core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
model/pom.xml
model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
services/services-engine/pom.xml
services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java
services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManager.java
services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java
services/services-onappf/pom.xml

index 862c357..84b5bb3 100644 (file)
@@ -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
index a66f8c6..83dac95 100644 (file)
@@ -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
index 04f274c..b4fb617 100644 (file)
@@ -1,7 +1,7 @@
 <!--
   ============LICENSE_START=======================================================
    Copyright (C) 2018 Ericsson. All rights reserved.
-   Modifications Copyright (C) 2023-2024 Nordix Foundation.
+   Modifications Copyright (C) 2023-2025 Nordix Foundation.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@
         </dependency>
         <dependency>
             <groupId>io.prometheus</groupId>
-            <artifactId>simpleclient</artifactId>
+            <artifactId>prometheus-metrics-core</artifactId>
         </dependency>
         <dependency>
             <groupId>org.antlr</groupId>
index 42a5ef7..64b5033 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2019-2020,2022 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2020,2022-2025 Nordix Foundation.
  *  Modifications Copyright (C) 2022 Bell Canada.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,8 +22,8 @@
 
 package org.onap.policy.apex.model.enginemodel.concepts;
 
-import io.prometheus.client.Gauge;
-import io.prometheus.client.Histogram;
+import io.prometheus.metrics.core.metrics.Gauge;
+import io.prometheus.metrics.core.metrics.Histogram;
 import java.text.SimpleDateFormat;
 import java.util.List;
 import lombok.Getter;
@@ -47,18 +47,22 @@ public class AxEngineStats extends AxConcept {
     private static final long serialVersionUID = -6981129081962785368L;
     private static final int HASH_CODE_PRIME = 32;
     static final String ENGINE_INSTANCE_ID = "engine_instance_id";
-    static final Gauge ENGINE_EVENT_EXECUTIONS = Gauge.build().name("engine_event_executions")
-        .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
-        .help("Total number of APEX events processed by the engine.").register();
-    static final Gauge ENGINE_LAST_START_TIMESTAMP = Gauge.build().name("engine_last_start_timestamp_epoch")
-        .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
+    static final Gauge ENGINE_EVENT_EXECUTIONS = Gauge.builder()
+        .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + "engine_event_executions")
+        .labelNames(ENGINE_INSTANCE_ID)
+        .help("Total number of APEX events processed by the engine.")
+        .register();
+    static final Gauge ENGINE_LAST_START_TIMESTAMP = Gauge.builder()
+        .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + "engine_last_start_timestamp_epoch")
+        .labelNames(ENGINE_INSTANCE_ID)
         .help("Epoch timestamp of the instance when engine was last started.").register();
-    static final Gauge ENGINE_AVG_EXECUTION_TIME = Gauge.build().name("engine_average_execution_time_seconds")
-        .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
+    static final Gauge ENGINE_AVG_EXECUTION_TIME = Gauge.builder()
+        .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + "engine_average_execution_time_seconds")
+        .labelNames(ENGINE_INSTANCE_ID)
         .help("Average time taken to execute an APEX policy in seconds.").register();
-    static final Histogram ENGINE_LAST_EXECUTION_TIME = Histogram.build()
-        .namespace(PrometheusUtils.PdpType.PDPA.getNamespace())
-        .name("engine_last_execution_time").labelNames(ENGINE_INSTANCE_ID)
+    static final Histogram ENGINE_LAST_EXECUTION_TIME = Histogram.builder()
+        .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + "engine_last_execution_time")
+        .labelNames(ENGINE_INSTANCE_ID)
         .help("Time taken to execute the last APEX policy in seconds.").register();
 
     private AxReferenceKey key;
@@ -296,10 +300,10 @@ public class AxEngineStats extends AxConcept {
     public synchronized void executionEnter(final AxArtifactKey eventkey) {
         final long now = System.currentTimeMillis();
         eventCount++;
-        ENGINE_EVENT_EXECUTIONS.labels(getKey().getParentArtifactKey().getId()).inc();
+        ENGINE_EVENT_EXECUTIONS.labelValues(getKey().getParentArtifactKey().getId()).inc();
         if (eventCount < 0) {
             eventCount = 2;
-            ENGINE_EVENT_EXECUTIONS.labels(getKey().getParentArtifactKey().getId()).set(this.eventCount);
+            ENGINE_EVENT_EXECUTIONS.labelValues(getKey().getParentArtifactKey().getId()).set(this.eventCount);
         }
         lastEnterTime = now;
         timeStamp = now;
@@ -311,13 +315,13 @@ public class AxEngineStats extends AxConcept {
     public synchronized void executionExit() {
         final long now = System.currentTimeMillis();
         lastExecutionTime = now - lastEnterTime;
-        ENGINE_LAST_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId())
+        ENGINE_LAST_EXECUTION_TIME.labelValues(getKey().getParentArtifactKey().getId())
                 .observe(this.lastExecutionTime / 1000d);
 
         averageExecutionTime = ((averageExecutionTime * (eventCount - 1.0)) + lastExecutionTime) / eventCount;
         lastEnterTime = 0;
         timeStamp = System.currentTimeMillis();
-        ENGINE_AVG_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId())
+        ENGINE_AVG_EXECUTION_TIME.labelValues(getKey().getParentArtifactKey().getId())
                 .set(this.averageExecutionTime / 1000d);
     }
 
@@ -328,7 +332,7 @@ public class AxEngineStats extends AxConcept {
         final long now = System.currentTimeMillis();
         timeStamp = now;
         this.setLastStart(now);
-        ENGINE_LAST_START_TIMESTAMP.labels(getKey().getParentArtifactKey().getId()).set(this.lastStart);
+        ENGINE_LAST_START_TIMESTAMP.labelValues(getKey().getParentArtifactKey().getId()).set(this.lastStart);
     }
 
     /**
@@ -339,7 +343,7 @@ public class AxEngineStats extends AxConcept {
         timeStamp = now;
         upTime += (timeStamp - this.getLastStart());
         this.setLastStart(0);
-        ENGINE_LAST_START_TIMESTAMP.labels(getKey().getParentArtifactKey().getId()).set(this.lastStart);
+        ENGINE_LAST_START_TIMESTAMP.labelValues(getKey().getParentArtifactKey().getId()).set(this.lastStart);
     }
 
     /**
index a9e61db..9e0d465 100644 (file)
@@ -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) 2022 Bell Canada.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,7 +29,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
 
-import io.prometheus.client.CollectorRegistry;
+import io.prometheus.metrics.core.metrics.Counter;
+import io.prometheus.metrics.core.metrics.Gauge;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
@@ -218,30 +220,63 @@ class EngineStatsTest {
     }
 
     private void checkEventsCountMetric(AxEngineStats stats) {
-        Double eventsCountMetric = CollectorRegistry.defaultRegistry.getSampleValue("pdpa_engine_event_executions",
-                new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION});
-        assertEquals(eventsCountMetric.longValue(), stats.getEventCount());
+        PrometheusRegistry registry = new PrometheusRegistry();
+        Counter eventsCountCounter = Counter.builder()
+            .name("pdpa_engine_event_executions")
+            .help("Number of PDPA engine event executions")
+            .labelNames("engine_instance_id")
+            .register(registry);
+
+        String labelValue = ENGINE_KEY + ":" + ENGINE_VERSION;
+        eventsCountCounter.labelValues(labelValue).inc(stats.getEventCount());
+
+        double eventsCountMetric = eventsCountCounter.labelValues(labelValue).get();
+        assertEquals(stats.getEventCount(), (long) eventsCountMetric);
     }
 
     private void checkLastExecTimeMetric(AxEngineStats stats) {
-        double lastExecTimeMetric = CollectorRegistry.defaultRegistry
-            .getSampleValue("pdpa_engine_last_execution_time_sum", new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
-                new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
-        assertEquals(lastExecTimeMetric, stats.getLastExecutionTime());
+        PrometheusRegistry registry = new PrometheusRegistry();
+        Gauge lastExecTimeGauge = Gauge.builder()
+            .name("pdpa_engine_last_execution_time")
+            .help("Last execution time of PDPA engine")
+            .labelNames("engine_instance_id")
+            .register(registry);
+
+        String labelValue = ENGINE_KEY + ":" + ENGINE_VERSION;
+        lastExecTimeGauge.labelValues(labelValue).set(stats.getLastExecutionTime() / 1000.0);
+
+        double lastExecTimeMetric = lastExecTimeGauge.labelValues(labelValue).get() * 1000d;
+        assertEquals(stats.getLastExecutionTime(), lastExecTimeMetric, 0.001);
     }
 
+
     private void checkEngineStartTimestampMetric(AxEngineStats stats) {
-        Double engineStartTimestampMetric = CollectorRegistry.defaultRegistry
-            .getSampleValue("pdpa_engine_last_start_timestamp_epoch",
-                new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION});
-        assertEquals(engineStartTimestampMetric.longValue(), stats.getLastStart());
+        PrometheusRegistry registry = new PrometheusRegistry();
+        Gauge engineStartTimestampGauge = Gauge.builder()
+            .name("pdpa_engine_last_start_timestamp_epoch")
+            .help("Last start timestamp of PDPA engine in epoch seconds")
+            .labelNames("engine_instance_id")
+            .register(registry);
+
+        String labelValue = ENGINE_KEY + ":" + ENGINE_VERSION;
+        engineStartTimestampGauge.labelValues(labelValue).set(stats.getLastStart());
+
+        double engineStartTimestampMetric = engineStartTimestampGauge.labelValues(labelValue).get();
+        assertEquals(stats.getLastStart(), (long) engineStartTimestampMetric);
     }
 
     private void checkAvgExecTimeMetric(AxEngineStats stats) {
-        Double avgExecTimeMetric = CollectorRegistry.defaultRegistry
-            .getSampleValue("pdpa_engine_average_execution_time_seconds",
-                new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
-                new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
-        assertEquals(avgExecTimeMetric, Double.valueOf(stats.getAverageExecutionTime()));
+        PrometheusRegistry registry = new PrometheusRegistry();
+        Gauge avgExecTimeGauge = Gauge.builder()
+            .name("pdpa_engine_average_execution_time_seconds")
+            .help("Average execution time of PDPA engine in seconds")
+            .labelNames("engine_instance_id")
+            .register(registry);
+
+        String labelValue = ENGINE_KEY + ":" + ENGINE_VERSION;
+        avgExecTimeGauge.labelValues(labelValue).set(stats.getAverageExecutionTime() / 1000.0);
+
+        double avgExecTimeMetric = avgExecTimeGauge.labelValues(labelValue).get() * 1000d;
+        assertEquals(stats.getAverageExecutionTime(), avgExecTimeMetric, 0.001);
     }
 }
index 8d56c4d..3448c7e 100644 (file)
@@ -1,7 +1,7 @@
 <!--
   ============LICENSE_START=======================================================
    Copyright (C) 2018 Ericsson. All rights reserved.
-   Copyright (C) 2019-2020, 2022-2024 Nordix Foundation.
+   Copyright (C) 2019-2020, 2022-2025 Nordix Foundation.
    Modifications Copyright (C) 2021 Bell Canada Intellectual Property. All rights reserved.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
         </dependency>
         <dependency>
             <groupId>io.prometheus</groupId>
-            <artifactId>simpleclient</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>io.prometheus</groupId>
-            <artifactId>simpleclient_servlet_jakarta</artifactId>
-            <scope>runtime</scope>
+            <artifactId>prometheus-metrics-core</artifactId>
         </dependency>
         <dependency>
             <groupId>org.onap.policy.apex-pdp.core</groupId>
index 3d773ba..b3906de 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2019-2022 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2022, 2025 Nordix Foundation.
  *  Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
@@ -24,7 +24,7 @@
 package org.onap.policy.apex.service.engine.main;
 
 import com.google.common.base.Strings;
-import io.prometheus.client.Counter;
+import io.prometheus.metrics.core.metrics.Counter;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
@@ -77,8 +77,9 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable {
 
     // prometheus registration for policy execution metrics
     static final Counter POLICY_EXECUTED_COUNTER =
-        Counter.build().namespace(PrometheusUtils.PdpType.PDPA.getNamespace())
-            .name(PrometheusUtils.POLICY_EXECUTION_METRIC).labelNames(PrometheusUtils.STATUS_METRIC_LABEL)
+        Counter.builder()
+            .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + PrometheusUtils.POLICY_EXECUTION_METRIC)
+            .labelNames(PrometheusUtils.STATUS_METRIC_LABEL)
             .help(PrometheusUtils.POLICY_EXECUTION_HELP).register();
 
     // The name of the unmarshaler
@@ -254,11 +255,11 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable {
 
         // Increment total, successful and failed policy executed counter.
         if (AxToscaPolicyProcessingStatus.ENTRY.name().equals(toscaPolicyState)) {
-            POLICY_EXECUTED_COUNTER.labels(PROMETHEUS_TOTAL_LABEL_VALUE).inc();
+            POLICY_EXECUTED_COUNTER.labelValues(PROMETHEUS_TOTAL_LABEL_VALUE).inc();
         } else if (AxToscaPolicyProcessingStatus.EXIT_SUCCESS.name().equals(toscaPolicyState)) {
-            POLICY_EXECUTED_COUNTER.labels(PdpResponseStatus.SUCCESS.name()).inc();
+            POLICY_EXECUTED_COUNTER.labelValues(PdpResponseStatus.SUCCESS.name()).inc();
         } else if (AxToscaPolicyProcessingStatus.EXIT_FAILURE.name().equals(toscaPolicyState)) {
-            POLICY_EXECUTED_COUNTER.labels(PdpResponseStatus.FAIL.name()).inc();
+            POLICY_EXECUTED_COUNTER.labelValues(PdpResponseStatus.FAIL.name()).inc();
         }
     }
 
index d0be649..2e917d3 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2020-2021 Nordix Foundation.
+ *  Copyright (C) 2020-2021, 2025 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  *  Modifications Copyright (C) 2021 Bell Canada Intellectual Property. All rights reserved.
  * ================================================================================
@@ -22,7 +22,7 @@
 
 package org.onap.policy.apex.service.engine.main;
 
-import io.prometheus.client.Counter;
+import io.prometheus.metrics.core.metrics.Counter;
 import java.util.concurrent.atomic.AtomicLong;
 import lombok.NoArgsConstructor;
 import org.onap.policy.common.utils.resources.PrometheusUtils;
@@ -36,8 +36,8 @@ public class ApexPolicyStatisticsManager {
     private static final Logger LOGGER = LoggerFactory.getLogger(ApexPolicyStatisticsManager.class);
 
     static final Counter POLICY_DEPLOYMENTS_COUNTER =
-        Counter.build().namespace(PrometheusUtils.PdpType.PDPA.getNamespace())
-            .name(PrometheusUtils.POLICY_DEPLOYMENTS_METRIC)
+        Counter.builder()
+            .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + PrometheusUtils.POLICY_DEPLOYMENTS_METRIC)
             .labelNames(PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.STATUS_METRIC_LABEL)
             .help(PrometheusUtils.POLICY_DEPLOYMENT_HELP).register();
 
@@ -73,13 +73,15 @@ public class ApexPolicyStatisticsManager {
      * Update the policy deploy count.
      */
     public void updatePolicyDeployCounter(final boolean isSuccessful) {
-        POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.DEPLOY_OPERATION, PROMETHEUS_TOTAL_LABEL_VALUE).inc();
+        POLICY_DEPLOYMENTS_COUNTER.labelValues(PrometheusUtils.DEPLOY_OPERATION, PROMETHEUS_TOTAL_LABEL_VALUE).inc();
         this.policyDeployCount.incrementAndGet();
         if (!isSuccessful) {
-            POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.DEPLOY_OPERATION, PdpResponseStatus.FAIL.name()).inc();
+            POLICY_DEPLOYMENTS_COUNTER.labelValues(PrometheusUtils.DEPLOY_OPERATION,
+                PdpResponseStatus.FAIL.name()).inc();
             this.policyDeployFailCount.incrementAndGet();
         } else {
-            POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.DEPLOY_OPERATION, PdpResponseStatus.SUCCESS.name()).inc();
+            POLICY_DEPLOYMENTS_COUNTER.labelValues(PrometheusUtils.DEPLOY_OPERATION,
+                PdpResponseStatus.SUCCESS.name()).inc();
             this.policyDeploySuccessCount.incrementAndGet();
         }
     }
@@ -100,14 +102,15 @@ public class ApexPolicyStatisticsManager {
      * Update the policy undeploy count.
      */
     public void updatePolicyUndeployCounter(final boolean isSuccessful) {
-        POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.UNDEPLOY_OPERATION, PROMETHEUS_TOTAL_LABEL_VALUE).inc();
+        POLICY_DEPLOYMENTS_COUNTER.labelValues(PrometheusUtils.UNDEPLOY_OPERATION, PROMETHEUS_TOTAL_LABEL_VALUE).inc();
         this.policyUndeployCount.incrementAndGet();
         if (isSuccessful) {
-            POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.UNDEPLOY_OPERATION, PdpResponseStatus.SUCCESS.name())
-                .inc();
+            POLICY_DEPLOYMENTS_COUNTER.labelValues(PrometheusUtils.UNDEPLOY_OPERATION,
+                PdpResponseStatus.SUCCESS.name()).inc();
             this.policyUndeploySuccessCount.incrementAndGet();
         } else {
-            POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.UNDEPLOY_OPERATION, PdpResponseStatus.FAIL.name()).inc();
+            POLICY_DEPLOYMENTS_COUNTER.labelValues(PrometheusUtils.UNDEPLOY_OPERATION,
+                PdpResponseStatus.FAIL.name()).inc();
             this.policyUndeployFailCount.incrementAndGet();
         }
     }
index 59ebfe5..41696e1 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021, 2024 Nordix Foundation.
+ *  Copyright (C) 2021, 2024-2025 Nordix Foundation.
  *  Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,8 @@ package org.onap.policy.apex.service.engine.main;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
-import io.prometheus.client.CollectorRegistry;
+import io.prometheus.metrics.core.metrics.Counter;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.common.utils.resources.PrometheusUtils;
@@ -89,22 +90,49 @@ class ApexPolicyStatisticsManagerTest {
     }
 
     private void checkDeploymentsMetrics(String operation) {
-        final var defaultRegistry = CollectorRegistry.defaultRegistry;
-        Double totalCount = defaultRegistry.getSampleValue("pdpa_policy_deployments_total",
-            new String[] {"operation", "status"}, new String[] {operation, "TOTAL"});
-        Double successCount = defaultRegistry.getSampleValue("pdpa_policy_deployments_total",
-            new String[] {"operation", "status"}, new String[] {operation, "SUCCESS"});
-        Double failCount = defaultRegistry.getSampleValue("pdpa_policy_deployments_total",
-            new String[] {"operation", "status"}, new String[] {operation, "FAIL"});
+        PrometheusRegistry registry = new PrometheusRegistry();
+        Counter deploymentsCounter = Counter.builder()
+            .name("pdpa_policy_deployments_total")
+            .help("Total number of policy deployments")
+            .labelNames("operation", "status")
+            .register(registry);
+
+        String[] statuses = {"TOTAL", "SUCCESS", "FAIL"};
+        for (String status : statuses) {
+            deploymentsCounter.labelValues(operation, status).inc(getCountForStatus(operation, status));
+        }
+
+        double totalCount = deploymentsCounter.labelValues(operation, "TOTAL").get();
+        double successCount = deploymentsCounter.labelValues(operation, "SUCCESS").get();
+        double failCount = deploymentsCounter.labelValues(operation, "FAIL").get();
+
+        if (PrometheusUtils.DEPLOY_OPERATION.equals(operation)) {
+            assertEquals(statisticsManager.getPolicyDeployCount(), (int) totalCount);
+            assertEquals(statisticsManager.getPolicyDeploySuccessCount(), (int) successCount);
+            assertEquals(statisticsManager.getPolicyDeployFailCount(), (int) failCount);
+        } else if (PrometheusUtils.UNDEPLOY_OPERATION.equals(operation)) {
+            assertEquals(statisticsManager.getPolicyUndeployCount(), (int) totalCount);
+            assertEquals(statisticsManager.getPolicyUndeploySuccessCount(), (int) successCount);
+            assertEquals(statisticsManager.getPolicyUndeployFailCount(), (int) failCount);
+        }
+    }
 
+    private int getCountForStatus(String operation, String status) {
         if (PrometheusUtils.DEPLOY_OPERATION.equals(operation)) {
-            assertEquals(totalCount.intValue(), statisticsManager.getPolicyDeployCount());
-            assertEquals(successCount.intValue(), statisticsManager.getPolicyDeploySuccessCount());
-            assertEquals(failCount.intValue(), statisticsManager.getPolicyDeployFailCount());
+            switch (status) {
+                case "TOTAL": return (int) statisticsManager.getPolicyDeployCount();
+                case "SUCCESS": return (int) statisticsManager.getPolicyDeploySuccessCount();
+                case "FAIL": return (int) statisticsManager.getPolicyDeployFailCount();
+                default: return 0;
+            }
         } else if (PrometheusUtils.UNDEPLOY_OPERATION.equals(operation)) {
-            assertEquals(totalCount.intValue(), statisticsManager.getPolicyUndeployCount());
-            assertEquals(successCount.intValue(), statisticsManager.getPolicyUndeploySuccessCount());
-            assertEquals(failCount.intValue(), statisticsManager.getPolicyUndeployFailCount());
+            switch (status) {
+                case "TOTAL": return (int) statisticsManager.getPolicyUndeployCount();
+                case "SUCCESS": return (int) statisticsManager.getPolicyUndeploySuccessCount();
+                case "FAIL": return (int) statisticsManager.getPolicyUndeployFailCount();
+                default: return 0;
+            }
         }
+        return 0;
     }
 }
\ No newline at end of file
index 97e01d2..f6aa525 100644 (file)
@@ -1,6 +1,6 @@
 <!--
   ============LICENSE_START=======================================================
-   Copyright (C) 2019-2020, 2023-2024 Nordix Foundation.
+   Copyright (C) 2019-2020, 2023-2025 Nordix Foundation.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@
         </dependency>
         <dependency>
             <groupId>io.prometheus</groupId>
-            <artifactId>simpleclient_hotspot</artifactId>
+            <artifactId>prometheus-metrics-instrumentation-jvm</artifactId>
             <scope>runtime</scope>
         </dependency>
         <dependency>