public static final String REG_STATISTICS_MANAGER = "object:manager/statistics";
public static final String REG_PDP_MODIFY_LOCK = "lock:pdp";
public static final String REG_PDP_MODIFY_MAP = "object:pdp/modify/map";
+ public static final String REG_METER_REGISTRY = "object:meter/registry";
// topic names
public static final String TOPIC_POLICY_PDP_PAP = "POLICY-PDP-PAP";
package org.onap.policy.pap.main.notification;
+import io.micrometer.core.instrument.MeterRegistry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.Getter;
+import org.onap.policy.common.utils.resources.PrometheusUtils;
+import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pap.concepts.PolicyNotification;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.State;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.pap.main.PapConstants;
import org.onap.policy.pap.main.notification.StatusAction.Action;
import org.onap.policy.pap.main.service.PolicyStatusService;
* </ol>
*/
public class DeploymentStatus {
+
/**
* Tracks the groups that have been loaded.
*/
public void flush(PolicyNotification notif) {
// must add notifications BEFORE deleting undeployments
addNotifications(notif);
+ updateMetrics();
deleteUndeployments();
flush();
}
}
}
+ private void updateMetrics() {
+ MeterRegistry meterRegistry = Registry.get(PapConstants.REG_METER_REGISTRY, MeterRegistry.class);
+ String counterName = "pap_" + PrometheusUtils.POLICY_DEPLOYMENTS_METRIC;
+ recordMap.forEach((key, value) -> {
+ if (value.getAction().equals(StatusAction.Action.UPDATED)) {
+ if (value.getStatus().getState().equals(State.SUCCESS)) {
+ meterRegistry.counter(counterName, PrometheusUtils.OPERATION_METRIC_LABEL,
+ value.getStatus().isDeploy() ? PrometheusUtils.DEPLOY_OPERATION
+ : PrometheusUtils.UNDEPLOY_OPERATION,
+ PrometheusUtils.STATUS_METRIC_LABEL, State.SUCCESS.name()).increment();
+ } else if (value.getStatus().getState().equals(State.FAILURE)) {
+ meterRegistry.counter(counterName, PrometheusUtils.OPERATION_METRIC_LABEL,
+ value.getStatus().isDeploy() ? PrometheusUtils.DEPLOY_OPERATION
+ : PrometheusUtils.UNDEPLOY_OPERATION,
+ PrometheusUtils.STATUS_METRIC_LABEL, State.FAILURE.name()).increment();
+ }
+ }
+ });
+ }
+
/**
* Deletes records for any policies that have been completely undeployed.
*/
package org.onap.policy.pap.main.startstop;
+import io.micrometer.core.instrument.MeterRegistry;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
* @param papParameterGroup the parameters for the pap service
*/
public PapActivator(PapParameterGroup papParameterGroup, PolicyNotifier policyNotifier,
- PdpHeartbeatListener pdpHeartbeatListener, PdpModifyRequestMap pdpModifyRequestMap) {
+ PdpHeartbeatListener pdpHeartbeatListener, PdpModifyRequestMap pdpModifyRequestMap,
+ MeterRegistry meterRegistry) {
super("Policy PAP");
this.papParameterGroup = papParameterGroup;
TopicEndpointManager.getManager().addTopics(papParameterGroup.getTopicParameterGroup());
final AtomicReference<PdpModifyRequestMap> requestMap = new AtomicReference<>();
// @formatter:off
+
+ addAction("Meter Registry",
+ () -> Registry.register(PapConstants.REG_METER_REGISTRY, meterRegistry),
+ () -> Registry.unregister(PapConstants.REG_METER_REGISTRY));
+
addAction("PAP parameters",
() -> ParameterService.register(papParameterGroup),
() -> ParameterService.deregister(papParameterGroup.getName()));
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import lombok.NonNull;
import org.apache.commons.lang3.builder.CompareToBuilder;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pap.concepts.PolicyNotification;
import org.onap.policy.models.pap.concepts.PolicyStatus;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.PdpPolicyStatusBuilder;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.State;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.pap.main.PapConstants;
import org.onap.policy.pap.main.notification.StatusAction.Action;
import org.onap.policy.pap.main.service.PolicyStatusService;
private DeploymentStatus tracker;
+ /**
+ * Set up the meter registry for tests.
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() {
+ Registry.register(PapConstants.REG_METER_REGISTRY, new SimpleMeterRegistry());
+ }
+
+ /**
+ * Tear down the meter registry after tests.
+ */
+ @AfterClass
+ public static void tearDownAfterClass() {
+ Registry.unregister(PapConstants.REG_METER_REGISTRY);
+ }
+
/**
* Sets up.
*/
.deploy(true)
.state(State.SUCCESS);
// @formatter:on
+
}
@Test
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import io.micrometer.core.instrument.MeterRegistry;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
protected PdpModifyRequestMap reqmap;
protected ToscaPolicy policy1;
protected PapStatisticsManager statsmanager;
+ protected MeterRegistry meterRegistry;
/**
* Configures DAO, captors, and various mocks.
policy1 = loadPolicy("policy.json");
statsmanager = mock(PapStatisticsManager.class);
+ meterRegistry = mock(MeterRegistry.class);
+
List<PdpGroup> groups = loadGroups("groups.json");
when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(groups);
Registry.register(PapConstants.REG_PDP_MODIFY_LOCK, lockit);
Registry.register(PapConstants.REG_PDP_MODIFY_MAP, reqmap);
Registry.register(PapConstants.REG_STATISTICS_MANAGER, statsmanager);
+ Registry.register(PapConstants.REG_METER_REGISTRY, meterRegistry);
+
}
/**
package org.onap.policy.pap.main.rest.e2e;
+import io.micrometer.core.instrument.MeterRegistry;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.PrometheusUtils;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroups;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
+import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.State;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@Autowired
public ToscaServiceTemplateService toscaService;
+ @Autowired
+ public MeterRegistry meterRegistry;
+
+ public String deploymentsCounterName = "pap_" + PrometheusUtils.POLICY_DEPLOYMENTS_METRIC;
+ public String[] deploymentSuccessTag = {PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.DEPLOY_OPERATION,
+ PrometheusUtils.STATUS_METRIC_LABEL, State.SUCCESS.name()};
+ public String[] unDeploymentSuccessTag = {PrometheusUtils.OPERATION_METRIC_LABEL,
+ PrometheusUtils.UNDEPLOY_OPERATION, PrometheusUtils.STATUS_METRIC_LABEL, State.SUCCESS.name()};
+
/**
* Tears down.
*/
}
context = null;
}
-
+ meterRegistry.clear();
super.tearDown();
}
package org.onap.policy.pap.main.rest.e2e;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
assertEquals(0, deleted.getIncompleteCount());
assertEquals(new ToscaConceptIdentifier("onap.restart.tcaB", "1.0.0"), deleted.getPolicy());
+ assertThat(meterRegistry.counter(deploymentsCounterName, unDeploymentSuccessTag).count()).isEqualTo(2);
+
rawresp = invocationBuilder.delete();
resp = rawresp.readEntity(PdpGroupDeployResponse.class);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
package org.onap.policy.pap.main.rest.e2e;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
assertNull(resp.getErrorDetails());
+ assertThat(meterRegistry.counter(deploymentsCounterName, deploymentSuccessTag).count()).isEqualTo(2);
+
// repeat with unknown group - should fail
DeploymentGroup group = groups.getGroups().get(0);
group.setName("unknown-group");
notifications.add(msg);
});
+ assertThat(meterRegistry.counter(deploymentsCounterName, deploymentSuccessTag).count()).isEqualTo(0);
+
Invocation.Builder invocationBuilder = sendRequest(DEPLOY_POLICIES_ENDPOINT);
PdpDeployPolicies policies = loadJsonFile("deployPoliciesReq2.json", PdpDeployPolicies.class);
resp = rawresp.readEntity(PdpGroupDeployResponse.class);
assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
assertNull(resp.getErrorDetails());
+
+ assertThat(meterRegistry.counter(deploymentsCounterName, deploymentSuccessTag).count()).isEqualTo(2);
}
}
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;
final PapParameterGroup parGroup = new CommonTestData().getPapParameterGroup(6969);
activator = new PapActivator(parGroup, new PolicyNotifier(null), new PdpHeartbeatListener(),
- new PdpModifyRequestMap(null, null, null, null, null));
+ new PdpModifyRequestMap(null, null, null, null, null), new SimpleMeterRegistry());
}