summaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-04-06 15:42:02 +0100
committerMichael Morris <michael.morris@est.tech>2022-04-14 23:11:10 +0000
commite02ad3ed9ce507d8b78cc511ea1832a86f77c274 (patch)
tree1adb781b5314b3f36b81f533316860f8040a824d /openecomp-be
parenteb8de3664309f577362df7710d6cd93d00a734e2 (diff)
Add application metrics in the onboarding backend
A new endpoint was introduced /onboarding-api/v1.0/actuator/prometheus in the onboarding backend, that returns application metrics in a format consumable by prometheus, using the micrometer library. Change-Id: I684b5cab55947c6bedee1b838343676489ad3ebf Issue-ID: SDC-3956 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/pom.xml68
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/config/MicrometerSpringConfig.java38
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/metrics/api/PrometheusMetricsController.java42
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/metrics/impl/PrometheusMetricControllerImpl.java69
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/pom.xml5
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml1
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/pom.xml1
7 files changed, 224 insertions, 0 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/pom.xml
new file mode 100644
index 0000000000..d5d022f6fe
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ -
+ ~ ============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=========================================================
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-rest-webapp</artifactId>
+ <version>1.11.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>metrics-rest</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>${ws.rs.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.micrometer</groupId>
+ <artifactId>micrometer-registry-prometheus</artifactId>
+ <version>${micrometer.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.swagger.core.v3</groupId>
+ <artifactId>swagger-annotations</artifactId>
+ <version>${swagger.version}</version>
+ </dependency>
+ </dependencies>
+
+</project> \ No newline at end of file
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/config/MicrometerSpringConfig.java b/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/config/MicrometerSpringConfig.java
new file mode 100644
index 0000000000..847f6bcf0d
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/config/MicrometerSpringConfig.java
@@ -0,0 +1,38 @@
+/*
+ * -
+ * ============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.openecomp.sdcrests.config;
+
+import io.micrometer.prometheus.PrometheusConfig;
+import io.micrometer.prometheus.PrometheusMeterRegistry;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MicrometerSpringConfig {
+
+ @Bean(name = "prometheusRegistry")
+ PrometheusMeterRegistry prometheusRegistry() {
+ return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
+ }
+
+}
+
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/metrics/api/PrometheusMetricsController.java b/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/metrics/api/PrometheusMetricsController.java
new file mode 100644
index 0000000000..d7b6e36c61
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/metrics/api/PrometheusMetricsController.java
@@ -0,0 +1,42 @@
+/*
+ * -
+ * ============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.openecomp.sdcrests.metrics.api;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+
+@Path(PrometheusMetricsController.URL)
+@Tag(name = "SDCE-1 APIs")
+public interface PrometheusMetricsController {
+
+ String URL = "/v1.0/actuator/prometheus";
+
+ @GET
+ @Operation(summary = "Prometheus Micrometer Metrics", description = "Gets the prometheus micrometer application metrics")
+ String prometheusMetrics(@Parameter(description = "The Accept header to determine the output content type")
+ @HeaderParam(value = "Accept") String acceptHeader);
+
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/metrics/impl/PrometheusMetricControllerImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/metrics/impl/PrometheusMetricControllerImpl.java
new file mode 100644
index 0000000000..0472bc703b
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/metrics-rest/src/main/java/org/openecomp/sdcrests/metrics/impl/PrometheusMetricControllerImpl.java
@@ -0,0 +1,69 @@
+/*
+ * -
+ * ============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.openecomp.sdcrests.metrics.impl;
+
+import io.micrometer.core.instrument.binder.jetty.JettyConnectionMetrics;
+import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
+import io.micrometer.core.instrument.binder.jvm.JvmCompilationMetrics;
+import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
+import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
+import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
+import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics;
+import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
+import io.micrometer.core.instrument.binder.system.UptimeMetrics;
+import io.micrometer.prometheus.PrometheusMeterRegistry;
+import io.prometheus.client.exporter.common.TextFormat;
+import org.openecomp.sdcrests.metrics.api.PrometheusMetricsController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController("prometheusMetricsController")
+public class PrometheusMetricControllerImpl implements PrometheusMetricsController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(PrometheusMetricControllerImpl.class);
+
+ private final PrometheusMeterRegistry prometheusMeterRegistry;
+
+ public PrometheusMetricControllerImpl(final PrometheusMeterRegistry prometheusMeterRegistry) {
+ this.prometheusMeterRegistry = prometheusMeterRegistry;
+ new ClassLoaderMetrics().bindTo(prometheusMeterRegistry);
+ try (final JvmGcMetrics jvmGcMetrics = new JvmGcMetrics()) {
+ jvmGcMetrics.bindTo(prometheusMeterRegistry);
+ } catch (final Exception e) {
+ LOGGER.error("Could not instantiate the JVM GC Metrics", e);
+ }
+ new JvmMemoryMetrics().bindTo(prometheusMeterRegistry);
+ new JvmCompilationMetrics().bindTo(prometheusMeterRegistry);
+ new JvmThreadMetrics().bindTo(prometheusMeterRegistry);
+ new ProcessorMetrics().bindTo(prometheusMeterRegistry);
+ new UptimeMetrics().bindTo(prometheusMeterRegistry);
+ new FileDescriptorMetrics().bindTo(prometheusMeterRegistry);
+ new JettyConnectionMetrics(prometheusMeterRegistry);
+ }
+
+ @Override
+ public String prometheusMetrics(final String acceptHeader) {
+ return prometheusMeterRegistry.scrape(TextFormat.chooseContentType(acceptHeader));
+ }
+
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/pom.xml
index 09235e5f5c..9d5f962643 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/pom.xml
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/pom.xml
@@ -96,6 +96,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>metrics-rest</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml
index f4a84a0056..8c005f0169 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/beans-services.xml
@@ -84,6 +84,7 @@
<ref bean="togglz"/>
<ref bean="items"/>
<ref bean="uniqueTypes"/>
+ <ref bean="prometheusMetricsController"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/pom.xml
index 1dccc5c188..6f8e69d8d7 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/pom.xml
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/pom.xml
@@ -29,6 +29,7 @@
<module>togglz-rest</module>
<module>unique-type-rest</module>
<module>externaltesting-rest</module>
+ <module>metrics-rest</module>
</modules>
</project>