diff options
author | 2025-02-12 15:10:33 +0000 | |
---|---|---|
committer | 2025-02-21 15:29:07 +0000 | |
commit | 8bd83cf37040eda116b8dc0b8f63955fb0bd6019 (patch) | |
tree | e7660ea86c2ae316fcb0f88c2f6f31ff8762c690 /services | |
parent | 33c9cbf48bdfae74b5c3ecad187c91a309e3ed2e (diff) |
Uplift prometheus depedencies
Issue-ID: POLICY-5190
Change-Id: Id695ccc476ae516dd977b0e39eabe52db6f57a14
Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'services')
5 files changed, 69 insertions, 42 deletions
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> |