summaryrefslogtreecommitdiffstats
path: root/services/services-engine
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-engine')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManager.java53
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java25
2 files changed, 45 insertions, 33 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 277b23f06..d0be6492e 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
@@ -25,7 +25,9 @@ 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.resources.PrometheusUtils;
import org.onap.policy.common.utils.services.Registry;
+import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,26 +35,14 @@ import org.slf4j.LoggerFactory;
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();
+ static final Counter POLICY_DEPLOYMENTS_COUNTER =
+ Counter.build().namespace(PrometheusUtils.PdpType.PDPA.getNamespace())
+ .name(PrometheusUtils.POLICY_DEPLOYMENTS_METRIC)
+ .labelNames(PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.STATUS_METRIC_LABEL)
+ .help(PrometheusUtils.POLICY_DEPLOYMENT_HELP).register();
public static final String REG_APEX_PDP_POLICY_COUNTER = "object:pdp/statistics/policy/counter";
+ private static final String PROMETHEUS_TOTAL_LABEL_VALUE = "TOTAL";
private final AtomicLong policyDeployCount = new AtomicLong(0);
private final AtomicLong policyDeploySuccessCount = new AtomicLong(0);
@@ -79,19 +69,18 @@ public class ApexPolicyStatisticsManager {
return instance;
}
-
/**
* Update the policy deploy count.
*/
public void updatePolicyDeployCounter(final boolean isSuccessful) {
+ POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.DEPLOY_OPERATION, PROMETHEUS_TOTAL_LABEL_VALUE).inc();
this.policyDeployCount.incrementAndGet();
- POLICY_DEPLOY_REQUESTS_COUNTER.inc();
if (!isSuccessful) {
+ POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.DEPLOY_OPERATION, PdpResponseStatus.FAIL.name()).inc();
this.policyDeployFailCount.incrementAndGet();
- POLICY_DEPLOY_REQUESTS_FAILED_COUNTER.inc();
} else {
+ POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.DEPLOY_OPERATION, PdpResponseStatus.SUCCESS.name()).inc();
this.policyDeploySuccessCount.incrementAndGet();
- POLICY_DEPLOY_REQUESTS_SUCCESS_COUNTER.inc();
}
}
@@ -107,32 +96,32 @@ public class ApexPolicyStatisticsManager {
}
}
-
/**
* Update the policy undeploy count.
*/
public void updatePolicyUndeployCounter(final boolean isSuccessful) {
+ POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.UNDEPLOY_OPERATION, PROMETHEUS_TOTAL_LABEL_VALUE).inc();
this.policyUndeployCount.incrementAndGet();
- POLICY_UNDEPLOY_REQUESTS_COUNTER.inc();
if (isSuccessful) {
+ POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.UNDEPLOY_OPERATION, PdpResponseStatus.SUCCESS.name())
+ .inc();
this.policyUndeploySuccessCount.incrementAndGet();
- POLICY_UNDEPLOY_REQUESTS_SUCCESS_COUNTER.inc();
} else {
+ POLICY_DEPLOYMENTS_COUNTER.labels(PrometheusUtils.UNDEPLOY_OPERATION, PdpResponseStatus.FAIL.name()).inc();
this.policyUndeployFailCount.incrementAndGet();
- POLICY_UNDEPLOY_REQUESTS_FAILED_COUNTER.inc();
}
}
public long getPolicyDeployCount() {
- return Double.valueOf(POLICY_DEPLOY_REQUESTS_COUNTER.get()).longValue();
+ return policyDeployCount.get();
}
public long getPolicyDeployFailCount() {
- return Double.valueOf(POLICY_DEPLOY_REQUESTS_FAILED_COUNTER.get()).longValue();
+ return policyDeployFailCount.get();
}
public long getPolicyDeploySuccessCount() {
- return Double.valueOf(POLICY_DEPLOY_REQUESTS_SUCCESS_COUNTER.get()).longValue();
+ return policyDeploySuccessCount.get();
}
public long getPolicyExecutedCount() {
@@ -148,14 +137,14 @@ public class ApexPolicyStatisticsManager {
}
public long getPolicyUndeployCount() {
- return Double.valueOf(POLICY_UNDEPLOY_REQUESTS_COUNTER.get()).longValue();
+ return policyUndeployCount.get();
}
public long getPolicyUndeploySuccessCount() {
- return Double.valueOf(POLICY_UNDEPLOY_REQUESTS_SUCCESS_COUNTER.get()).longValue();
+ return policyUndeploySuccessCount.get();
}
public long getPolicyUndeployFailCount() {
- return Double.valueOf(POLICY_UNDEPLOY_REQUESTS_FAILED_COUNTER.get()).longValue();
+ return policyUndeployFailCount.get();
}
} \ 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 a63cea5eb..6213cae1f 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,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Nordix Foundation.
- * Modifications Copyright (C) 2021 Bell Canada Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021-2022 Bell Canada. 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.
@@ -23,8 +23,10 @@ package org.onap.policy.apex.service.engine.main;
import static org.junit.Assert.assertEquals;
+import io.prometheus.client.CollectorRegistry;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.resources.PrometheusUtils;
public class ApexPolicyStatisticsManagerTest {
@@ -46,6 +48,7 @@ public class ApexPolicyStatisticsManagerTest {
statisticsManager.updatePolicyDeployCounter(true);
statisticsManager.updatePolicyDeployCounter(true);
assertDeploys(3, 2, 1);
+ checkDeploymentsMetrics("deploy");
}
@Test
@@ -64,6 +67,7 @@ public class ApexPolicyStatisticsManagerTest {
statisticsManager.updatePolicyUndeployCounter(true);
assertUndeploys(2, 1, 1);
+ checkDeploymentsMetrics("undeploy");
}
private void assertDeploys(long count, long success, long fail) {
@@ -84,4 +88,23 @@ public class ApexPolicyStatisticsManagerTest {
assertEquals(fail, statisticsManager.getPolicyExecutedFailCount());
}
+ private void checkDeploymentsMetrics(String operation) {
+ final var defaultRegistry = CollectorRegistry.defaultRegistry;
+ Double totalCount = defaultRegistry.getSampleValue("pdpa_policy_deployments_total",
+ new String[]{"operation", "status"}, new String[]{operation, "TOTAL"});
+ Double successCount = defaultRegistry.getSampleValue("pdpa_policy_deployments_total",
+ new String[]{"operation", "status"}, new String[]{operation, "SUCCESS"});
+ Double failCount = defaultRegistry.getSampleValue("pdpa_policy_deployments_total",
+ new String[]{"operation", "status"}, new String[]{operation, "FAIL"});
+
+ if (PrometheusUtils.DEPLOY_OPERATION.equals(operation)) {
+ assertEquals(totalCount.intValue(), statisticsManager.getPolicyDeployCount());
+ assertEquals(successCount.intValue(), statisticsManager.getPolicyDeploySuccessCount());
+ assertEquals(failCount.intValue(), statisticsManager.getPolicyDeployFailCount());
+ } else if (PrometheusUtils.UNDEPLOY_OPERATION.equals(operation)) {
+ assertEquals(totalCount.intValue(), statisticsManager.getPolicyUndeployCount());
+ assertEquals(successCount.intValue(), statisticsManager.getPolicyUndeploySuccessCount());
+ assertEquals(failCount.intValue(), statisticsManager.getPolicyUndeployFailCount());
+ }
+ }
} \ No newline at end of file