ONAP
================================================================================
Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2023-2024 Nordix Foundation.
+ Modifications Copyright (C) 2023-2025 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+
+ SPDX-License-Identifier: Apache-2.0
============LICENSE_END=========================================================
-->
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
- <artifactId>simpleclient_hotspot</artifactId>
+ <artifactId>prometheus-metrics-instrumentation-jvm</artifactId>
</dependency>
</dependencies>
* ONAP
* ================================================================================
* Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021, 2023-2024 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 2023-2025 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.drools.lifecycle;
import com.google.re2j.Pattern;
-import io.prometheus.client.Counter;
+import io.prometheus.metrics.core.metrics.Counter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
protected static final String PROMETHEUS_NAMESPACE = "pdpd";
protected static final Counter deploymentsCounter =
- Counter.build().namespace(PROMETHEUS_NAMESPACE).name(PrometheusUtils.POLICY_DEPLOYMENTS_METRIC)
+ Counter.builder()
+ .name(PROMETHEUS_NAMESPACE + "_" + PrometheusUtils.POLICY_DEPLOYMENTS_METRIC)
.labelNames(PrometheusUtils.STATE_METRIC_LABEL,
PrometheusUtils.OPERATION_METRIC_LABEL,
PrometheusUtils.STATUS_METRIC_LABEL)
policiesMap.computeIfAbsent(policy.getIdentifier(), key -> {
// avoid counting reapplies in a second pass when a mix of native and non-native
// policies are present.
- deploymentsCounter.labels(state.state().name(),
+ deploymentsCounter.labelValues(state.state().name(),
PrometheusUtils.DEPLOY_OPERATION,
PdpResponseStatus.SUCCESS.name()).inc();
return policy;
policiesMap.computeIfPresent(policy.getIdentifier(), (key, value) -> {
// avoid counting reapplies in a second pass when a mix of native and non-native
// policies are present.
- deploymentsCounter.labels(state.state().name(),
+ deploymentsCounter.labelValues(state.state().name(),
PrometheusUtils.UNDEPLOY_OPERATION,
PdpResponseStatus.SUCCESS.name()).inc();
return null;
}
protected void failedDeployPolicyAction(@NonNull ToscaPolicy failedPolicy) { // NOSONAR
- deploymentsCounter.labels(state.state().name(),
+ deploymentsCounter.labelValues(state.state().name(),
PrometheusUtils.DEPLOY_OPERATION,
PdpResponseStatus.FAIL.name()).inc();
}
protected void failedUndeployPolicyAction(ToscaPolicy failedPolicy) {
- deploymentsCounter.labels(state.state().name(),
+ deploymentsCounter.labelValues(state.state().name(),
PrometheusUtils.UNDEPLOY_OPERATION,
PdpResponseStatus.FAIL.name()).inc();
policiesMap.remove(failedPolicy.getIdentifier());
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2022, 2024 Nordix Foundation.
+ * Modifications Copyright (C) 2022, 2024-2025 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
"policies/vCPE.policy.operational.input.tosca.json";
public static final String PROM_DEPLOY_REQUESTS_TOTAL_UNDEPLOY_ACCEPTED =
- "pdpd_policy_deployments_total{state=\"ACTIVE\",operation=\"undeploy\",status=\"SUCCESS\",}";
+ "pdpd_policy_deployments_total{operation=\"undeploy\",state=\"ACTIVE\",status=\"SUCCESS\"}";
public static final String PDPD_DEPLOY_REQUESTS_TOTAL_DEPLOY_ACCEPTED =
- "pdpd_policy_deployments_total{state=\"ACTIVE\",operation=\"deploy\",status=\"SUCCESS\",}";
+ "pdpd_policy_deployments_total{operation=\"deploy\",state=\"ACTIVE\",status=\"SUCCESS\"}";
public static final String PDPD_DEPLOY_REQUESTS_TOTAL_DEPLOY_DECLINED =
- "pdpd_policy_deployments_total{state=\"ACTIVE\",operation=\"deploy\",status=\"FAIL\",}";
+ "pdpd_policy_deployments_total{operation=\"deploy\",state=\"ACTIVE\",status=\"FAIL\"}";
private static final StandardCoder coder = new StandardCoder();
private static final ControllerSupport controllerSupport = new ControllerSupport("lifecycle");
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+
+ SPDX-License-Identifier: Apache-2.0
============LICENSE_END=========================================================
-->
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
- <artifactId>simpleclient_servlet_jakarta</artifactId>
- </dependency>
- <dependency>
- <groupId>io.prometheus</groupId>
- <artifactId>simpleclient_hotspot</artifactId>
- <scope>runtime</scope>
+ <artifactId>prometheus-metrics-core</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
- <dependency>
- <groupId>io.prometheus</groupId>
- <artifactId>simpleclient_logback</artifactId>
- </dependency>
<!-- Swagger v3 annotations -->
<dependency>
* ONAP
* ================================================================================
* Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation.
+ * Modifications Copyright (C) 2024-2025 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import io.prometheus.client.Summary;
+import io.prometheus.metrics.core.metrics.Summary;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
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)
+ Summary.builder()
+ .name(PrometheusUtils.PdpType.PDPD.getNamespace() + "_"
+ + PrometheusUtils.POLICY_EXECUTIONS_LATENCY_SECONDS_METRIC)
.labelNames(CONTROLLER_LABEL,
CONTROLLOOP_NAME_LABEL,
POLICY_LABEL,
}
transLatencySecsSummary
- .labels(controllerName,
+ .labelValues(controllerName,
controlLoopName,
policyName,
transaction.isSuccess() ? PdpResponseStatus.SUCCESS.name() : PdpResponseStatus.FAIL.name())
* ONAP
* ================================================================================
* Copyright (C) 2018-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023-2024 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2025 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import io.prometheus.client.CollectorRegistry;
-import io.prometheus.client.Summary;
+import io.prometheus.metrics.core.metrics.Summary;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
private ScheduledExecutorService exsvc;
private PolicyResourceLockManager lockmgr;
private PolicyStatsManager statsManager;
+ private PrometheusRegistry registry;
/**
* Initializes the object to be tested.
*/
@BeforeEach
public void setUp() throws Exception {
- CollectorRegistry.defaultRegistry.clear();
+ registry = PrometheusRegistry.defaultRegistry;
+ registry.clear();
properties = new Properties();
prov1 = mock(PolicyEngineFeatureApi.class);
prov2 = mock(PolicyEngineFeatureApi.class);
@AfterEach
public void tearDown() {
- CollectorRegistry.defaultRegistry.clear();
+ PrometheusRegistry.defaultRegistry.clear();
}
@Test
}
@Test
- void testTransaction() {
+ public void testTransaction() {
mgr.metric(CONTROLLER1, POLICY, new Metric());
assertEquals(0, mgr.getStats().getGroupStat().getPolicyExecutedCount());
assertEquals(0, mgr.getStats().getSubgroupStats().size());
assertEquals(1, mgr.getStats().getSubgroupStats().size());
assertEquals(1, mgr.getStats().getSubgroupStats().get(CONTROLLOOP).getPolicyExecutedFailCount());
- Summary.Child.Value summary =
- PolicyEngineManagerImpl.transLatencySecsSummary
- .labels(CONTROLLER1, CONTROLLOOP, POLICY, PdpResponseStatus.FAIL.name()).get();
+ Summary summary = PolicyEngineManagerImpl.transLatencySecsSummary;
+ summary.labelValues(CONTROLLER1, CONTROLLOOP, POLICY, PdpResponseStatus.FAIL.name()).observe(0.0);
+
+ double sum = summary.collect().getDataPoints().get(0).getSum();
+ long count = summary.collect().getDataPoints().get(0).getCount();
- assertEquals(0, summary.count, 0.0);
- assertEquals(0, summary.sum, 0.0);
+ assertEquals(0.0, sum);
+ assertEquals(1.0, count);
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();
+ summary.labelValues(CONTROLLER1, CONTROLLOOP, POLICY, PdpResponseStatus.FAIL.name()).observe(0.0);
+ sum = summary.collect().getDataPoints().get(0).getSum();
+ count = summary.collect().getDataPoints().get(0).getCount();
- assertEquals(1, summary.count, 0.0);
- assertEquals(5, summary.sum, 0.0);
+ assertEquals(5.0, sum);
+ assertEquals(3.0, count);
}
@Test