aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java16
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java57
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java39
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java12
-rw-r--r--main/src/main/resources/application.yaml1
5 files changed, 95 insertions, 30 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java
index 5770f441..01b539e3 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2022 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -28,6 +28,7 @@ import io.swagger.annotations.SecurityDefinition;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import java.net.HttpURLConnection;
+import java.util.Objects;
import java.util.UUID;
import javax.ws.rs.core.MediaType;
import org.onap.policy.models.base.PfModelException;
@@ -110,12 +111,9 @@ public class PapRestControllerV1 {
* @return the response builder, with version logging
*/
public static BodyBuilder addLoggingHeaders(BodyBuilder respBuilder, UUID requestId) {
- if (requestId == null) {
- // Generate a random uuid if client does not embed requestId in rest request
- return respBuilder.header(REQUEST_ID_NAME, UUID.randomUUID().toString());
- }
-
- return respBuilder.header(REQUEST_ID_NAME, requestId.toString());
+ // Generate a random uuid if client does not embed requestId in rest request
+ return respBuilder.header(REQUEST_ID_NAME,
+ Objects.requireNonNullElseGet(requestId, UUID::randomUUID).toString());
}
/**
@@ -134,7 +132,7 @@ public class PapRestControllerV1 {
* Functions that throw {@link PfModelException}.
*/
@FunctionalInterface
- public static interface RunnableWithPfEx {
- public void run() throws PfModelException;
+ public interface RunnableWithPfEx {
+ void run() throws PfModelException;
}
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java
index 7853fda6..10db1793 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java
@@ -3,7 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,8 @@
package org.onap.policy.pap.main.rest;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Timer;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
@@ -30,15 +32,20 @@ import io.swagger.annotations.Authorization;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.ResponseHeader;
+import java.time.Duration;
+import java.time.Instant;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
+import org.onap.policy.common.utils.resources.PrometheusUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
+import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -56,6 +63,33 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
private static final Logger logger = LoggerFactory.getLogger(PdpGroupDeleteControllerV1.class);
private final PdpGroupDeleteProvider provider;
+ private Timer undeploySuccessTimer;
+ private Timer undeployFailureTimer;
+
+
+ @Autowired
+ public PdpGroupDeleteControllerV1(PdpGroupDeleteProvider provider, MeterRegistry meterRegistry) {
+ this.provider = provider;
+ initMetrics(meterRegistry);
+ }
+
+ /**
+ * Initializes the metrics for delete operation.
+ *
+ * @param meterRegistry spring bean for MeterRegistry to add the new metric
+ */
+ public void initMetrics(MeterRegistry meterRegistry) {
+ String metricName = String.join(".", "pap", "policy", "deployments");
+ String description = "Timer for HTTP request to deploy/undeploy a policy";
+ undeploySuccessTimer = Timer.builder(metricName).description(description)
+ .tags(PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.UNDEPLOY_OPERATION,
+ PrometheusUtils.STATUS_METRIC_LABEL, PdpPolicyStatus.State.SUCCESS.name())
+ .register(meterRegistry);
+ undeployFailureTimer = Timer.builder(metricName).description(description)
+ .tags(PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.UNDEPLOY_OPERATION,
+ PrometheusUtils.STATUS_METRIC_LABEL, PdpPolicyStatus.State.FAILURE.name())
+ .register(meterRegistry);
+ }
/**
* Deletes a PDP group.
@@ -98,7 +132,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
required = false,
value = REQUEST_ID_NAME) final UUID requestId,
@ApiParam(value = "PDP Group Name") @PathVariable("name") String groupName) {
- return doOperation(requestId, "delete group failed", () -> provider.deleteGroup(groupName));
+ return doOperation(requestId, () -> provider.deleteGroup(groupName));
}
/**
@@ -143,7 +177,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
value = REQUEST_ID_NAME) final UUID requestId,
@ApiParam(value = "PDP Policy Name") @PathVariable("name") String policyName) {
- return doUndeployOperation(requestId, "undeploy policy failed",
+ return doUndeployOperation(requestId,
() -> provider.undeploy(new ToscaConceptIdentifierOptVersion(policyName, null), getPrincipal()));
}
@@ -191,7 +225,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
@ApiParam(value = "PDP Policy Name") @PathVariable("name") String policyName,
@ApiParam(value = "PDP Policy Version") @PathVariable("version") String version) {
- return doUndeployOperation(requestId, "undeploy policy failed",
+ return doUndeployOperation(requestId,
() -> provider.undeploy(new ToscaConceptIdentifierOptVersion(policyName, version), getPrincipal()));
}
@@ -199,19 +233,17 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
* Invokes an operation.
*
* @param requestId request ID
- * @param errmsg error message to log if the operation throws an exception
* @param runnable operation to invoke
* @return a {@link PdpGroupDeleteResponse} response entity
*/
- private ResponseEntity<PdpGroupDeleteResponse> doOperation(UUID requestId, String errmsg,
- RunnableWithPfEx runnable) {
+ private ResponseEntity<PdpGroupDeleteResponse> doOperation(UUID requestId, RunnableWithPfEx runnable) {
try {
runnable.run();
return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
.body(new PdpGroupDeleteResponse());
} catch (PfModelException | PfModelRuntimeException e) {
- logger.warn(errmsg, e);
+ logger.warn("delete group failed", e);
var resp = new PdpGroupDeleteResponse();
resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
return addLoggingHeaders(
@@ -224,22 +256,23 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
* Invokes the undeployment operation.
*
* @param requestId request ID
- * @param errmsg error message to log if the operation throws an exception
* @param runnable operation to invoke
* @return a {@link PdpGroupDeployResponse} response entity
*/
- private ResponseEntity<PdpGroupDeployResponse> doUndeployOperation(UUID requestId, String errmsg,
- RunnableWithPfEx runnable) {
+ private ResponseEntity<PdpGroupDeployResponse> doUndeployOperation(UUID requestId, RunnableWithPfEx runnable) {
+ Instant start = Instant.now();
try {
runnable.run();
+ undeploySuccessTimer.record(Duration.between(start, Instant.now()));
return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.accepted()), requestId)
.body(new PdpGroupDeployResponse(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG,
PdpGroupDeployControllerV1.POLICY_STATUS_URI));
} catch (PfModelException | PfModelRuntimeException e) {
- logger.warn(errmsg, e);
+ logger.warn("undeploy policy failed", e);
var resp = new PdpGroupDeployResponse();
resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
+ undeployFailureTimer.record(Duration.between(start, Instant.now()));
return addLoggingHeaders(
addVersionControlHeaders(ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode())),
requestId).body(resp);
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java
index d1e732d5..5917dafc 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java
@@ -4,7 +4,7 @@
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
- * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@
package org.onap.policy.pap.main.rest;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Timer;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
@@ -30,15 +32,20 @@ import io.swagger.annotations.Authorization;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.ResponseHeader;
+import java.time.Duration;
+import java.time.Instant;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
+import org.onap.policy.common.utils.resources.PrometheusUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.pap.concepts.PdpDeployPolicies;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
import org.onap.policy.models.pdp.concepts.DeploymentGroups;
+import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -62,6 +69,33 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
private static final Logger logger = LoggerFactory.getLogger(PdpGroupDeployControllerV1.class);
private final PdpGroupDeployProvider provider;
+ private Timer deploySuccessTimer;
+ private Timer deployFailureTimer;
+
+
+ @Autowired
+ public PdpGroupDeployControllerV1(PdpGroupDeployProvider provider, MeterRegistry meterRegistry) {
+ this.provider = provider;
+ initMetrics(meterRegistry);
+ }
+
+ /**
+ * Initializes the metrics for delete operation.
+ *
+ * @param meterRegistry spring bean for MeterRegistry to add the new metric
+ */
+ public void initMetrics(MeterRegistry meterRegistry) {
+ String metricName = String.join(".", "pap", "policy", "deployments");
+ String description = "Timer for HTTP request to deploy/undeploy a policy";
+ deploySuccessTimer = Timer.builder(metricName).description(description)
+ .tags(PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.DEPLOY_OPERATION,
+ PrometheusUtils.STATUS_METRIC_LABEL, PdpPolicyStatus.State.SUCCESS.name())
+ .register(meterRegistry);
+ deployFailureTimer = Timer.builder(metricName).description(description)
+ .tags(PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.DEPLOY_OPERATION,
+ PrometheusUtils.STATUS_METRIC_LABEL, PdpPolicyStatus.State.FAILURE.name())
+ .register(meterRegistry);
+ }
/**
* Updates policy deployments within specific PDP groups.
@@ -163,8 +197,10 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
*/
private ResponseEntity<PdpGroupDeployResponse> doOperation(UUID requestId, String errmsg,
RunnableWithPfEx runnable) {
+ Instant start = Instant.now();
try {
runnable.run();
+ deploySuccessTimer.record(Duration.between(start, Instant.now()));
return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.accepted()), requestId)
.body(new PdpGroupDeployResponse(DEPLOYMENT_RESPONSE_MSG, POLICY_STATUS_URI));
@@ -172,6 +208,7 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
logger.warn(errmsg, e);
var resp = new PdpGroupDeployResponse();
resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
+ deployFailureTimer.record(Duration.between(start, Instant.now()));
return addLoggingHeaders(
addVersionControlHeaders(ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode())),
requestId).body(resp);
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
index c1c63c7f..9857883c 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
@@ -3,7 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation.
* Modifications Copyright (C) 2020,2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -56,7 +56,6 @@ import org.springframework.context.event.EventListener;
* </ul>
*/
public abstract class ProviderBase {
- public static final String DB_ERROR_MSG = "DB error";
public static final String DEFAULT_USER = "PAP";
/**
@@ -235,11 +234,8 @@ public abstract class ProviderBase {
* @param policyType the policy type of interest
* @return the matching PDP group, or {@code null} if no active group supports the
* given PDP types
- * @throws PfModelException if an error occurred
*/
- private Collection<PdpGroup> getGroups(SessionData data, ToscaConceptIdentifier policyType)
- throws PfModelException {
-
+ private Collection<PdpGroup> getGroups(SessionData data, ToscaConceptIdentifier policyType) {
return data.getActivePdpGroupsByPolicyType(policyType);
}
@@ -334,7 +330,7 @@ public abstract class ProviderBase {
}
@FunctionalInterface
- public static interface BiConsumerWithEx<F, S> {
+ public interface BiConsumerWithEx<F, S> {
/**
* Performs this operation on the given arguments.
*
@@ -346,7 +342,7 @@ public abstract class ProviderBase {
}
@FunctionalInterface
- public static interface Updater {
+ public interface Updater {
boolean apply(PdpGroup group, PdpSubGroup subgroup) throws PfModelException;
}
}
diff --git a/main/src/main/resources/application.yaml b/main/src/main/resources/application.yaml
index 2711e2d1..ee6383f5 100644
--- a/main/src/main/resources/application.yaml
+++ b/main/src/main/resources/application.yaml
@@ -90,4 +90,5 @@ management:
base-path: /
exposure:
include: health, metrics, prometheus
+ path-mapping.metrics: plain-metrics
path-mapping.prometheus: metrics