diff options
12 files changed, 509 insertions, 0 deletions
@@ -39,6 +39,7 @@ <commons-text.version>1.6</commons-text.version> <jetbrains-annotations.version>16.0.3</jetbrains-annotations.version> <protoc-jar-maven-plugin.version>3.6.0.2</protoc-jar-maven-plugin.version> + <micrometer.version>1.1.4</micrometer.version> </properties> <modules> @@ -211,6 +212,11 @@ <version>${logback.version}</version> <scope>runtime</scope> </dependency> + <dependency> + <groupId>io.micrometer</groupId> + <artifactId>micrometer-registry-prometheus</artifactId> + <version>${micrometer.version}</version> + </dependency> <dependency> <groupId>org.mockito</groupId> @@ -225,6 +231,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <version>${junit-jupiter.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>${assertj-core.version}</version> diff --git a/standardization/moher-api/healthstate/pom.xml b/standardization/moher-api/healthstate/pom.xml new file mode 100644 index 00000000..d6cf46be --- /dev/null +++ b/standardization/moher-api/healthstate/pom.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ============LICENSE_START======================================================= + ~ DCAEGEN2-SERVICES-SDK + ~ ================================================================================ + ~ Copyright (C) 2019 Nokia + ~ ================================================================================ + ~ 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========================================================= + --> +<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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>dcaegen2-sdk-moher-api</artifactId> + <groupId>org.onap.dcaegen2.services.sdk</groupId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + <name>Monitoring and Healthcheck :: Health state</name> + <description>MoHeR standardization for providing application state</description> + <artifactId>dcaegen2-sdk-moher-healthstate</artifactId> + + +</project>
\ No newline at end of file diff --git a/standardization/moher-api/metrics/pom.xml b/standardization/moher-api/metrics/pom.xml new file mode 100644 index 00000000..fd0c9678 --- /dev/null +++ b/standardization/moher-api/metrics/pom.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ============LICENSE_START======================================================= + ~ DCAEGEN2-SERVICES-SDK + ~ ================================================================================ + ~ Copyright (C) 2019 Nokia + ~ ================================================================================ + ~ 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========================================================= + --> +<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"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>dcaegen2-sdk-moher-api</artifactId> + <groupId>org.onap.dcaegen2.services.sdk</groupId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + <name>Monitoring and Healthcheck :: Metrics</name> + <description>MoHeR standardization for providing application metrics</description> + <artifactId>dcaegen2-sdk-moher-metrics</artifactId> + + <dependencies> + <dependency> + <groupId>io.micrometer</groupId> + <artifactId>micrometer-registry-prometheus</artifactId> + </dependency> + <dependency> + <groupId>io.projectreactor</groupId> + <artifactId>reactor-core</artifactId> + </dependency> + + <dependency> + <groupId>io.projectreactor</groupId> + <artifactId>reactor-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/standardization/moher-api/metrics/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/api/Metrics.java b/standardization/moher-api/metrics/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/api/Metrics.java new file mode 100644 index 00000000..66c33680 --- /dev/null +++ b/standardization/moher-api/metrics/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/api/Metrics.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. 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.dcaegen2.services.sdk.standardization.moher.metrics.api; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.time.Duration; + +/** + * Object responsible for returning application metrics. + * + * @since 1.2.0 + */ +public interface Metrics { + + /** + * Return all gathered metrics. + * + * Returns a Publisher that will emit a single string containing all + * metrics with current values and finish afterwards. + * + * @since 1.2.0 + */ + Mono<String> collect(); + + /** + * Returns all gathered metrics. + * + * Returns a Publisher that will emit string containing all metrics with current values in intervals. + * + * @param interval interval in which Publisher should return metrics + * @since 1.2.0 + */ + Flux<String> collect(Duration interval); +}
\ No newline at end of file diff --git a/standardization/moher-api/metrics/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/api/MetricsFactory.java b/standardization/moher-api/metrics/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/api/MetricsFactory.java new file mode 100644 index 00000000..359f7470 --- /dev/null +++ b/standardization/moher-api/metrics/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/api/MetricsFactory.java @@ -0,0 +1,61 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. 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.dcaegen2.services.sdk.standardization.moher.metrics.api; + +import io.micrometer.prometheus.PrometheusConfig; +import io.micrometer.prometheus.PrometheusMeterRegistry; +import org.onap.dcaegen2.services.sdk.standardization.moher.metrics.impl.MetricsImpl; + +/** + * Factory for creating {@link Metrics} object. + * + * <p>Typical usage:</p> + * + * <pre> + * // create registry + * PrometheusMeterRegistry registry = MetricsFactory.createDefaultRegistry(); + * // create metrics + * Metrics metrics = MetricsFactory.createMetrics(registry); + * </pre> + * + * @since 1.2.0 + */ +public class MetricsFactory { + + /** + * Method for creating default Prometheus registry. + * + * @since 1.2.0 + */ + public static PrometheusMeterRegistry createDefaultRegistry() { + return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); + } + + /** + * Method for creating {@link Metrics} with configured Prometheus registry. + * + * @param registry Prometheus registry to be used + * @since 1.2.0 + */ + public static Metrics createMetrics(PrometheusMeterRegistry registry) { + return new MetricsImpl(registry); + } +} diff --git a/standardization/moher-api/metrics/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/impl/MetricsImpl.java b/standardization/moher-api/metrics/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/impl/MetricsImpl.java new file mode 100644 index 00000000..068a2db4 --- /dev/null +++ b/standardization/moher-api/metrics/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/impl/MetricsImpl.java @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. 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.dcaegen2.services.sdk.standardization.moher.metrics.impl; + + +import io.micrometer.prometheus.PrometheusMeterRegistry; +import org.onap.dcaegen2.services.sdk.standardization.moher.metrics.api.Metrics; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.time.Duration; + +public class MetricsImpl implements Metrics { + private final PrometheusMeterRegistry registry; + + public MetricsImpl(PrometheusMeterRegistry registry) { + this.registry = registry; + } + + @Override + public Mono<String> collect() { + return Mono.just(registry.scrape()); + } + + @Override + public Flux<String> collect(Duration interval) { + return Flux.interval(interval) + .map((l) -> registry.scrape()); + } +} diff --git a/standardization/moher-api/metrics/src/test/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/impl/MetricsIT.java b/standardization/moher-api/metrics/src/test/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/impl/MetricsIT.java new file mode 100644 index 00000000..f04636e9 --- /dev/null +++ b/standardization/moher-api/metrics/src/test/java/org/onap/dcaegen2/services/sdk/standardization/moher/metrics/impl/MetricsIT.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. 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.dcaegen2.services.sdk.standardization.moher.metrics.impl; + +import io.micrometer.core.instrument.Counter; +import io.micrometer.prometheus.PrometheusMeterRegistry; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.standardization.moher.metrics.api.Metrics; +import org.onap.dcaegen2.services.sdk.standardization.moher.metrics.api.MetricsFactory; +import reactor.test.StepVerifier; + +import java.time.Duration; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +class MetricsIT { + + private static final String COUNTER_NAME = "Duplicates_Amount"; + private static final String GAUGE_NAME = "gauge_Duplicates_Amount"; + private static final String TIMER_NAME = "Duplicates_Amount_timer"; + private static final String SUMMARY_NAME = "Duplicates_Amount_summary"; + private static final Duration INTERVAL = Duration.ofMillis(100); + + private PrometheusMeterRegistry defaultRegistry; + private Metrics cut; + + @BeforeEach + void setup() { + defaultRegistry = MetricsFactory.createDefaultRegistry(); + cut = MetricsFactory.createMetrics(defaultRegistry); + } + + @Test + void metrics_givenDefaultRegistry_shouldReturnCreatedMeters() { + + Counter counter = defaultRegistry.counter(COUNTER_NAME); + defaultRegistry.gauge(GAUGE_NAME, counter.count()); + defaultRegistry.timer(TIMER_NAME); + defaultRegistry.summary(SUMMARY_NAME); + + StepVerifier.create(cut.collect()) + .expectNextMatches((collectedMetrics) -> + collectedMetrics.contains(COUNTER_NAME) && + collectedMetrics.contains(GAUGE_NAME) && + collectedMetrics.contains(TIMER_NAME) && + collectedMetrics.contains(SUMMARY_NAME) + ) + .verifyComplete(); + } + + @Test + void metrics_givenDefaultRegistry_shouldReturnCreatedMetersInIntervals() { + + Counter counter = defaultRegistry.counter(COUNTER_NAME); + + StepVerifier.create( + cut.collect(INTERVAL).take(2) + ) + .consumeNextWith((collectedMetrics) -> { + assertTrue(collectedMetrics.contains(COUNTER_NAME)); + counter.increment(); + }) + .thenAwait(INTERVAL) + .expectNextMatches((collectedMetrics) -> + collectedMetrics.contains(COUNTER_NAME + "_total 1.0")) + .verifyComplete(); + } +} diff --git a/standardization/moher-api/pom.xml b/standardization/moher-api/pom.xml new file mode 100644 index 00000000..b4276d7e --- /dev/null +++ b/standardization/moher-api/pom.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ============LICENSE_START======================================================= + ~ DCAEGEN2-SERVICES-SDK + ~ ================================================================================ + ~ Copyright (C) 2019 Nokia + ~ ================================================================================ + ~ 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========================================================= + --> +<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"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>dcaegen2-services-sdk-standardization</artifactId> + <groupId>org.onap.dcaegen2.services.sdk</groupId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + <name>Monitoring and Healthcheck</name> + <description>Monitoring and Healthcheck REST API standardization</description> + <artifactId>dcaegen2-sdk-moher-api</artifactId> + <packaging>pom</packaging> + + <modules> + <module>metrics</module> + <module>healthstate</module> + <module>server-adapters</module> + </modules> +</project>
\ No newline at end of file diff --git a/standardization/moher-api/server-adapters/pom.xml b/standardization/moher-api/server-adapters/pom.xml new file mode 100644 index 00000000..4b8f4a55 --- /dev/null +++ b/standardization/moher-api/server-adapters/pom.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ============LICENSE_START======================================================= + ~ DCAEGEN2-SERVICES-SDK + ~ ================================================================================ + ~ Copyright (C) 2019 Nokia + ~ ================================================================================ + ~ 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========================================================= + --> +<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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>dcaegen2-sdk-moher-api</artifactId> + <groupId>org.onap.dcaegen2.services.sdk</groupId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + <name>Monitoring and Healthcheck :: Server Adapters</name> + <description>Server adapters for incorporating standardized REST endpoints for healthcheck and monitoring + </description> + <artifactId>dcaegen2-sdk-moher-server-adapters</artifactId> + <packaging>pom</packaging> + + <modules> + <module>spring</module> + <module>reactor-netty</module> + </modules> +</project>
\ No newline at end of file diff --git a/standardization/moher-api/server-adapters/reactor-netty/pom.xml b/standardization/moher-api/server-adapters/reactor-netty/pom.xml new file mode 100644 index 00000000..f2f37412 --- /dev/null +++ b/standardization/moher-api/server-adapters/reactor-netty/pom.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ============LICENSE_START======================================================= + ~ DCAEGEN2-SERVICES-SDK + ~ ================================================================================ + ~ Copyright (C) 2019 Nokia + ~ ================================================================================ + ~ 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========================================================= + --> +<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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>dcaegen2-sdk-moher-server-adapters</artifactId> + <groupId>org.onap.dcaegen2.services.sdk</groupId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + <name>Monitoring and Healthcheck :: Server Adapters :: Reactor Netty</name> + <description>MoHeR Project Reactor's Netty server adapter</description> + <artifactId>dcae-sdk-moher-reactor-netty</artifactId> + +</project>
\ No newline at end of file diff --git a/standardization/moher-api/server-adapters/spring/pom.xml b/standardization/moher-api/server-adapters/spring/pom.xml new file mode 100644 index 00000000..52f1dad2 --- /dev/null +++ b/standardization/moher-api/server-adapters/spring/pom.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ============LICENSE_START======================================================= + ~ DCAEGEN2-SERVICES-SDK + ~ ================================================================================ + ~ Copyright (C) 2019 Nokia + ~ ================================================================================ + ~ 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========================================================= + --> +<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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>dcaegen2-sdk-moher-server-adapters</artifactId> + <groupId>org.onap.dcaegen2.services.sdk</groupId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + <name>Monitoring and Healthcheck :: Server Adapters :: Spring</name> + <description>MoHeR Spring server adapter</description> + <artifactId>dcae-sdk-moher-spring</artifactId> + +</project>
\ No newline at end of file diff --git a/standardization/pom.xml b/standardization/pom.xml index 0d1e3b3d..b37e296c 100644 --- a/standardization/pom.xml +++ b/standardization/pom.xml @@ -21,6 +21,7 @@ <modules> <module>api-custom-header</module> + <module>moher-api</module> </modules> </project> |