Uplift prometheus dependencies 78/140278/2
authorwaynedunican <wayne.dunican@est.tech>
Wed, 12 Feb 2025 15:11:24 +0000 (15:11 +0000)
committerwaynedunican <wayne.dunican@est.tech>
Tue, 25 Feb 2025 08:36:35 +0000 (08:36 +0000)
Issue-ID: POLICY-5190
Change-Id: I9369340c9270d594d93f5fff2931dc10cbacb95f
Signed-off-by: waynedunican <wayne.dunican@est.tech>
feature-lifecycle/pom.xml
feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
policy-management/pom.xml
policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java

index 3f9da72..13c4ef6 100644 (file)
@@ -3,7 +3,7 @@
   ONAP
   ================================================================================
   Copyright (C) 2019-2021 AT&T Intellectual Property. 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.
@@ -16,6 +16,8 @@
   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=========================================================
   -->
 
         </dependency>
         <dependency>
             <groupId>io.prometheus</groupId>
-            <artifactId>simpleclient_hotspot</artifactId>
+            <artifactId>prometheus-metrics-instrumentation-jvm</artifactId>
         </dependency>
     </dependencies>
 
index 6e33490..24bd4cc 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021, 2023-2024 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 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.
  * 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.drools.lifecycle;
 
 import com.google.re2j.Pattern;
-import io.prometheus.client.Counter;
+import io.prometheus.metrics.core.metrics.Counter;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -102,7 +104,8 @@ public class LifecycleFsm implements Startable {
     protected static final String PROMETHEUS_NAMESPACE = "pdpd";
 
     protected static final Counter deploymentsCounter =
-            Counter.build().namespace(PROMETHEUS_NAMESPACE).name(PrometheusUtils.POLICY_DEPLOYMENTS_METRIC)
+            Counter.builder()
+                    .name(PROMETHEUS_NAMESPACE + "_" + PrometheusUtils.POLICY_DEPLOYMENTS_METRIC)
                     .labelNames(PrometheusUtils.STATE_METRIC_LABEL,
                             PrometheusUtils.OPERATION_METRIC_LABEL,
                             PrometheusUtils.STATUS_METRIC_LABEL)
@@ -448,7 +451,7 @@ public class LifecycleFsm implements Startable {
         policiesMap.computeIfAbsent(policy.getIdentifier(), key -> {
             // avoid counting reapplies in a second pass when a mix of native and non-native
             // policies are present.
-            deploymentsCounter.labels(state.state().name(),
+            deploymentsCounter.labelValues(state.state().name(),
                     PrometheusUtils.DEPLOY_OPERATION,
                     PdpResponseStatus.SUCCESS.name()).inc();
             return policy;
@@ -459,7 +462,7 @@ public class LifecycleFsm implements Startable {
         policiesMap.computeIfPresent(policy.getIdentifier(), (key, value) -> {
             // avoid counting reapplies in a second pass when a mix of native and non-native
             // policies are present.
-            deploymentsCounter.labels(state.state().name(),
+            deploymentsCounter.labelValues(state.state().name(),
                     PrometheusUtils.UNDEPLOY_OPERATION,
                     PdpResponseStatus.SUCCESS.name()).inc();
             return null;
@@ -467,13 +470,13 @@ public class LifecycleFsm implements Startable {
     }
 
     protected void failedDeployPolicyAction(@NonNull ToscaPolicy failedPolicy) {    // NOSONAR
-        deploymentsCounter.labels(state.state().name(),
+        deploymentsCounter.labelValues(state.state().name(),
                 PrometheusUtils.DEPLOY_OPERATION,
                 PdpResponseStatus.FAIL.name()).inc();
     }
 
     protected void failedUndeployPolicyAction(ToscaPolicy failedPolicy) {
-        deploymentsCounter.labels(state.state().name(),
+        deploymentsCounter.labelValues(state.state().name(),
                 PrometheusUtils.UNDEPLOY_OPERATION,
                 PdpResponseStatus.FAIL.name()).inc();
         policiesMap.remove(failedPolicy.getIdentifier());
index 86d58dd..675d101 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2022, 2024 Nordix Foundation.
+ * Modifications Copyright (C) 2022, 2024-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.
@@ -14,6 +14,8 @@
  * 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=========================================================
  */
 
@@ -89,11 +91,11 @@ public class RestLifecycleManagerTest {
         "policies/vCPE.policy.operational.input.tosca.json";
 
     public static final String PROM_DEPLOY_REQUESTS_TOTAL_UNDEPLOY_ACCEPTED =
-        "pdpd_policy_deployments_total{state=\"ACTIVE\",operation=\"undeploy\",status=\"SUCCESS\",}";
+        "pdpd_policy_deployments_total{operation=\"undeploy\",state=\"ACTIVE\",status=\"SUCCESS\"}";
     public static final String PDPD_DEPLOY_REQUESTS_TOTAL_DEPLOY_ACCEPTED =
-        "pdpd_policy_deployments_total{state=\"ACTIVE\",operation=\"deploy\",status=\"SUCCESS\",}";
+        "pdpd_policy_deployments_total{operation=\"deploy\",state=\"ACTIVE\",status=\"SUCCESS\"}";
     public static final String PDPD_DEPLOY_REQUESTS_TOTAL_DEPLOY_DECLINED =
-        "pdpd_policy_deployments_total{state=\"ACTIVE\",operation=\"deploy\",status=\"FAIL\",}";
+        "pdpd_policy_deployments_total{operation=\"deploy\",state=\"ACTIVE\",status=\"FAIL\"}";
 
     private static final StandardCoder coder = new StandardCoder();
     private static final ControllerSupport controllerSupport = new ControllerSupport("lifecycle");
index c6770d3..e9c23a1 100644 (file)
@@ -17,6 +17,8 @@
   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=========================================================
   -->
 
         </dependency>
         <dependency>
             <groupId>io.prometheus</groupId>
-            <artifactId>simpleclient_servlet_jakarta</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>io.prometheus</groupId>
-            <artifactId>simpleclient_hotspot</artifactId>
-            <scope>runtime</scope>
+            <artifactId>prometheus-metrics-core</artifactId>
         </dependency>
         <dependency>
             <groupId>commons-codec</groupId>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
         </dependency>
-        <dependency>
-            <groupId>io.prometheus</groupId>
-            <artifactId>simpleclient_logback</artifactId>
-        </dependency>
 
         <!-- Swagger v3 annotations -->
         <dependency>
index 580d424..446d53e 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation.
+ * Modifications Copyright (C) 2024-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.
@@ -16,6 +16,8 @@
  * 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=========================================================
  */
 
@@ -27,7 +29,7 @@ import static org.onap.policy.drools.system.PolicyEngineConstants.TELEMETRY_SERV
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
-import io.prometheus.client.Summary;
+import io.prometheus.metrics.core.metrics.Summary;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
@@ -198,8 +200,9 @@ public class PolicyEngineManager implements PolicyEngine {
     protected static final String POLICY_LABEL = "policy";
 
     protected static final Summary transLatencySecsSummary =
-            Summary.build().namespace(PrometheusUtils.PdpType.PDPD.getNamespace())
-                    .name(PrometheusUtils.POLICY_EXECUTIONS_LATENCY_SECONDS_METRIC)
+            Summary.builder()
+                    .name(PrometheusUtils.PdpType.PDPD.getNamespace() + "_"
+                        + PrometheusUtils.POLICY_EXECUTIONS_LATENCY_SECONDS_METRIC)
                     .labelNames(CONTROLLER_LABEL,
                             CONTROLLOOP_NAME_LABEL,
                             POLICY_LABEL,
@@ -312,7 +315,7 @@ public class PolicyEngineManager implements PolicyEngine {
         }
 
         transLatencySecsSummary
-            .labels(controllerName,
+            .labelValues(controllerName,
                     controlLoopName,
                     policyName,
                     transaction.isSuccess() ? PdpResponseStatus.SUCCESS.name() : PdpResponseStatus.FAIL.name())
index 14ca171..63a96b0 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2018-2022 AT&T Intellectual Property. 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.
@@ -16,6 +16,8 @@
  * 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=========================================================
  */
 
@@ -42,8 +44,8 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import io.prometheus.client.CollectorRegistry;
-import io.prometheus.client.Summary;
+import io.prometheus.metrics.core.metrics.Summary;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -153,6 +155,7 @@ class PolicyEngineManagerTest {
     private ScheduledExecutorService exsvc;
     private PolicyResourceLockManager lockmgr;
     private PolicyStatsManager statsManager;
+    private PrometheusRegistry registry;
 
     /**
      * Initializes the object to be tested.
@@ -161,7 +164,8 @@ class PolicyEngineManagerTest {
      */
     @BeforeEach
     public void setUp() throws Exception {
-        CollectorRegistry.defaultRegistry.clear();
+        registry = PrometheusRegistry.defaultRegistry;
+        registry.clear();
         properties = new Properties();
         prov1 = mock(PolicyEngineFeatureApi.class);
         prov2 = mock(PolicyEngineFeatureApi.class);
@@ -327,7 +331,7 @@ class PolicyEngineManagerTest {
 
     @AfterEach
     public void tearDown() {
-        CollectorRegistry.defaultRegistry.clear();
+        PrometheusRegistry.defaultRegistry.clear();
     }
 
     @Test
@@ -1407,7 +1411,7 @@ class PolicyEngineManagerTest {
     }
 
     @Test
-    void testTransaction() {
+    public void testTransaction() {
         mgr.metric(CONTROLLER1, POLICY, new Metric());
         assertEquals(0, mgr.getStats().getGroupStat().getPolicyExecutedCount());
         assertEquals(0, mgr.getStats().getSubgroupStats().size());
@@ -1418,24 +1422,26 @@ class PolicyEngineManagerTest {
         assertEquals(1, mgr.getStats().getSubgroupStats().size());
         assertEquals(1, mgr.getStats().getSubgroupStats().get(CONTROLLOOP).getPolicyExecutedFailCount());
 
-        Summary.Child.Value summary =
-            PolicyEngineManagerImpl.transLatencySecsSummary
-                .labels(CONTROLLER1, CONTROLLOOP, POLICY, PdpResponseStatus.FAIL.name()).get();
+        Summary summary = PolicyEngineManagerImpl.transLatencySecsSummary;
+        summary.labelValues(CONTROLLER1, CONTROLLOOP, POLICY, PdpResponseStatus.FAIL.name()).observe(0.0);
+
+        double sum = summary.collect().getDataPoints().get(0).getSum();
+        long count = summary.collect().getDataPoints().get(0).getCount();
 
-        assertEquals(0, summary.count, 0.0);
-        assertEquals(0, summary.sum, 0.0);
+        assertEquals(0.0, sum);
+        assertEquals(1.0, count);
 
         metric.setServiceInstanceId(POLICY);
         metric.setElapsedTime(5000L);
         metric.setSuccess(false);
         mgr.transaction(CONTROLLER1, CONTROLLOOP, metric);
 
-        summary =
-            PolicyEngineManagerImpl.transLatencySecsSummary
-                .labels(CONTROLLER1, CONTROLLOOP, POLICY, PdpResponseStatus.FAIL.name()).get();
+        summary.labelValues(CONTROLLER1, CONTROLLOOP, POLICY, PdpResponseStatus.FAIL.name()).observe(0.0);
+        sum = summary.collect().getDataPoints().get(0).getSum();
+        count = summary.collect().getDataPoints().get(0).getCount();
 
-        assertEquals(1, summary.count, 0.0);
-        assertEquals(5, summary.sum, 0.0);
+        assertEquals(5.0, sum);
+        assertEquals(3.0, count);
     }
 
     @Test