aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2021-02-22 16:31:30 +0000
committerGerrit Code Review <gerrit@onap.org>2021-02-22 16:31:30 +0000
commit9fdbb34cfe1237c07e3fb1a7b5e9d617d2865bf9 (patch)
tree4092651dc31dd725cfe590cccbc7b2c4429ff6af
parent027c40b1c70d521158f851f95e8d4743d1a1ea32 (diff)
parentea029d57c8c132b8dac6a280b7037ff495c184a4 (diff)
Merge "support control loop transaction metrics"
-rw-r--r--controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java33
-rw-r--r--controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java34
2 files changed, 51 insertions, 16 deletions
diff --git a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java
index 956d28ed8..468c2ea9a 100644
--- a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java
+++ b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. 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.
@@ -29,6 +29,7 @@ import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -38,6 +39,7 @@ import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.drools.utils.logging.MdcTransaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -163,7 +165,7 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics {
case FINAL_FAILURE:
case FINAL_SUCCESS:
case FINAL_OPENLOOP:
- endTransaction(notification);
+ endTransaction(controller, notification);
break;
case ACTIVE:
case OPERATION:
@@ -224,18 +226,15 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics {
/**
* End of a control loop transaction.
*
+ * @param controller controller
* @param notification control loop notification
*/
- protected void endTransaction(VirtualControlLoopNotification notification) {
+ protected void endTransaction(PolicyController controller, VirtualControlLoopNotification notification) {
ZonedDateTime startTime;
VirtualControlLoopNotification startNotification = cache.getIfPresent(notification.getRequestId());
- if (startNotification != null) {
- startTime = startNotification.getNotificationTime();
- } else {
- startTime = notification.getNotificationTime();
- }
+ startTime = Objects.requireNonNullElse(startNotification, notification).getNotificationTime();
- this.transaction(notification, startTime);
+ this.transaction(controller, notification, startTime);
if (startNotification != null) {
removeTransaction(startNotification.getRequestId());
}
@@ -349,7 +348,8 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics {
return trans;
}
- protected void transaction(VirtualControlLoopNotification notification, ZonedDateTime startTime) {
+ protected void transaction(PolicyController controller,
+ VirtualControlLoopNotification notification, ZonedDateTime startTime) {
MdcTransaction trans = getMdcTransaction(notification)
.setStartTime(startTime.toInstant())
.setEndTime(notification.getNotificationTime().toInstant());
@@ -372,6 +372,13 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics {
break;
}
+ try {
+ PolicyEngineConstants.getManager().transaction(controller.getName(),
+ notification.getClosedLoopControlName(), trans.getMetric());
+ } catch (RuntimeException rex) {
+ logger.info("error pegging control loop transaction: {}", trans.getMetric(), rex);
+ }
+
trans.transaction().resetTransaction();
}
@@ -387,10 +394,6 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics {
private String notificationTypeToResponseCode(String notificationType) {
String code = note2code.get(notificationType);
- if (code != null) {
- return code;
- } else {
- return UNKNOWN_RESPONSE_CODE;
- }
+ return Objects.requireNonNullElse(code, UNKNOWN_RESPONSE_CODE);
}
}
diff --git a/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java b/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
index a19006e05..480c8d474 100644
--- a/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
+++ b/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2021 AT&T Intellectual Property. 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.
@@ -32,6 +32,7 @@ import java.nio.file.Path;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -52,6 +53,17 @@ public class ControlLoopMetricsFeatureTest {
private static final Path configPath = SystemPersistenceConstants.getManager().getConfigurationPath();
private static PolicyController testController;
+ private static void resetStats() {
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setAverageExecutionTime(0d);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setLastExecutionTime(0L);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setLastStart(0L);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setAverageExecutionTime(0d);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setPolicyExecutedCount(0L);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setPolicyExecutedFailCount(0L);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setPolicyExecutedSuccessCount(0L);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setTotalElapsedTime(0d);
+ }
+
/**
* Setup method.
*/
@@ -65,6 +77,12 @@ public class ControlLoopMetricsFeatureTest {
@AfterClass
public static void tearDown() {
SystemPersistenceConstants.getManager().setConfigurationDir(configPath.toString());
+ resetStats();
+ }
+
+ @Before
+ public void beforeTest() {
+ resetStats();
}
@Test
@@ -231,6 +249,19 @@ public class ControlLoopMetricsFeatureTest {
Serialization.gsonPretty.fromJson(finalSuccessNotification, VirtualControlLoopNotification.class);
feature.beforeDeliver(testController, CommInfrastructure.DMAAP, POLICY_CL_MGT, finalSuccess);
assertEquals(0, ControlLoopMetricsManager.getManager().getTransactionIds().size());
+ assertEquals(1,
+ PolicyEngineConstants.getManager().getStats().getGroupStat().getPolicyExecutedSuccessCount());
+ assertEquals(0,
+ PolicyEngineConstants.getManager().getStats().getGroupStat().getPolicyExecutedFailCount());
+ assertEquals(1, PolicyEngineConstants.getManager().getStats().getGroupStat().getPolicyExecutedCount());
+ assertEquals(1587409937684L,
+ PolicyEngineConstants.getManager().getStats().getGroupStat().getLastExecutionTime());
+ assertEquals(461d,
+ PolicyEngineConstants.getManager().getStats().getGroupStat().getAverageExecutionTime(), 0.0d);
+ assertEquals(1587409937223L,
+ PolicyEngineConstants.getManager().getStats().getGroupStat().getLastStart());
+ assertEquals(461d,
+ PolicyEngineConstants.getManager().getStats().getGroupStat().getTotalElapsedTime(), 0.0d);
}
@Test
@@ -255,4 +286,5 @@ public class ControlLoopMetricsFeatureTest {
Thread.sleep((ControlLoopMetricsManager.getManager().getTransactionTimeout() + 1) * 1000L); // NOSONAR
assertEquals(0, ControlLoopMetricsManager.getManager().getTransactionIds().size());
}
+
}