aboutsummaryrefslogtreecommitdiffstats
path: root/model/src/test
diff options
context:
space:
mode:
authorRashmi Pujar <rashmi.pujar1@bell.ca>2022-03-31 11:52:53 -0400
committerRashmi Pujar <rashmi.pujar1@bell.ca>2022-03-31 12:45:23 -0400
commitd2be27372c1e3efb76e2edd648bcfab8945ea51f (patch)
treed137d765090e11de35dd32972b499718bc9f0fec /model/src/test
parent6c3a6abb7e18be81284866f61a54557474e643ed (diff)
Bug fixes for APEX PDP metrics
1. APEX engine metrics were being initialized to 0 in the constructor which caused them to reset to 0. Hence, initialization is removed, and updates are done to metrics only upon: engineStart/Stop, executionEnter/Exit stages. 2. APEX engine Uptime was only updated when engine stopped, hence always 0. Also, uptime is redundant since it can be derived from lastStart timestamp and hence is removed as a metric. 3. Fixed a corner case bug which occurs when all policies are undeployed the counters are not correct. 4. Fix Unit tests Issue-ID: POLICY-4044 Signed-off-by: Rashmi Pujar <rashmi.pujar1@bell.ca> Change-Id: I4d875ff288cf8c242a1851eb105e56dc69b97883
Diffstat (limited to 'model/src/test')
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java38
1 files changed, 7 insertions, 31 deletions
diff --git a/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java b/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
index 3eca27c08..542c6e4c5 100644
--- a/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
+++ b/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
@@ -62,16 +62,13 @@ public class EngineStatsTest {
stats.setAverageExecutionTime(123.45);
assertEquals(Double.valueOf(123.45), Double.valueOf(stats.getAverageExecutionTime()));
- checkAvgExecTimeMetric(stats);
stats.setEventCount(987);
assertEquals(987, stats.getEventCount());
- checkEventsCountMetric(stats);
final long lastExecutionTime = System.currentTimeMillis();
stats.setLastExecutionTime(lastExecutionTime);
assertEquals(lastExecutionTime, stats.getLastExecutionTime());
- checkLastExecTimeMetric(stats);
final long timestamp = System.currentTimeMillis();
stats.setTimeStamp(timestamp);
@@ -81,17 +78,14 @@ public class EngineStatsTest {
final long upTime = System.currentTimeMillis() - timestamp;
stats.setUpTime(upTime);
assertEquals(upTime, stats.getUpTime());
- checkUpTimeMetric(stats);
stats.engineStart();
assertTrue(stats.getUpTime() > -1);
checkEngineStartTimestampMetric(stats);
- checkLastExecTimeMetric(stats);
stats.engineStop();
assertTrue(stats.getUpTime() >= 0);
stats.engineStop();
- checkUpTimeMetric(stats);
checkEngineStartTimestampMetric(stats);
stats.reset();
@@ -104,15 +98,12 @@ public class EngineStatsTest {
stats.setEventCount(10);
stats.executionEnter(new AxArtifactKey());
assertEquals(11, stats.getEventCount());
- checkEventsCountMetric(stats);
stats.reset();
stats.engineStart();
- stats.setEventCount(4);
- checkUpTimeMetric(stats);
+ stats.setEventCount(3);
stats.executionEnter(new AxArtifactKey());
checkEventsCountMetric(stats);
- checkAvgExecTimeMetric(stats);
checkEngineStartTimestampMetric(stats);
synchronized (WAIT_LOCK) {
@@ -124,10 +115,13 @@ public class EngineStatsTest {
}
stats.executionExit();
+ checkAvgExecTimeMetric(stats);
+ checkEventsCountMetric(stats);
+ checkLastExecTimeMetric(stats);
final double avExecutionTime = stats.getAverageExecutionTime();
assertTrue(avExecutionTime >= 2.0 && avExecutionTime < 10.0);
stats.engineStop();
- checkUpTimeMetric(stats);
+ checkEngineStartTimestampMetric(stats);
AxValidationResult result = new AxValidationResult();
result = stats.validate(result);
@@ -145,7 +139,6 @@ public class EngineStatsTest {
stats.clean();
stats.reset();
- checkAllPrometheusMetrics(stats);
final AxEngineStats clonedStats = new AxEngineStats(stats);
assertEquals("AxEngineStats:(engineKey=AxReferenceKey:(parentKey", clonedStats.toString().substring(0, 50));
@@ -158,7 +151,6 @@ public class EngineStatsTest {
assertEquals(stats, stats); // NOSONAR
assertEquals(stats, clonedStats);
assertNotNull(stats);
- checkAllPrometheusMetrics(clonedStats);
Object helloObject = "Hello";
assertNotEquals(stats, helloObject);
@@ -176,7 +168,6 @@ public class EngineStatsTest {
stats.setTimeStamp(0);
assertEquals(stats, new AxEngineStats(statsKey));
assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
- checkAllPrometheusMetrics(clonedStats);
stats.setEventCount(1);
assertNotEquals(stats, new AxEngineStats(statsKey));
@@ -210,23 +201,16 @@ public class EngineStatsTest {
stats.engineStart();
assertNotEquals(stats, new AxEngineStats(statsKey));
+ checkEngineStartTimestampMetric(stats);
final AxEngineStats newStats = new AxEngineStats(statsKey);
newStats.setTimeStamp(stats.getTimeStamp());
assertNotEquals(stats, newStats);
assertNotEquals(0, stats.compareTo(newStats));
stats.engineStop();
- checkUpTimeMetric(stats);
checkEngineStartTimestampMetric(stats);
stats.reset();
assertEquals(stats, new AxEngineStats(statsKey));
assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
- checkAllPrometheusMetrics(stats);
- }
-
- private void checkUpTimeMetric(AxEngineStats stats) {
- 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) {
@@ -256,12 +240,4 @@ public class EngineStatsTest {
new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
assertEquals(avgExecTimeMetric, Double.valueOf(stats.getAverageExecutionTime()));
}
-
- private void checkAllPrometheusMetrics(AxEngineStats stats) {
- checkEventsCountMetric(stats);
- checkUpTimeMetric(stats);
- checkAvgExecTimeMetric(stats);
- checkEngineStartTimestampMetric(stats);
- checkEngineStartTimestampMetric(stats);
- }
-} \ No newline at end of file
+}