aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java8
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java3
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java36
-rw-r--r--model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java28
-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
6 files changed, 82 insertions, 71 deletions
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
index 7bd9087df..35139bfe4 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
@@ -56,6 +56,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput;
import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskOutputType;
import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference;
import org.onap.policy.apex.model.policymodel.concepts.AxTask;
+import org.onap.policy.common.utils.resources.PrometheusUtils;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -74,9 +75,10 @@ public class ApexEngineImpl implements ApexEngine {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEngineImpl.class);
// Register state changes with prometheus
- static final Gauge ENGINE_STATE = Gauge.build().name("apex_engine_state").labelNames("engine_instance_id")
- .help("State of the APEX engine as integers mapped as - 0:UNDEFINED, 1:STOPPED, 2:READY,"
- + " 3:EXECUTING, 4:STOPPING").register();
+ static final Gauge ENGINE_STATE = Gauge.build().namespace(PrometheusUtils.PdpType.PDPA.getNamespace())
+ .name("engine_state").labelNames("engine_instance_id")
+ .help("State of the APEX engine as integers mapped as - 0:UNDEFINED, 1:STOPPED, 2:READY,"
+ + " 3:EXECUTING, 4:STOPPING").register();
// Recurring string constants
private static final String UPDATE_MODEL = "updateModel()<-";
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
index 88602206d..3b682acd6 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
@@ -515,8 +515,7 @@ public class ApexEngineImplTest {
private void checkAxEngineStateMetric(AxEngineState state) {
Double stateMetric = CollectorRegistry.defaultRegistry
- .getSampleValue("apex_engine_state", new String[]{"engine_instance_id"},
- new String[]{ENGINE_ID});
+ .getSampleValue("pdpa_engine_state", new String[]{"engine_instance_id"}, new String[]{ENGINE_ID});
assertEquals(stateMetric.intValue(), state.getStateIdentifier());
}
} \ No newline at end of file
diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
index 36df645a5..1420d1e0d 100644
--- a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
+++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
@@ -34,6 +34,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+import org.onap.policy.common.utils.resources.PrometheusUtils;
import org.onap.policy.common.utils.validation.Assertions;
/**
@@ -46,21 +47,22 @@ public class AxEngineStats extends AxConcept {
private static final long serialVersionUID = -6981129081962785368L;
private static final int HASH_CODE_PRIME = 32;
static final String ENGINE_INSTANCE_ID = "engine_instance_id";
- static final Gauge ENGINE_EVENTS_EXECUTED_COUNT = Gauge.build().name("apex_engine_events_executed_count")
- .labelNames(ENGINE_INSTANCE_ID)
- .help("Total number of APEX events processed by the engine.").register();
- static final Gauge ENGINE_UPTIME = Gauge.build().name("apex_engine_uptime")
- .labelNames(ENGINE_INSTANCE_ID)
- .help("Time elapsed since the engine was started.").register();
- static final Gauge ENGINE_START_TIMESTAMP = Gauge.build().name("apex_engine_last_start_timestamp_epoch")
- .labelNames(ENGINE_INSTANCE_ID)
- .help("Epoch timestamp of the instance when engine was last started.").register();
- static final Gauge ENGINE_AVG_EXECUTION_TIME = Gauge.build().name("apex_engine_average_execution_time_seconds")
- .labelNames(ENGINE_INSTANCE_ID)
- .help("Average time taken to execute an APEX policy in seconds.").register();
+ static final Gauge ENGINE_EVENT_EXECUTIONS = Gauge.build().name("engine_event_executions")
+ .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
+ .help("Total number of APEX events processed by the engine.").register();
+ static final Gauge ENGINE_UPTIME = Gauge.build().name("engine_uptime")
+ .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
+ .help("Time elapsed since the engine was started.").register();
+ static final Gauge ENGINE_START_TIMESTAMP = Gauge.build().name("engine_last_start_timestamp_epoch")
+ .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
+ .help("Epoch timestamp of the instance when engine was last started.").register();
+ static final Gauge ENGINE_AVG_EXECUTION_TIME = Gauge.build().name("engine_average_execution_time_seconds")
+ .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
+ .help("Average time taken to execute an APEX policy in seconds.").register();
static final Histogram ENGINE_LAST_EXECUTION_TIME = Histogram.build()
- .name("apex_engine_last_execution_time").labelNames(ENGINE_INSTANCE_ID)
- .help("Time taken to execute the last APEX policy in seconds.").register();
+ .namespace(PrometheusUtils.PdpType.PDPA.getNamespace())
+ .name("engine_last_execution_time").labelNames(ENGINE_INSTANCE_ID)
+ .help("Time taken to execute the last APEX policy in seconds.").register();
private AxReferenceKey key;
private long timeStamp;
@@ -97,7 +99,7 @@ public class AxEngineStats extends AxConcept {
return;
}
ENGINE_UPTIME.labels(engineId).set(upTime / 1000d);
- ENGINE_EVENTS_EXECUTED_COUNT.labels(engineId).set(this.eventCount);
+ ENGINE_EVENT_EXECUTIONS.labels(engineId).set(this.eventCount);
ENGINE_START_TIMESTAMP.labels(engineId).set(this.lastStart);
ENGINE_AVG_EXECUTION_TIME.labels(engineId).set(this.averageExecutionTime / 1000d);
ENGINE_LAST_EXECUTION_TIME.labels(engineId).observe(this.lastExecutionTime / 1000d);
@@ -216,7 +218,7 @@ public class AxEngineStats extends AxConcept {
*/
public void setEventCount(final long eventCount) {
this.eventCount = eventCount;
- ENGINE_EVENTS_EXECUTED_COUNT.labels(getKey().getParentArtifactKey().getId())
+ ENGINE_EVENT_EXECUTIONS.labels(getKey().getParentArtifactKey().getId())
.set(this.eventCount);
}
@@ -328,7 +330,7 @@ public class AxEngineStats extends AxConcept {
}
lastEnterTime = now;
timeStamp = now;
- ENGINE_EVENTS_EXECUTED_COUNT.labels(getKey().getParentArtifactKey().getId()).set(this.eventCount);
+ ENGINE_EVENT_EXECUTIONS.labels(getKey().getParentArtifactKey().getId()).set(this.eventCount);
}
/**
diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
index a40e8cbbf..3eca27c08 100644
--- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
+++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
@@ -224,40 +224,36 @@ public class EngineStatsTest {
}
private void checkUpTimeMetric(AxEngineStats stats) {
- Double upTimeMetric = CollectorRegistry.defaultRegistry.getSampleValue("apex_engine_uptime",
- new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
- new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
+ Double upTimeMetric = CollectorRegistry.defaultRegistry.getSampleValue("pdpa_engine_uptime",
+ new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
assertEquals(upTimeMetric.longValue(), stats.getUpTime());
}
private void checkEventsCountMetric(AxEngineStats stats) {
- Double eventsCountMetric = CollectorRegistry.defaultRegistry
- .getSampleValue("apex_engine_events_executed_count",
- new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
- new String[]{ENGINE_KEY + ":" + ENGINE_VERSION});
+ Double eventsCountMetric = CollectorRegistry.defaultRegistry.getSampleValue("pdpa_engine_event_executions",
+ new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION});
assertEquals(eventsCountMetric.longValue(), stats.getEventCount());
}
private void checkLastExecTimeMetric(AxEngineStats stats) {
Double lastExecTimeMetric = CollectorRegistry.defaultRegistry
- .getSampleValue("apex_engine_last_execution_time_sum", new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
- new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
+ .getSampleValue("pdpa_engine_last_execution_time_sum", new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
+ new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
assertEquals(lastExecTimeMetric.longValue(), stats.getLastExecutionTime());
}
private void checkEngineStartTimestampMetric(AxEngineStats stats) {
Double engineStartTimestampMetric = CollectorRegistry.defaultRegistry
- .getSampleValue("apex_engine_last_start_timestamp_epoch",
- new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
- new String[]{ENGINE_KEY + ":" + ENGINE_VERSION});
+ .getSampleValue("pdpa_engine_last_start_timestamp_epoch",
+ new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION});
assertEquals(engineStartTimestampMetric.longValue(), stats.getLastStart());
}
private void checkAvgExecTimeMetric(AxEngineStats stats) {
Double avgExecTimeMetric = CollectorRegistry.defaultRegistry
- .getSampleValue("apex_engine_average_execution_time_seconds",
- new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
- new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
+ .getSampleValue("pdpa_engine_average_execution_time_seconds",
+ new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
+ new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
assertEquals(avgExecTimeMetric, Double.valueOf(stats.getAverageExecutionTime()));
}
@@ -268,4 +264,4 @@ public class EngineStatsTest {
checkEngineStartTimestampMetric(stats);
checkEngineStartTimestampMetric(stats);
}
-}
+} \ 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 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