diff options
author | a.sreekumar <ajith.sreekumar@bell.ca> | 2022-04-11 11:18:04 +0100 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@bell.ca> | 2022-04-12 11:11:07 +0100 |
commit | 9dbc162db1f26e9b37641c73fff8fba0d4f23c81 (patch) | |
tree | 616324d4a87545189937524db6ba475a16f1a363 /main/src/main/java | |
parent | 055c1546c92e797dc54cdb9e41a1d032abdf49b4 (diff) |
Fix incorrect deployments counter on parallel execution
Change-Id: I72bde10eae615e2c89ccc1a211c6385404b9b3c7
Issue-ID: POLICY-4088
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'main/src/main/java')
-rw-r--r-- | main/src/main/java/org/onap/policy/pap/main/notification/DeploymentStatus.java | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/notification/DeploymentStatus.java b/main/src/main/java/org/onap/policy/pap/main/notification/DeploymentStatus.java index 7a1aa107..24b75ab8 100644 --- a/main/src/main/java/org/onap/policy/pap/main/notification/DeploymentStatus.java +++ b/main/src/main/java/org/onap/policy/pap/main/notification/DeploymentStatus.java @@ -21,6 +21,7 @@ package org.onap.policy.pap.main.notification; +import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.MeterRegistry; import java.util.ArrayList; import java.util.HashMap; @@ -77,6 +78,10 @@ public class DeploymentStatus { private PolicyStatusService policyStatusService; + private Counter deploymentSuccessCounter; + private Counter unDeploymentSuccessCounter; + private Counter deploymentFailureCounter; + private Counter unDeploymentFailureCounter; /** * Constructs the object. @@ -85,6 +90,27 @@ public class DeploymentStatus { */ public DeploymentStatus(PolicyStatusService policyStatusService) { this.policyStatusService = policyStatusService; + initializeMetrics(); + } + + private void initializeMetrics() { + String counterName = "pap_" + PrometheusUtils.POLICY_DEPLOYMENTS_METRIC; + MeterRegistry meterRegistry = Registry.get(PapConstants.REG_METER_REGISTRY, MeterRegistry.class); + deploymentSuccessCounter = + Counter.builder(counterName).tags(PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.DEPLOY_OPERATION, + PrometheusUtils.STATUS_METRIC_LABEL, State.SUCCESS.name()).register(meterRegistry); + + unDeploymentSuccessCounter = Counter.builder(counterName).tags(PrometheusUtils.OPERATION_METRIC_LABEL, + PrometheusUtils.UNDEPLOY_OPERATION, PrometheusUtils.STATUS_METRIC_LABEL, State.SUCCESS.name()) + .register(meterRegistry); + + deploymentFailureCounter = + Counter.builder(counterName).tags(PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.DEPLOY_OPERATION, + PrometheusUtils.STATUS_METRIC_LABEL, State.FAILURE.name()).register(meterRegistry); + + unDeploymentFailureCounter = Counter.builder(counterName).tags(PrometheusUtils.OPERATION_METRIC_LABEL, + PrometheusUtils.UNDEPLOY_OPERATION, PrometheusUtils.STATUS_METRIC_LABEL, State.FAILURE.name()) + .register(meterRegistry); } /** @@ -178,20 +204,12 @@ public class DeploymentStatus { } private void updateMetrics() { - MeterRegistry meterRegistry = Registry.get(PapConstants.REG_METER_REGISTRY, MeterRegistry.class); - String counterName = "pap_" + PrometheusUtils.POLICY_DEPLOYMENTS_METRIC; recordMap.forEach((key, value) -> { if (value.getAction().equals(StatusAction.Action.UPDATED)) { if (value.getStatus().getState().equals(State.SUCCESS)) { - meterRegistry.counter(counterName, PrometheusUtils.OPERATION_METRIC_LABEL, - value.getStatus().isDeploy() ? PrometheusUtils.DEPLOY_OPERATION - : PrometheusUtils.UNDEPLOY_OPERATION, - PrometheusUtils.STATUS_METRIC_LABEL, State.SUCCESS.name()).increment(); + (value.getStatus().isDeploy() ? deploymentSuccessCounter : unDeploymentSuccessCounter).increment(); } else if (value.getStatus().getState().equals(State.FAILURE)) { - meterRegistry.counter(counterName, PrometheusUtils.OPERATION_METRIC_LABEL, - value.getStatus().isDeploy() ? PrometheusUtils.DEPLOY_OPERATION - : PrometheusUtils.UNDEPLOY_OPERATION, - PrometheusUtils.STATUS_METRIC_LABEL, State.FAILURE.name()).increment(); + (value.getStatus().isDeploy() ? deploymentFailureCounter : unDeploymentFailureCounter).increment(); } } }); |