diff options
author | halil.cakal <halil.cakal@est.tech> | 2022-09-29 09:47:09 +0100 |
---|---|---|
committer | halil.cakal <halil.cakal@est.tech> | 2022-10-17 10:28:51 +0100 |
commit | 8eadcb635a4d3dfaa7f2ac83f4081120a62e1781 (patch) | |
tree | b9a872c2c8982381209a2c506181d7174ef8cf82 /a1-policy-management/src/main/java | |
parent | 36f9bf4305ef193089330242c94d229f9310f69d (diff) |
Metrics and statistics for A1 PMS
Enable app metrics to be collected by Prometheus
Patch set 2: Remove hardcoded defines ccsdk.sli dependency
Issue-ID: CCSDK-3766
Change-Id: I58f05390007b74e58427b9be2711912c551d6e1e
Signed-off-by: halil.cakal <halil.cakal@est.tech>
Diffstat (limited to 'a1-policy-management/src/main/java')
4 files changed, 80 insertions, 7 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); } |