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";
39 protected static final String POLICY_DECISIONS_METRIC = "policy_decisions";
40 public static final String POLICY_DECISIONS_HELP = "The total number of policy decisions.";
41 public static final String PERMIT_OPERATION = "permit";
42 public static final String DENY_OPERATION = "deny";
43 public static final String INDETERMINANT_OPERATION = "indeterminant";
44 public static final String NOT_APPLICABLE_OPERATION = "not_applicable";
46 protected static final Counter deploymentsCounter =
47 Counter.build().namespace(PROMETHEUS_NAMESPACE).name(PrometheusUtils.POLICY_DEPLOYMENTS_METRIC)
48 .labelNames(PrometheusUtils.OPERATION_METRIC_LABEL,
49 PrometheusUtils.STATUS_METRIC_LABEL)
50 .help(PrometheusUtils.POLICY_DEPLOYMENT_HELP)
53 protected static final Counter decisionsCounter =
54 Counter.build().namespace(PROMETHEUS_NAMESPACE).name(POLICY_DECISIONS_METRIC)
55 .labelNames(PrometheusUtils.STATUS_METRIC_LABEL)
56 .help(POLICY_DECISIONS_HELP)
59 private long totalPolicyTypesCount;
60 private long totalPoliciesCount;
61 private long errorCount;
62 private long permitDecisionsCount;
63 private long denyDecisionsCount;
64 private long deploySuccessCount;
65 private long deployFailureCount;
66 private long undeploySuccessCount;
67 private long undeployFailureCount;
68 private long indeterminantDecisionsCount;
69 private long notApplicableDecisionsCount;
72 * Method to set the xacml pdp total policy types count. This
73 * doesn't really increment, it depends on the applications
74 * that are loaded. Which can be dynamic.
79 public long setTotalPolicyTypesCount(long newCount) {
80 totalPolicyTypesCount = newCount;
81 return totalPolicyTypesCount;
85 * Method to set the xacml pdp total policies count. This
86 * doesn't really increment, it depends on the applications
87 * that are loaded. Which can be dynamic.
92 public long setTotalPolicyCount(long newCount) {
93 totalPoliciesCount = newCount;
94 return totalPoliciesCount;
98 * Method to update the number of error decisions.
100 * @return the errorDecisionsCount
103 public long updateErrorCount() {
108 * Method to update the number of permit decisions.
110 * @return the permitDecisionsCount
113 public long updatePermitDecisionsCount() {
114 decisionsCounter.labels(PERMIT_OPERATION).inc();
115 return ++permitDecisionsCount;
119 * Method to update the number of deny decisions.
121 * @return the denyDecisionsCount
124 public long updateDenyDecisionsCount() {
125 decisionsCounter.labels(DENY_OPERATION).inc();
126 return ++denyDecisionsCount;
130 * Method to update the number of successful deploys.
132 * @return the deploySuccessCount
135 public long updateDeploySuccessCount() {
136 deploymentsCounter.labels(PrometheusUtils.DEPLOY_OPERATION,
137 PdpResponseStatus.SUCCESS.name()).inc();
138 return ++deploySuccessCount;
142 * Method to update the number of failed deploys.
144 * @return the deployFailureCount
147 public long updateDeployFailureCount() {
148 deploymentsCounter.labels(PrometheusUtils.DEPLOY_OPERATION,
149 PdpResponseStatus.FAIL.name()).inc();
150 return ++deployFailureCount;
154 * Method to update the number of successful undeploys.
156 * @return the undeploySuccessCount
159 public long updateUndeploySuccessCount() {
160 deploymentsCounter.labels(PrometheusUtils.UNDEPLOY_OPERATION,
161 PdpResponseStatus.SUCCESS.name()).inc();
162 return ++undeploySuccessCount;
166 * Method to update the number of failed undeploys.
168 * @return the undeployFailureCount
171 public long updateUndeployFailureCount() {
172 deploymentsCounter.labels(PrometheusUtils.UNDEPLOY_OPERATION,
173 PdpResponseStatus.FAIL.name()).inc();
174 return ++undeployFailureCount;
178 * Method to update the number of indeterminant decisions.
180 * @return the indeterminantDecisionsCount
183 public long updateIndeterminantDecisionsCount() {
184 decisionsCounter.labels(INDETERMINANT_OPERATION).inc();
185 return ++indeterminantDecisionsCount;
189 * Method to update the number of not applicable decisions.
191 * @return the notApplicableDecisionsCount
194 public long updateNotApplicableDecisionsCount() {
195 decisionsCounter.labels(NOT_APPLICABLE_OPERATION).inc();
196 return ++notApplicableDecisionsCount;
200 * Reset all the statistics counts to 0.
203 public void resetAllStatistics() {
204 totalPolicyTypesCount = 0L;
205 totalPoliciesCount = 0L;
207 permitDecisionsCount = 0L;
208 denyDecisionsCount = 0L;
209 deploySuccessCount = 0L;
210 deployFailureCount = 0L;
211 undeploySuccessCount = 0L;
212 undeployFailureCount = 0L;
213 indeterminantDecisionsCount = 0L;
214 notApplicableDecisionsCount = 0L;