From: waynedunican Date: Wed, 12 Feb 2025 15:11:24 +0000 (+0000) Subject: Uplift prometheus dependencies X-Git-Tag: 3.1.1~3 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=6595971b29033876ff13e9f9eaef5ee2d0683e4b;p=policy%2Fdrools-pdp.git Uplift prometheus dependencies Issue-ID: POLICY-5190 Change-Id: I9369340c9270d594d93f5fff2931dc10cbacb95f Signed-off-by: waynedunican --- diff --git a/feature-lifecycle/pom.xml b/feature-lifecycle/pom.xml index 3f9da728..13c4ef6c 100644 --- a/feature-lifecycle/pom.xml +++ b/feature-lifecycle/pom.xml @@ -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========================================================= --> @@ -114,7 +116,7 @@ io.prometheus - simpleclient_hotspot + prometheus-metrics-instrumentation-jvm diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java index 6e334901..24bd4ccf 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java @@ -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. @@ -16,13 +16,15 @@ * 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()); diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java index 86d58dd1..675d101a 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java @@ -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"); diff --git a/policy-management/pom.xml b/policy-management/pom.xml index c6770d39..e9c23a16 100644 --- a/policy-management/pom.xml +++ b/policy-management/pom.xml @@ -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========================================================= --> @@ -268,12 +270,7 @@ io.prometheus - simpleclient_servlet_jakarta - - - io.prometheus - simpleclient_hotspot - runtime + prometheus-metrics-core commons-codec @@ -309,10 +306,6 @@ commons-io commons-io - - io.prometheus - simpleclient_logback - diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java index 580d4244..446d53e7 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java @@ -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()) diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java index 14ca1714..63a96b06 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java @@ -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