diff options
author | 2022-01-07 01:38:40 -0500 | |
---|---|---|
committer | 2022-01-10 16:08:30 -0500 | |
commit | 58eae5d260f4e41ae439b733404fd1bc7dca453b (patch) | |
tree | e48dd9fc1a81191cf61184e2e43b7ef2e55bb671 /core/core-engine/src/main/java | |
parent | 63cd91c92e53349283ef920bb1dfd9efa1ca3a48 (diff) |
Prometheues metrics for APEX engine stats
Issue-ID: POLICY-3846
Signed-off-by: Rashmi Pujar <rashmi.pujar1@bell.ca>
Change-Id: I385446683372548f3fed6d609a9e85633ec2916d
Diffstat (limited to 'core/core-engine/src/main/java')
-rw-r--r-- | core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java index 0d9d34d39..7bd9087df 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-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"); @@ -25,6 +25,7 @@ package org.onap.policy.apex.core.engine.engine.impl; import static org.onap.policy.common.utils.validation.Assertions.argumentNotNull; +import io.prometheus.client.Gauge; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; @@ -72,6 +73,11 @@ public class ApexEngineImpl implements ApexEngine { // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEngineImpl.class); + // Register state changes with prometheus + static final Gauge ENGINE_STATE = Gauge.build().name("apex_engine_state").labelNames("engine_instance_id") + .help("State of the APEX engine as integers mapped as - 0:UNDEFINED, 1:STOPPED, 2:READY," + + " 3:EXECUTING, 4:STOPPING").register(); + // Recurring string constants private static final String UPDATE_MODEL = "updateModel()<-"; private static final String START = "start()<-"; @@ -123,6 +129,7 @@ public class ApexEngineImpl implements ApexEngine { */ @Override public void updateModel(final AxPolicyModel apexModel, final boolean isSubsequentInstance) throws ApexException { + updateStatePrometheusMetric(); if (apexModel != null) { LOGGER.entry("updateModel()->{}, apexPolicyModel {}", key.getId(), apexModel.getKey().getId()); } else { @@ -249,6 +256,7 @@ public class ApexEngineImpl implements ApexEngine { // OK, we are good to go state = AxEngineState.READY; + updateStatePrometheusMetric(); LOGGER.exit("start()" + key); } @@ -278,6 +286,7 @@ public class ApexEngineImpl implements ApexEngine { case READY: case STOPPED: state = AxEngineState.STOPPED; + updateStatePrometheusMetric(); stateMachineHandler.stop(); engineStats.engineStop(); LOGGER.exit("stop()" + key); @@ -286,6 +295,7 @@ public class ApexEngineImpl implements ApexEngine { // Engine is executing a policy, wait for it to stop case EXECUTING: state = AxEngineState.STOPPING; + updateStatePrometheusMetric(); break; // Wait for the engine to stop @@ -303,6 +313,7 @@ public class ApexEngineImpl implements ApexEngine { synchronized (stateLockObj) { state = AxEngineState.STOPPED; } + updateStatePrometheusMetric(); throw new ApexException(STOP + key.getId() + "," + state + ", error stopping engine, engine stop timed out"); } @@ -370,6 +381,7 @@ public class ApexEngineImpl implements ApexEngine { state = AxEngineState.EXECUTING; } + updateStatePrometheusMetric(); String message = "execute(): triggered by event " + incomingEvent.toString(); LOGGER.debug(message); @@ -413,6 +425,7 @@ public class ApexEngineImpl implements ApexEngine { state = AxEngineState.STOPPED; } } + updateStatePrometheusMetric(); return ret; } @@ -507,4 +520,11 @@ public class ApexEngineImpl implements ApexEngine { return Set.of(exceptionEvent); } -} + + /** + * Update the APEX engine state to prometheus for monitoring. + */ + private void updateStatePrometheusMetric() { + ENGINE_STATE.labels(getKey().getId()).set(state.getStateIdentifier()); + } +}
\ No newline at end of file |