summaryrefslogtreecommitdiffstats
path: root/policy-management/src/main
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/main
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/main')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java35
1 files changed, 34 insertions, 1 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