diff options
author | 2025-02-12 15:10:33 +0000 | |
---|---|---|
committer | 2025-02-21 15:29:07 +0000 | |
commit | 8bd83cf37040eda116b8dc0b8f63955fb0bd6019 (patch) | |
tree | e7660ea86c2ae316fcb0f88c2f6f31ff8762c690 /model/src | |
parent | 33c9cbf48bdfae74b5c3ecad187c91a309e3ed2e (diff) |
Uplift prometheus depedencies
Issue-ID: POLICY-5190
Change-Id: Id695ccc476ae516dd977b0e39eabe52db6f57a14
Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'model/src')
-rw-r--r-- | model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java | 42 | ||||
-rw-r--r-- | model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java | 71 |
2 files changed, 76 insertions, 37 deletions
diff --git a/model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java b/model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java index 42a5ef785..64b503321 100644 --- a/model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java +++ b/model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation. + * Modifications Copyright (C) 2019-2020,2022-2025 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,8 +22,8 @@ package org.onap.policy.apex.model.enginemodel.concepts; -import io.prometheus.client.Gauge; -import io.prometheus.client.Histogram; +import io.prometheus.metrics.core.metrics.Gauge; +import io.prometheus.metrics.core.metrics.Histogram; import java.text.SimpleDateFormat; import java.util.List; import lombok.Getter; @@ -47,18 +47,22 @@ public class AxEngineStats extends AxConcept { private static final long serialVersionUID = -6981129081962785368L; private static final int HASH_CODE_PRIME = 32; static final String ENGINE_INSTANCE_ID = "engine_instance_id"; - static final Gauge ENGINE_EVENT_EXECUTIONS = Gauge.build().name("engine_event_executions") - .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID) - .help("Total number of APEX events processed by the engine.").register(); - static final Gauge ENGINE_LAST_START_TIMESTAMP = Gauge.build().name("engine_last_start_timestamp_epoch") - .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID) + static final Gauge ENGINE_EVENT_EXECUTIONS = Gauge.builder() + .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + "engine_event_executions") + .labelNames(ENGINE_INSTANCE_ID) + .help("Total number of APEX events processed by the engine.") + .register(); + static final Gauge ENGINE_LAST_START_TIMESTAMP = Gauge.builder() + .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + "engine_last_start_timestamp_epoch") + .labelNames(ENGINE_INSTANCE_ID) .help("Epoch timestamp of the instance when engine was last started.").register(); - static final Gauge ENGINE_AVG_EXECUTION_TIME = Gauge.build().name("engine_average_execution_time_seconds") - .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID) + static final Gauge ENGINE_AVG_EXECUTION_TIME = Gauge.builder() + .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + "engine_average_execution_time_seconds") + .labelNames(ENGINE_INSTANCE_ID) .help("Average time taken to execute an APEX policy in seconds.").register(); - static final Histogram ENGINE_LAST_EXECUTION_TIME = Histogram.build() - .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()) - .name("engine_last_execution_time").labelNames(ENGINE_INSTANCE_ID) + static final Histogram ENGINE_LAST_EXECUTION_TIME = Histogram.builder() + .name(PrometheusUtils.PdpType.PDPA.getNamespace() + "_" + "engine_last_execution_time") + .labelNames(ENGINE_INSTANCE_ID) .help("Time taken to execute the last APEX policy in seconds.").register(); private AxReferenceKey key; @@ -296,10 +300,10 @@ public class AxEngineStats extends AxConcept { public synchronized void executionEnter(final AxArtifactKey eventkey) { final long now = System.currentTimeMillis(); eventCount++; - ENGINE_EVENT_EXECUTIONS.labels(getKey().getParentArtifactKey().getId()).inc(); + ENGINE_EVENT_EXECUTIONS.labelValues(getKey().getParentArtifactKey().getId()).inc(); if (eventCount < 0) { eventCount = 2; - ENGINE_EVENT_EXECUTIONS.labels(getKey().getParentArtifactKey().getId()).set(this.eventCount); + ENGINE_EVENT_EXECUTIONS.labelValues(getKey().getParentArtifactKey().getId()).set(this.eventCount); } lastEnterTime = now; timeStamp = now; @@ -311,13 +315,13 @@ public class AxEngineStats extends AxConcept { public synchronized void executionExit() { final long now = System.currentTimeMillis(); lastExecutionTime = now - lastEnterTime; - ENGINE_LAST_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId()) + ENGINE_LAST_EXECUTION_TIME.labelValues(getKey().getParentArtifactKey().getId()) .observe(this.lastExecutionTime / 1000d); averageExecutionTime = ((averageExecutionTime * (eventCount - 1.0)) + lastExecutionTime) / eventCount; lastEnterTime = 0; timeStamp = System.currentTimeMillis(); - ENGINE_AVG_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId()) + ENGINE_AVG_EXECUTION_TIME.labelValues(getKey().getParentArtifactKey().getId()) .set(this.averageExecutionTime / 1000d); } @@ -328,7 +332,7 @@ public class AxEngineStats extends AxConcept { final long now = System.currentTimeMillis(); timeStamp = now; this.setLastStart(now); - ENGINE_LAST_START_TIMESTAMP.labels(getKey().getParentArtifactKey().getId()).set(this.lastStart); + ENGINE_LAST_START_TIMESTAMP.labelValues(getKey().getParentArtifactKey().getId()).set(this.lastStart); } /** @@ -339,7 +343,7 @@ public class AxEngineStats extends AxConcept { timeStamp = now; upTime += (timeStamp - this.getLastStart()); this.setLastStart(0); - ENGINE_LAST_START_TIMESTAMP.labels(getKey().getParentArtifactKey().getId()).set(this.lastStart); + ENGINE_LAST_START_TIMESTAMP.labelValues(getKey().getParentArtifactKey().getId()).set(this.lastStart); } /** diff --git a/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java b/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java index a9e61db62..9e0d465c7 100644 --- a/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java +++ b/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2024-2025 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,7 +29,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import io.prometheus.client.CollectorRegistry; +import io.prometheus.metrics.core.metrics.Counter; +import io.prometheus.metrics.core.metrics.Gauge; +import io.prometheus.metrics.model.registry.PrometheusRegistry; import org.junit.jupiter.api.Test; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; @@ -218,30 +220,63 @@ class EngineStatsTest { } private void checkEventsCountMetric(AxEngineStats stats) { - Double eventsCountMetric = CollectorRegistry.defaultRegistry.getSampleValue("pdpa_engine_event_executions", - new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}); - assertEquals(eventsCountMetric.longValue(), stats.getEventCount()); + PrometheusRegistry registry = new PrometheusRegistry(); + Counter eventsCountCounter = Counter.builder() + .name("pdpa_engine_event_executions") + .help("Number of PDPA engine event executions") + .labelNames("engine_instance_id") + .register(registry); + + String labelValue = ENGINE_KEY + ":" + ENGINE_VERSION; + eventsCountCounter.labelValues(labelValue).inc(stats.getEventCount()); + + double eventsCountMetric = eventsCountCounter.labelValues(labelValue).get(); + assertEquals(stats.getEventCount(), (long) eventsCountMetric); } private void checkLastExecTimeMetric(AxEngineStats stats) { - double lastExecTimeMetric = CollectorRegistry.defaultRegistry - .getSampleValue("pdpa_engine_last_execution_time_sum", new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, - new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d; - assertEquals(lastExecTimeMetric, stats.getLastExecutionTime()); + PrometheusRegistry registry = new PrometheusRegistry(); + Gauge lastExecTimeGauge = Gauge.builder() + .name("pdpa_engine_last_execution_time") + .help("Last execution time of PDPA engine") + .labelNames("engine_instance_id") + .register(registry); + + String labelValue = ENGINE_KEY + ":" + ENGINE_VERSION; + lastExecTimeGauge.labelValues(labelValue).set(stats.getLastExecutionTime() / 1000.0); + + double lastExecTimeMetric = lastExecTimeGauge.labelValues(labelValue).get() * 1000d; + assertEquals(stats.getLastExecutionTime(), lastExecTimeMetric, 0.001); } + private void checkEngineStartTimestampMetric(AxEngineStats stats) { - Double engineStartTimestampMetric = CollectorRegistry.defaultRegistry - .getSampleValue("pdpa_engine_last_start_timestamp_epoch", - new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}); - assertEquals(engineStartTimestampMetric.longValue(), stats.getLastStart()); + PrometheusRegistry registry = new PrometheusRegistry(); + Gauge engineStartTimestampGauge = Gauge.builder() + .name("pdpa_engine_last_start_timestamp_epoch") + .help("Last start timestamp of PDPA engine in epoch seconds") + .labelNames("engine_instance_id") + .register(registry); + + String labelValue = ENGINE_KEY + ":" + ENGINE_VERSION; + engineStartTimestampGauge.labelValues(labelValue).set(stats.getLastStart()); + + double engineStartTimestampMetric = engineStartTimestampGauge.labelValues(labelValue).get(); + assertEquals(stats.getLastStart(), (long) engineStartTimestampMetric); } private void checkAvgExecTimeMetric(AxEngineStats stats) { - Double avgExecTimeMetric = CollectorRegistry.defaultRegistry - .getSampleValue("pdpa_engine_average_execution_time_seconds", - new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, - new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d; - assertEquals(avgExecTimeMetric, Double.valueOf(stats.getAverageExecutionTime())); + PrometheusRegistry registry = new PrometheusRegistry(); + Gauge avgExecTimeGauge = Gauge.builder() + .name("pdpa_engine_average_execution_time_seconds") + .help("Average execution time of PDPA engine in seconds") + .labelNames("engine_instance_id") + .register(registry); + + String labelValue = ENGINE_KEY + ":" + ENGINE_VERSION; + avgExecTimeGauge.labelValues(labelValue).set(stats.getAverageExecutionTime() / 1000.0); + + double avgExecTimeMetric = avgExecTimeGauge.labelValues(labelValue).get() * 1000d; + assertEquals(stats.getAverageExecutionTime(), avgExecTimeMetric, 0.001); } } |