aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-engine
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-engine')
-rw-r--r--services/services-engine/pom.xml7
-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
4 files changed, 52 insertions, 114 deletions
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.
@@ -42,6 +43,10 @@
<artifactId>common-parameters</artifactId>
</dependency>
<dependency>
+ <groupId>io.prometheus</groupId>
+ <artifactId>simpleclient</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.onap.policy.apex-pdp.core</groupId>
<artifactId>core-engine</artifactId>
<version>${project.version}</version>
@@ -102,4 +107,4 @@
</resource>
</resources>
</build>
-</project>
+</project> \ 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