aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2022-02-09 07:59:29 -0600
committerjhh <jorge.hernandez-herrero@att.com>2022-02-09 07:59:29 -0600
commitbeb5cb32f7d1ccb08735ea3d5f77a8b2223857e4 (patch)
tree64378ad8701ce6483b0f780cd8316e76ac8300f6 /policy-management/src
parent673ec06842c37f245c6da4848a330b656e20bfda (diff)
add policy_executions_latency_seconds summary
Issue-ID: POLICY-3761 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: I9867472784d8f153b6955ce95b34de250f60f558
Diffstat (limited to 'policy-management/src')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java35
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java41
2 files changed, 70 insertions, 6 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
index 7252179b..ea4094fc 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 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.
@@ -26,8 +26,10 @@ import static org.onap.policy.drools.system.PolicyEngineConstants.TELEMETRY_SERV
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import io.prometheus.client.Summary;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -57,6 +59,7 @@ import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.gson.annotation.GsonJsonProperty;
import org.onap.policy.common.utils.logging.LoggerUtils;
+import org.onap.policy.common.utils.resources.PrometheusUtils;
import org.onap.policy.common.utils.services.FeatureApiUtils;
import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.core.PolicyContainer;
@@ -83,6 +86,7 @@ import org.onap.policy.drools.stats.PolicyStatsManager;
import org.onap.policy.drools.system.internal.SimpleLockManager;
import org.onap.policy.drools.utils.PropertyUtil;
import org.onap.policy.drools.utils.logging.MdcTransaction;
+import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -171,6 +175,20 @@ class PolicyEngineManager implements PolicyEngine {
*/
private final Gson decoder = new GsonBuilder().disableHtmlEscaping().create();
+ protected static final String CONTROLLOOP_NAME_LABEL = "controlloop";
+ protected static final String CONTROLLER_LABEL = "controller";
+ protected static final String POLICY_LABEL = "policy";
+
+ protected static final Summary transLatencySecsSummary =
+ Summary.build().namespace(PrometheusUtils.PdpType.PDPD.getNamespace())
+ .name(PrometheusUtils.POLICY_EXECUTIONS_LATENCY_SECONDS_METRIC)
+ .labelNames(CONTROLLER_LABEL,
+ CONTROLLOOP_NAME_LABEL,
+ POLICY_LABEL,
+ PrometheusUtils.STATUS_METRIC_LABEL)
+ .help(PrometheusUtils.POLICY_EXECUTIONS_LATENCY_SECONDS_HELP)
+ .register();
+
@Override
public synchronized void boot(String[] cliArgs) {
@@ -266,6 +284,21 @@ class PolicyEngineManager implements PolicyEngine {
// the controller name is used for tracking purposes
getStats().stat(controlLoopName, transaction);
+
+ Long elapsedTime = transaction.getElapsedTime();
+ String policyName = transaction.getServiceInstanceId();
+ if (Objects.isNull(elapsedTime) || StringUtils.isEmpty(policyName)) {
+ logger.warn("{} transaction in controller {} incomplete transaction object: {}",
+ controlLoopName, controllerName, transaction);
+ return;
+ }
+
+ transLatencySecsSummary
+ .labels(controllerName,
+ controlLoopName,
+ policyName,
+ transaction.isSuccess() ? PdpResponseStatus.SUCCESS.name() : PdpResponseStatus.FAIL.name())
+ .observe(transaction.getElapsedTime() / 1000D);
}
@Override
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
index 4be25d1a..82c28695 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2022 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.
@@ -40,6 +40,8 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import io.prometheus.client.CollectorRegistry;
+import io.prometheus.client.Summary;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -47,6 +49,7 @@ import java.util.Properties;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -74,6 +77,7 @@ import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
import org.onap.policy.drools.stats.PolicyStatsManager;
import org.onap.policy.drools.system.internal.SimpleLockManager;
import org.onap.policy.drools.system.internal.SimpleLockProperties;
+import org.onap.policy.models.pdp.enums.PdpResponseStatus;
public class PolicyEngineManagerTest {
private static final String EXPECTED = "expected exception";
@@ -90,6 +94,8 @@ public class PolicyEngineManagerTest {
private static final String MESSAGE = "my-message";
private static final String MY_OWNER = "my-owner";
private static final String MY_RESOURCE = "my-resource";
+ private static final String POLICY = "policy";
+ private static final String CONTROLLOOP = "controlloop";
private static final Object MY_EVENT = new Object();
@@ -153,7 +159,7 @@ public class PolicyEngineManagerTest {
*/
@Before
public void setUp() throws Exception {
-
+ CollectorRegistry.defaultRegistry.clear();
properties = new Properties();
prov1 = mock(PolicyEngineFeatureApi.class);
prov2 = mock(PolicyEngineFeatureApi.class);
@@ -317,6 +323,11 @@ public class PolicyEngineManagerTest {
mgr = new PolicyEngineManagerImpl();
}
+ @After
+ public void tearDown() {
+ CollectorRegistry.defaultRegistry.clear();
+ }
+
@Test
public void testSerialize() {
mgr.configure(properties);
@@ -1360,14 +1371,34 @@ public class PolicyEngineManagerTest {
@Test
public void testTransaction() {
- mgr.metric("foo", "bar", new Metric());
+ mgr.metric(CONTROLLER1, POLICY, new Metric());
assertEquals(0, mgr.getStats().getGroupStat().getPolicyExecutedCount());
assertEquals(0, mgr.getStats().getSubgroupStats().size());
- mgr.transaction("foo", "bar", new Metric());
+ Metric metric = new Metric();
+ mgr.transaction(CONTROLLER1, CONTROLLOOP, metric);
assertEquals(1, mgr.getStats().getGroupStat().getPolicyExecutedCount());
assertEquals(1, mgr.getStats().getSubgroupStats().size());
- assertEquals(1, mgr.getStats().getSubgroupStats().get("bar").getPolicyExecutedFailCount());
+ assertEquals(1, mgr.getStats().getSubgroupStats().get(CONTROLLOOP).getPolicyExecutedFailCount());
+
+ Summary.Child.Value summary =
+ PolicyEngineManagerImpl.transLatencySecsSummary
+ .labels(CONTROLLER1, CONTROLLOOP, POLICY, PdpResponseStatus.FAIL.name()).get();
+
+ assertEquals(0, summary.count, 0.0);
+ assertEquals(0, summary.sum, 0.0);
+
+ metric.setServiceInstanceId(POLICY);
+ metric.setElapsedTime(5000L);
+ metric.setSuccess(false);
+ mgr.transaction(CONTROLLER1, CONTROLLOOP, metric);
+
+ summary =
+ PolicyEngineManagerImpl.transLatencySecsSummary
+ .labels(CONTROLLER1, CONTROLLOOP, POLICY, PdpResponseStatus.FAIL.name()).get();
+
+ assertEquals(1, summary.count, 0.0);
+ assertEquals(5, summary.sum, 0.0);
}
@Test