diff options
author | Rashmi Pujar <rashmi.pujar1@bell.ca> | 2022-01-25 18:08:09 -0500 |
---|---|---|
committer | Ajith Sreekumar <ajith.sreekumar@bell.ca> | 2022-02-07 10:08:27 +0000 |
commit | 143d9c2e74ebe962640810140aa028637af88a6c (patch) | |
tree | 3beb7899f119678b997af379cbb63f405a7b94dd /services/services-engine/src/main/java | |
parent | def44b294fa00bb5470e977eef9a05e5087035f0 (diff) |
Expose APEX policy execution metrics
Testing of these metrics will be covered in CSIT.
Issue-ID: POLICY-3845
Signed-off-by: Rashmi Pujar <rashmi.pujar1@bell.ca>
Change-Id: I8aed49d113f071ab33691f8cf1df624f3358386a
Diffstat (limited to 'services/services-engine/src/main/java')
-rw-r--r-- | services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java index 8f3bb858f..a5e823e97 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2021 Nordix Foundation. - * Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,6 +23,8 @@ package org.onap.policy.apex.service.engine.main; +import com.google.common.base.Strings; +import io.prometheus.client.Counter; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; @@ -33,9 +35,11 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import lombok.Getter; import lombok.NonNull; +import org.apache.commons.lang3.EnumUtils; import org.onap.policy.apex.core.infrastructure.threading.ApplicationThreadFactory; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus; import org.onap.policy.apex.service.engine.event.ApexEvent; import org.onap.policy.apex.service.engine.event.ApexEventConsumer; import org.onap.policy.apex.service.engine.event.ApexEventException; @@ -48,6 +52,9 @@ import org.onap.policy.apex.service.engine.event.impl.EventProtocolFactory; import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.onap.policy.common.utils.resources.PrometheusUtils; +import org.onap.policy.models.pdp.concepts.PdpStatus; +import org.onap.policy.models.pdp.enums.PdpResponseStatus; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -67,6 +74,14 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { // The amount of time to wait between polls of the event queue in milliseconds private static final long EVENT_QUEUE_POLL_INTERVAL = 20; + private static final String PROMETHEUS_TOTAL_LABEL_VALUE = "TOTAL"; + + // prometheus registration for policy execution metrics + static final Counter POLICY_EXECUTED_COUNTER = + Counter.build().namespace(PrometheusUtils.PdpType.PDPA.getNamespace()) + .name(PrometheusUtils.POLICY_EXECUTION_METRIC).labelNames(PrometheusUtils.STATUS_METRIC_LABEL) + .help(PrometheusUtils.POLICY_EXECUTION_HELP).register(); + // The name of the unmarshaler @Getter private final String name; @@ -218,11 +233,36 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { synchronousEventCache.cacheSynchronizedEventToApex(apexEvent.getExecutionId(), apexEvent); } + // Update policy execution metrics + updatePolicyExecutedMetrics(apexEvent.getToscaPolicyState()); + // Enqueue the event queue.add(apexEvent); } } + /** + * Increment Prometheus counters for TOSCA policy execution metrics. + * + * @param toscaPolicyState the TOSCA Policy state flag from the event + */ + private void updatePolicyExecutedMetrics(String toscaPolicyState) { + // Skip events that are not flagged as TOSCA processing entry or exit points. + if (Strings.isNullOrEmpty(toscaPolicyState) + || !EnumUtils.isValidEnum(AxToscaPolicyProcessingStatus.class, toscaPolicyState)) { + return; + } + + // Increment total, successful and failed policy executed counter. + if (AxToscaPolicyProcessingStatus.ENTRY.name().equals(toscaPolicyState)) { + POLICY_EXECUTED_COUNTER.labels(PROMETHEUS_TOTAL_LABEL_VALUE).inc(); + } else if (AxToscaPolicyProcessingStatus.EXIT_SUCCESS.name().equals(toscaPolicyState)) { + POLICY_EXECUTED_COUNTER.labels(PdpResponseStatus.SUCCESS.name()).inc(); + } else if (AxToscaPolicyProcessingStatus.EXIT_FAILURE.name().equals(toscaPolicyState)) { + POLICY_EXECUTED_COUNTER.labels(PdpResponseStatus.FAIL.name()).inc(); + } + } + private List<ApexEvent> convertToApexEvents(final Object event) throws ApexEventException { List<ApexEvent> apexEventList = null; List<String> eventNamesList = null; @@ -340,4 +380,4 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { } LOGGER.exit("shut down Apex event unmarshaller"); } -} +}
\ No newline at end of file |