From df756c6862e4a94b43e85c3b95b50fb305c9ee76 Mon Sep 17 00:00:00 2001 From: Rashmi Pujar Date: Fri, 26 Nov 2021 07:44:23 -0500 Subject: Prometheus metrics for policy deploy/undeploy requests for APEX Added counters for: - Policy deploy/undeploy requests total - Policy deploy/undeploy successful requests total - Policy deploy/undeploy failed requests total Cleaned up unused method resetAllStatistics. Fixed some checkstyle warnings Update to latest snapshot for parent, and common modules Depends on https://gerrit.onap.org/r/c/policy/parent/+/125974 for build to pass. Issue-ID: POLICY-3760 Change-Id: I4a9447c9caea7a018dba86057b9dae3871910709 Signed-off-by: Rashmi Pujar --- pom.xml | 10 +- services/services-engine/pom.xml | 7 +- .../engine/main/ApexPolicyStatisticsManager.java | 125 +++++++-------------- .../main/ApexPolicyStatisticsManagerTest.java | 23 +--- .../engine/runtime/impl/EngineWorkerTest.java | 11 +- 5 files changed, 57 insertions(+), 119 deletions(-) diff --git a/pom.xml b/pom.xml index 67cf39650..fa178475e 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ org.onap.policy.parent integration - 3.5.0 + 3.5.1-SNAPSHOT @@ -45,8 +45,8 @@ 1.4 2.3.0 5.3.7.Final - 1.10.0 - 2.6.0 + 1.10.1-SNAPSHOT + 2.6.1-SNAPSHOT 4.1.5.Final 2.8.0 ${project.basedir}/target/code-coverage/lcov.info @@ -129,7 +129,7 @@ - only-eclipse @@ -223,4 +223,4 @@ tools packages - + \ No newline at end of file diff --git a/services/services-engine/pom.xml b/services/services-engine/pom.xml index 039e40925..bd527c69d 100644 --- a/services/services-engine/pom.xml +++ b/services/services-engine/pom.xml @@ -2,6 +2,7 @@ ============LICENSE_START======================================================= Copyright (C) 2018 Ericsson. All rights reserved. Copyright (C) 2019-2020 Nordix Foundation. + Modifications Copyright (C) 2021 Bell Canada Intellectual Property. All rights reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -41,6 +42,10 @@ org.onap.policy.common common-parameters + + io.prometheus + simpleclient + org.onap.policy.apex-pdp.core core-engine @@ -102,4 +107,4 @@ - + \ No newline at end of file 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 1924d9f8a..277b23f06 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 @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2020-2021 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Bell Canada Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,7 @@ package org.onap.policy.apex.service.engine.main; +import io.prometheus.client.Counter; import java.util.concurrent.atomic.AtomicLong; import lombok.NoArgsConstructor; import org.onap.policy.common.utils.services.Registry; @@ -30,7 +32,28 @@ import org.slf4j.LoggerFactory; @NoArgsConstructor public class ApexPolicyStatisticsManager { private static final Logger LOGGER = LoggerFactory.getLogger(ApexPolicyStatisticsManager.class); + + static final Counter POLICY_DEPLOY_REQUESTS_COUNTER = Counter.build() + .name("policies_deploy_requests_total") + .help("Total number of TOSCA policies deploy requests.").register(); + static final Counter POLICY_DEPLOY_REQUESTS_SUCCESS_COUNTER = Counter.build() + .name("policies_deploy_requests_success") + .help("Total number of TOSCA policies deploy requests that succeeded.").register(); + static final Counter POLICY_DEPLOY_REQUESTS_FAILED_COUNTER = Counter.build() + .name("policies_deploy_requests_failed") + .help("Total number of TOSCA policies deploy requests that failed.").register(); + static final Counter POLICY_UNDEPLOY_REQUESTS_COUNTER = Counter.build() + .name("policies_undeploy_requests_total").help("Total number of TOSCA policies undeploy requests.") + .register(); + static final Counter POLICY_UNDEPLOY_REQUESTS_SUCCESS_COUNTER = Counter.build() + .name("policies_undeploy_requests_success") + .help("Total number of TOSCA policies undeploy requests that succeeded.").register(); + static final Counter POLICY_UNDEPLOY_REQUESTS_FAILED_COUNTER = Counter.build() + .name("policies_undeploy_requests_failed") + .help("Total number of TOSCA policies undeploy requests that failed.").register(); + public static final String REG_APEX_PDP_POLICY_COUNTER = "object:pdp/statistics/policy/counter"; + private final AtomicLong policyDeployCount = new AtomicLong(0); private final AtomicLong policyDeploySuccessCount = new AtomicLong(0); private final AtomicLong policyDeployFailCount = new AtomicLong(0); @@ -61,11 +84,14 @@ public class ApexPolicyStatisticsManager { * Update the policy deploy count. */ public void updatePolicyDeployCounter(final boolean isSuccessful) { - this.updatepPolicyDeployCount(); + this.policyDeployCount.incrementAndGet(); + POLICY_DEPLOY_REQUESTS_COUNTER.inc(); if (!isSuccessful) { - this.updatePolicyDeployFailCount(); + this.policyDeployFailCount.incrementAndGet(); + POLICY_DEPLOY_REQUESTS_FAILED_COUNTER.inc(); } else { - this.updatePolicyDeploySuccessCount(); + this.policyDeploySuccessCount.incrementAndGet(); + POLICY_DEPLOY_REQUESTS_SUCCESS_COUNTER.inc(); } } @@ -73,11 +99,11 @@ public class ApexPolicyStatisticsManager { * Update the policy executed count. */ public void updatePolicyExecutedCounter(final boolean isSuccessful) { - this.updatePolicyExecutedCount(); + this.policyExecutedCount.incrementAndGet(); if (isSuccessful) { - this.updatePolicyExecutedSuccessCount(); + this.policyExecutedSuccessCount.incrementAndGet(); } else { - this.updatePolicyExecutedFailCount(); + this.policyExecutedFailCount.incrementAndGet(); } } @@ -87,93 +113,26 @@ public class ApexPolicyStatisticsManager { */ public void updatePolicyUndeployCounter(final boolean isSuccessful) { this.policyUndeployCount.incrementAndGet(); + POLICY_UNDEPLOY_REQUESTS_COUNTER.inc(); if (isSuccessful) { this.policyUndeploySuccessCount.incrementAndGet(); + POLICY_UNDEPLOY_REQUESTS_SUCCESS_COUNTER.inc(); } else { this.policyUndeployFailCount.incrementAndGet(); + POLICY_UNDEPLOY_REQUESTS_FAILED_COUNTER.inc(); } } - /** - * Method to update the total policy deploy count. - * - * @return the updated value of policyDeployCount - */ - private long updatepPolicyDeployCount() { - return policyDeployCount.incrementAndGet(); - } - - /** - * Method to update the total policy deploy failed count. - * - * @return the updated value of totalPolicyDeployCount - */ - private long updatePolicyDeployFailCount() { - return policyDeployFailCount.incrementAndGet(); - } - - /** - * Method to update the policy deploy success count. - * - * @return the updated value of policyDeploySuccessCount - */ - private long updatePolicyDeploySuccessCount() { - return policyDeploySuccessCount.incrementAndGet(); - } - - - /** - * Method to update the total policy executed count. - * - * @return the updated value of policyExecutedCount - */ - private long updatePolicyExecutedCount() { - return policyExecutedCount.incrementAndGet(); - } - - /** - * Method to update the policy executed success count. - * - * @return the updated value of policyExecutedSuccessCount - */ - private long updatePolicyExecutedSuccessCount() { - return policyExecutedSuccessCount.incrementAndGet(); - } - - /** - * Method to update the policy executed failure count. - * - * @return the updated value of policyExecutedFailCount - */ - private long updatePolicyExecutedFailCount() { - return policyExecutedFailCount.incrementAndGet(); - } - - /** - * Reset all the statistics counts to 0. - */ - public void resetAllStatistics() { - policyDeployCount.set(0L); - policyDeployFailCount.set(0L); - policyDeploySuccessCount.set(0L); - policyUndeployCount.set(0L); - policyUndeployFailCount.set(0L); - policyUndeploySuccessCount.set(0L); - policyExecutedCount.set(0L); - policyExecutedSuccessCount.set(0L); - policyExecutedFailCount.set(0L); - } - public long getPolicyDeployCount() { - return policyDeployCount.get(); + return Double.valueOf(POLICY_DEPLOY_REQUESTS_COUNTER.get()).longValue(); } public long getPolicyDeployFailCount() { - return policyDeployFailCount.get(); + return Double.valueOf(POLICY_DEPLOY_REQUESTS_FAILED_COUNTER.get()).longValue(); } public long getPolicyDeploySuccessCount() { - return policyDeploySuccessCount.get(); + return Double.valueOf(POLICY_DEPLOY_REQUESTS_SUCCESS_COUNTER.get()).longValue(); } public long getPolicyExecutedCount() { @@ -189,14 +148,14 @@ public class ApexPolicyStatisticsManager { } public long getPolicyUndeployCount() { - return policyUndeployCount.get(); + return Double.valueOf(POLICY_UNDEPLOY_REQUESTS_COUNTER.get()).longValue(); } public long getPolicyUndeploySuccessCount() { - return policyUndeploySuccessCount.get(); + return Double.valueOf(POLICY_UNDEPLOY_REQUESTS_SUCCESS_COUNTER.get()).longValue(); } public long getPolicyUndeployFailCount() { - return policyUndeployFailCount.get(); + return Double.valueOf(POLICY_UNDEPLOY_REQUESTS_FAILED_COUNTER.get()).longValue(); } -} +} \ No newline at end of file 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 4c541bd12..a63cea5eb 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,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,26 +66,6 @@ public class ApexPolicyStatisticsManagerTest { assertUndeploys(2, 1, 1); } - @Test - public void testResetAllStatistics() { - statisticsManager.updatePolicyDeployCounter(true); - statisticsManager.updatePolicyDeployCounter(true); - statisticsManager.updatePolicyDeployCounter(false); - statisticsManager.updatePolicyUndeployCounter(false); - statisticsManager.updatePolicyExecutedCounter(true); - - assertDeploys(3, 2, 1); - assertUndeploys(1, 0, 1); - assertExecuted(1, 1, 0); - - statisticsManager.resetAllStatistics(); - - assertDeploys(0, 0, 0); - assertUndeploys(0, 0, 0); - assertExecuted(0, 0, 0); - - } - private void assertDeploys(long count, long success, long fail) { assertEquals(count, statisticsManager.getPolicyDeployCount()); assertEquals(success, statisticsManager.getPolicyDeploySuccessCount()); @@ -103,4 +84,4 @@ public class ApexPolicyStatisticsManagerTest { assertEquals(fail, statisticsManager.getPolicyExecutedFailCount()); } -} +} \ No newline at end of file diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java index 067a6b1b4..504e8df14 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -455,13 +456,5 @@ public class EngineWorkerTest { assertNotNull(policyCounter); assertEquals(policyCounter.getPolicyExecutedCount(), policyCounter.getPolicyExecutedFailCount() + policyCounter.getPolicyExecutedSuccessCount()); - policyCounter.resetAllStatistics(); - assertEquals(0, policyCounter.getPolicyExecutedCount()); - assertEquals(0, policyCounter.getPolicyExecutedFailCount()); - assertEquals(0, policyCounter.getPolicyExecutedSuccessCount()); - assertEquals(0, policyCounter.getPolicyDeployCount()); - assertEquals(0, policyCounter.getPolicyDeployFailCount()); - assertEquals(0, policyCounter.getPolicyDeploySuccessCount()); - } -} +} \ No newline at end of file -- cgit 1.2.3-korg