aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java11
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java20
-rw-r--r--model/pom.xml4
-rw-r--r--model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java42
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java71
-rw-r--r--services/services-engine/pom.xml9
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java15
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManager.java25
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java58
-rw-r--r--services/services-onappf/pom.xml4
10 files changed, 168 insertions, 91 deletions
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
diff --git a/model/pom.xml b/model/pom.xml
index 04f274ceb..b4fb617a4 100644
--- a/model/pom.xml
+++ b/model/pom.xml
@@ -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>
diff --git a/model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java b/model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
index 42a5ef785..64b503321 100644
--- a/model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
+++ b/model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
@@ -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);
}
/**
diff --git a/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java b/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
index a9e61db62..9e0d465c7 100644
--- a/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
+++ b/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.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) 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);
}
}
diff --git a/services/services-engine/pom.xml b/services/services-engine/pom.xml
index 8d56c4d0b..3448c7eaa 100644
--- a/services/services-engine/pom.xml
+++ b/services/services-engine/pom.xml
@@ -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");
@@ -44,12 +44,7 @@
</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>
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java
index 3d773ba90..b3906de74 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java
@@ -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();
}
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManager.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManager.java
index d0be6492e..2e917d3e3 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManager.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManager.java
@@ -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();
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java
index 59ebfe50d..41696e1ef 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java
@@ -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
diff --git a/services/services-onappf/pom.xml b/services/services-onappf/pom.xml
index 97e01d237..f6aa5259c 100644
--- a/services/services-onappf/pom.xml
+++ b/services/services-onappf/pom.xml
@@ -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>