Add Prometheus counters for AC element

Issue-ID: POLICY-4327
Change-Id: I8d17da711c8ba980e7f42ac611ee9bb858dccea9
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/MicrometerConfig.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/MicrometerConfig.java
new file mode 100644
index 0000000..8e83a77
--- /dev/null
+++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/MicrometerConfig.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.element.config;
+
+import io.micrometer.core.aop.TimedAspect;
+import io.micrometer.core.instrument.MeterRegistry;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MicrometerConfig {
+
+    @Bean
+    public TimedAspect timedAspect(MeterRegistry registry) {
+        return new TimedAspect(registry);
+    }
+}
diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageHandler.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageHandler.java
index 63b0ebc..906fc32 100644
--- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageHandler.java
+++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageHandler.java
@@ -20,12 +20,11 @@
 
 package org.onap.policy.clamp.acm.element.handler;
 
-import java.util.ArrayList;
+import io.micrometer.core.annotation.Timed;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import javax.ws.rs.core.Response;
-import lombok.Getter;
 import lombok.NonNull;
 import org.onap.policy.clamp.acm.element.main.parameters.AcElement;
 import org.onap.policy.clamp.acm.element.service.ElementService;
@@ -44,9 +43,6 @@
 
     private Map<ElementType, ElementService> map = new HashMap<>();
 
-    @Getter
-    private List<ElementMessage> messages = new ArrayList<>();
-
     /**
      * Constructor.
      *
@@ -99,8 +95,8 @@
         return service;
     }
 
+    @Timed(value = "listener.status", description = "STATUS messages received")
     public void handleMessage(ElementMessage message) {
-        messages.add(message);
         getActiveService().handleMessage(message);
     }
 
diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessagePublisher.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessagePublisher.java
index 928a4fe..1b0c223 100644
--- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessagePublisher.java
+++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessagePublisher.java
@@ -20,6 +20,7 @@
 
 package org.onap.policy.clamp.acm.element.handler;
 
+import io.micrometer.core.annotation.Timed;
 import java.util.List;
 import javax.ws.rs.core.Response;
 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
@@ -56,6 +57,7 @@
      *
      * @param msg the acknowledgement message
      */
+    @Timed(value = "publisher.status", description = "STATUS messages published")
     public void publishMsg(final ElementMessage msg) {
         if (!active) {
             throw new AutomationCompositionRuntimeException(Response.Status.CONFLICT, NOT_ACTIVE_TEXT);
diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/ConfigService.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/ConfigService.java
index f8f9024..4ffed19 100644
--- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/ConfigService.java
+++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/ConfigService.java
@@ -98,8 +98,4 @@
         elementConfig = new ElementConfig();
         LOGGER.info("Messages and service deactivated");
     }
-
-    public List<ElementMessage> getMessages() {
-        return handler.getMessages();
-    }
 }
diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java
index 84c6305..37d378b 100644
--- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java
+++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java
@@ -83,8 +83,6 @@
         var message = new ElementStatus();
         messageHandler.handleMessage(message);
         verify(bridge).handleMessage(message);
-        assertThat(messageHandler.getMessages()).hasSize(1);
-        assertThat(messageHandler.getMessages().get(0)).isEqualTo(message);
         messageHandler.deactivateElement();
     }
 
@@ -104,8 +102,6 @@
         var message = new ElementStatus();
         messageHandler.handleMessage(message);
         verify(sink).handleMessage(message);
-        assertThat(messageHandler.getMessages()).hasSize(1);
-        assertThat(messageHandler.getMessages().get(0)).isEqualTo(message);
         messageHandler.deactivateElement();
     }
 
diff --git a/participant/pom.xml b/participant/pom.xml
index 1e692eb..7f5a89a 100644
--- a/participant/pom.xml
+++ b/participant/pom.xml
@@ -116,6 +116,11 @@
             <artifactId>micrometer-registry-prometheus</artifactId>
             <version>${version.io.micrometer}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+            <version>${version.springboot}</version>
+        </dependency>
     </dependencies>
 
     <build>