diff options
author | Dan Timoney <dtimoney@att.com> | 2022-10-19 13:27:45 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-10-19 13:27:45 +0000 |
commit | def97cb71a69a8320b1e8bd3f2220978fe8fb34f (patch) | |
tree | 87a727320e2e2c8ddbcdbc83be0647d7c0b8168c /a1-policy-management/src | |
parent | 390e82aa57f6a563d274fd0e3c26ca858c5abebc (diff) | |
parent | 8eadcb635a4d3dfaa7f2ac83f4081120a62e1781 (diff) |
Merge "Metrics and statistics for A1 PMS"
Diffstat (limited to 'a1-policy-management/src')
6 files changed, 236 insertions, 8 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java index bf161954..8fc8bc8c 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java @@ -21,7 +21,6 @@ package org.onap.ccsdk.oran.a1policymanagementservice; import com.fasterxml.jackson.databind.ObjectMapper; - import org.apache.catalina.connector.Connector; import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory; import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java index 500ddd2a..ee2cae58 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java @@ -22,7 +22,6 @@ package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2; import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; @@ -30,15 +29,12 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; - import java.lang.invoke.MethodHandles; import java.time.Instant; import java.util.ArrayList; import java.util.Collection; import java.util.List; - import lombok.Getter; - import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse; import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.EntityNotFoundException; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTask.java new file mode 100644 index 00000000..8eb8fbcb --- /dev/null +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTask.java @@ -0,0 +1,78 @@ +/*- + * ========================LICENSE_START================================= + * ONAP : ccsdk oran + * ====================================================================== + * Copyright (C) 2022 Nordix Foundation. All rights reserved. + * ====================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + * ========================LICENSE_END=================================== + */ + +package org.onap.ccsdk.oran.a1policymanagementservice.tasks; + +import io.micrometer.core.instrument.MeterRegistry; +import java.lang.invoke.MethodHandles; +import java.util.concurrent.atomic.AtomicLong; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +/** + * The aim is to collect statistical values from the A1 Policy Management Service. + * The counters are being updated every minute. + */ +@EnableScheduling +@Component +public class RefreshCounterTask { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + private final Rics rics; + private final PolicyTypes policyTypes; + private final Policies policies; + + private final MeterRegistry meterRegistry; + + private final AtomicLong ricCount; + private final AtomicLong policyTypeCount; + private final AtomicLong policyCount; + + @Autowired + public RefreshCounterTask(Rics rics, PolicyTypes policyTypes, Policies policies, MeterRegistry meterRegistry) { + this.rics = rics; + this.policyTypes = policyTypes; + this.policies = policies; + this.meterRegistry = meterRegistry; + + ricCount = meterRegistry.gauge("total_ric_count", new AtomicLong(0)); + policyTypeCount = meterRegistry.gauge("total_policy_type_count", new AtomicLong(0)); + policyCount = meterRegistry.gauge("total_policy_count", new AtomicLong(0)); + } + + /** + * Every minute, updates counters for statistical purposes. + */ + @Scheduled(fixedRate = 1000 * 60) + public void checkAllCounters() { + logger.trace("Checking counters starting..."); + ricCount.set(rics.size()); + policyCount.set(policies.size()); + policyTypeCount.set(policyTypes.size()); + } +} diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java index e3edaf44..7a5f73d4 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java @@ -21,7 +21,6 @@ package org.onap.ccsdk.oran.a1policymanagementservice.tasks; import java.util.Collection; - import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client; import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory; import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory; @@ -41,7 +40,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; - import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -181,6 +179,7 @@ public class RicSupervision { return Mono.error(new SynchNeededException(ric)); } } + return Mono.just(ric); } } @@ -204,6 +203,7 @@ public class RicSupervision { return Mono.error(new SynchNeededException(ric)); } } + return Mono.just(ric); } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java new file mode 100644 index 00000000..3adfb316 --- /dev/null +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java @@ -0,0 +1,156 @@ +/*- + * ========================LICENSE_START================================= + * ONAP : ccsdk oran + * ====================================================================== + * Copyright (C) 2022 Nordix Foundation. All rights reserved. + * ====================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + * ========================LICENSE_END=================================== + */ + +package org.onap.ccsdk.oran.a1policymanagementservice.tasks; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.spy; + +import io.micrometer.prometheus.PrometheusConfig; +import io.micrometer.prometheus.PrometheusMeterRegistry; +import java.time.Instant; +import java.util.Arrays; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig; +import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics; + +@ExtendWith(MockitoExtension.class) +public class RefreshCounterTaskTest { + + private static final String POLICY_TYPE_1_NAME = "type1"; + private static final PolicyType POLICY_TYPE_1 = PolicyType.builder().id(POLICY_TYPE_1_NAME).schema("").build(); + + private static final Ric RIC_1 = new Ric(RicConfig.builder().ricId("ric_1").baseUrl("baseUrl1") + .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))).controllerName("controllerName") + .build()); + + private static final String POLICY_1_ID = "policyId1"; + private static final Policy POLICY_1 = Policy.builder().id(POLICY_1_ID).json("").ownerServiceId("service") + .ric(RIC_1).type(POLICY_TYPE_1).lastModified(Instant.now()).isTransient(false) + .statusNotificationUri("statusNotificationUri").build(); + + private PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); + private final ApplicationConfig appConfig = new ApplicationConfig(); + + private PolicyTypes types; + private Policies policies; + private Rics rics = new Rics(); + + @BeforeEach + void init() { + types = new PolicyTypes(appConfig); + policies = new Policies(appConfig); + + rics.clear(); + RIC_1.setState(Ric.RicState.AVAILABLE); + RIC_1.clearSupportedPolicyTypes(); + } + + @Test + void testCounters_whenNeitherChangedPoliciesNorPolicyTypes() { + RIC_1.setState(Ric.RicState.AVAILABLE); + RIC_1.addSupportedPolicyType(POLICY_TYPE_1); + rics.put(RIC_1); + + types.put(POLICY_TYPE_1); + + policies.put(POLICY_1); + + RefreshCounterTask refreshCounterTaskUnderTest = spy(createRefreshCounterTask()); + refreshCounterTaskUnderTest.checkAllCounters(); + + assertThat(prometheusMeterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1); + assertThat(prometheusMeterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(1); + assertThat(prometheusMeterRegistry.get("total_policy_count").gauge().value()).isEqualTo(1); + } + + @Test + void testCounters_whenChangedPoliciesAndNoChangedPolicyTypes() { + RIC_1.setState(Ric.RicState.AVAILABLE); + RIC_1.addSupportedPolicyType(POLICY_TYPE_1); + rics.put(RIC_1); + + types.put(POLICY_TYPE_1); + + policies.put(POLICY_1); + + String POLICY_2_ID = "policyId2"; + Policy POLICY_2 = Policy.builder() // + .id(POLICY_2_ID) // + .json("") // + .ownerServiceId("service") // + .ric(RIC_1) // + .type(POLICY_TYPE_1) // + .lastModified(Instant.now()) // + .isTransient(false) // + .statusNotificationUri("statusNotificationUri") // + .build(); + + policies.put(POLICY_2); + + RefreshCounterTask refreshCounterTaskUnderTest = spy(createRefreshCounterTask()); + refreshCounterTaskUnderTest.checkAllCounters(); + + assertThat(prometheusMeterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1); + assertThat(prometheusMeterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(1); + assertThat(prometheusMeterRegistry.get("total_policy_count").gauge().value()).isEqualTo(2); + } + + @Test + void testCounters_whenNoChangedPoliciesAndChangedPolicyTypes() { + RIC_1.setState(Ric.RicState.AVAILABLE); + + String POLICY_TYPE_2_NAME = "type2"; + PolicyType POLICY_TYPE_2 = PolicyType.builder() // + .id(POLICY_TYPE_2_NAME) // + .schema("") // + .build(); + + RIC_1.addSupportedPolicyType(POLICY_TYPE_1); + RIC_1.addSupportedPolicyType(POLICY_TYPE_2); + rics.put(RIC_1); + + types.put(POLICY_TYPE_1); + types.put(POLICY_TYPE_2); + + policies.put(POLICY_1); + + RefreshCounterTask refreshCounterTaskUnderTest = spy(createRefreshCounterTask()); + refreshCounterTaskUnderTest.checkAllCounters(); + + assertThat(prometheusMeterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1); + assertThat(prometheusMeterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(2); + assertThat(prometheusMeterRegistry.get("total_policy_count").gauge().value()).isEqualTo(1); + } + + private RefreshCounterTask createRefreshCounterTask() { + return new RefreshCounterTask(rics, types, policies, prometheusMeterRegistry); + } +} diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java index b2bf58e4..d9b36d9c 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java @@ -34,7 +34,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Vector; - import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; |