2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019, 2021-2022 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pdpx.main.rest;
23 import io.prometheus.client.Counter;
26 import lombok.Synchronized;
27 import org.onap.policy.common.utils.resources.PrometheusUtils;
28 import org.onap.policy.models.pdp.enums.PdpResponseStatus;
31 * Class to hold statistical data for xacmlPdp component.
33 @Getter(onMethod_ = @Synchronized)
34 public class XacmlPdpStatisticsManager {
37 private static XacmlPdpStatisticsManager current = null;
38 protected static final String PROMETHEUS_NAMESPACE = "pdpx";
40 protected static final Counter deploymentsCounter =
41 Counter.build().namespace(PROMETHEUS_NAMESPACE).name(PrometheusUtils.POLICY_DEPLOYMENTS_METRIC)
42 .labelNames(PrometheusUtils.OPERATION_METRIC_LABEL,
43 PrometheusUtils.STATUS_METRIC_LABEL)
44 .help(PrometheusUtils.POLICY_DEPLOYMENT_HELP)
47 private long totalPolicyTypesCount;
48 private long totalPoliciesCount;
49 private long errorCount;
50 private long permitDecisionsCount;
51 private long denyDecisionsCount;
52 private long deploySuccessCount;
53 private long deployFailureCount;
54 private long undeploySuccessCount;
55 private long undeployFailureCount;
56 private long indeterminantDecisionsCount;
57 private long notApplicableDecisionsCount;
60 * Method to set the xacml pdp total policy types count. This
61 * doesn't really increment, it depends on the applications
62 * that are loaded. Which can be dynamic.
67 public long setTotalPolicyTypesCount(long newCount) {
68 totalPolicyTypesCount = newCount;
69 return totalPolicyTypesCount;
73 * Method to set the xacml pdp total policies count. This
74 * doesn't really increment, it depends on the applications
75 * that are loaded. Which can be dynamic.
80 public long setTotalPolicyCount(long newCount) {
81 totalPoliciesCount = newCount;
82 return totalPoliciesCount;
86 * Method to update the number of error decisions.
88 * @return the errorDecisionsCount
91 public long updateErrorCount() {
96 * Method to update the number of permit decisions.
98 * @return the permitDecisionsCount
101 public long updatePermitDecisionsCount() {
102 return ++permitDecisionsCount;
106 * Method to update the number of deny decisions.
108 * @return the denyDecisionsCount
111 public long updateDenyDecisionsCount() {
112 return ++denyDecisionsCount;
116 * Method to update the number of successful deploys.
118 * @return the deploySuccessCount
121 public long updateDeploySuccessCount() {
122 deploymentsCounter.labels(PrometheusUtils.DEPLOY_OPERATION,
123 PdpResponseStatus.SUCCESS.name()).inc();
124 return ++deploySuccessCount;
128 * Method to update the number of failed deploys.
130 * @return the deployFailureCount
133 public long updateDeployFailureCount() {
134 deploymentsCounter.labels(PrometheusUtils.DEPLOY_OPERATION,
135 PdpResponseStatus.FAIL.name()).inc();
136 return ++deployFailureCount;
140 * Method to update the number of successful undeploys.
142 * @return the undeploySuccessCount
145 public long updateUndeploySuccessCount() {
146 deploymentsCounter.labels(PrometheusUtils.UNDEPLOY_OPERATION,
147 PdpResponseStatus.SUCCESS.name()).inc();
148 return ++undeploySuccessCount;
152 * Method to update the number of failed undeploys.
154 * @return the undeployFailureCount
157 public long updateUndeployFailureCount() {
158 deploymentsCounter.labels(PrometheusUtils.UNDEPLOY_OPERATION,
159 PdpResponseStatus.FAIL.name()).inc();
160 return ++undeployFailureCount;
164 * Method to update the number of indeterminant decisions.
166 * @return the indeterminantDecisionsCount
169 public long updateIndeterminantDecisionsCount() {
170 return ++indeterminantDecisionsCount;
174 * Method to update the number of not applicable decisions.
176 * @return the notApplicableDecisionsCount
179 public long updateNotApplicableDecisionsCount() {
180 return ++notApplicableDecisionsCount;
184 * Reset all the statistics counts to 0.
187 public void resetAllStatistics() {
188 totalPolicyTypesCount = 0L;
189 totalPoliciesCount = 0L;
191 permitDecisionsCount = 0L;
192 denyDecisionsCount = 0L;
193 deploySuccessCount = 0L;
194 deployFailureCount = 0L;
195 undeploySuccessCount = 0L;
196 undeployFailureCount = 0L;
197 indeterminantDecisionsCount = 0L;
198 notApplicableDecisionsCount = 0L;