diff options
Diffstat (limited to 'main/src/main')
-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(); } } }); |