summaryrefslogtreecommitdiffstats
path: root/services/services-engine/src
diff options
context:
space:
mode:
authorRashmi Pujar <rashmi.pujar1@bell.ca>2021-11-26 07:44:23 -0500
committerRashmi Pujar <rashmi.pujar1@bell.ca>2021-11-30 11:23:53 -0500
commitdf756c6862e4a94b43e85c3b95b50fb305c9ee76 (patch)
tree9acc4abfc21753711abffadabd5ab9610ac99714 /services/services-engine/src
parent886976ee99995c83dac4b6a7805c3d1514c5ce18 (diff)
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 <rashmi.pujar1@bell.ca>
Diffstat (limited to 'services/services-engine/src')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManager.java125
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java23
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java11
3 files changed, 46 insertions, 113 deletions
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