diff options
author | Rashmi Pujar <rashmi.pujar1@bell.ca> | 2021-11-26 07:44:23 -0500 |
---|---|---|
committer | Rashmi Pujar <rashmi.pujar1@bell.ca> | 2021-11-30 11:23:53 -0500 |
commit | df756c6862e4a94b43e85c3b95b50fb305c9ee76 (patch) | |
tree | 9acc4abfc21753711abffadabd5ab9610ac99714 /services/services-engine/src/main/java/org | |
parent | 886976ee99995c83dac4b6a7805c3d1514c5ce18 (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/main/java/org')
-rw-r--r-- | services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManager.java | 125 |
1 files changed, 42 insertions, 83 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 |