diff --git a/eng/jacoco-test-coverage/pom.xml b/eng/jacoco-test-coverage/pom.xml index 35456bd82a65..46ff5323c16a 100644 --- a/eng/jacoco-test-coverage/pom.xml +++ b/eng/jacoco-test-coverage/pom.xml @@ -212,6 +212,26 @@ azure-spring-boot 2.2.5-beta.1 + + com.microsoft.azure + azure-spring-boot-starter + 2.2.5-beta.1 + + + com.microsoft.azure + azure-active-directory-spring-boot-starter + 2.2.5-beta.1 + + + com.microsoft.azure + azure-spring-boot-metrics-starter + 2.2.5-beta.1 + + + com.microsoft.azure + azure-servicebus-jms-spring-boot-starter + 2.2.5-beta.1 + diff --git a/eng/versioning/external_dependencies.txt b/eng/versioning/external_dependencies.txt index 07ba36ba999b..e4368562b8a1 100644 --- a/eng/versioning/external_dependencies.txt +++ b/eng/versioning/external_dependencies.txt @@ -45,6 +45,7 @@ org.apache.logging.log4j:log4j-api;2.11.1 org.apache.logging.log4j:log4j-core;2.11.1 org.apache.logging.log4j:log4j-slf4j-impl;2.13.0 org.apache.qpid:proton-j;0.33.4 +org.apache.qpid:qpid-jms-client;0.43.0 org.asynchttpclient:async-http-client;2.10.5 org.codehaus.groovy:groovy-eclipse-batch;2.5.8-01 org.codehaus.groovy:groovy-eclipse-compiler;3.4.0-01 @@ -70,6 +71,7 @@ org.springframework.security:spring-security-oauth2-client;5.2.0.RELEASE org.springframework.security:spring-security-oauth2-core;5.2.0.RELEASE org.springframework.security:spring-security-oauth2-jose;5.2.0.RELEASE org.springframework:spring-web;5.2.5.RELEASE +org.springframework:spring-jms;5.2.5.RELEASE pl.pragmatists:JUnitParams;1.1.1 ## Test dependency versions @@ -227,3 +229,7 @@ media_com.microsoft.azure:adal4j;1.2.0 # sdk\storage\azure-storage-blob-cryptography\pom.xml storage_com.microsoft.azure:azure-storage;8.4.0 + +# sdk\spring\azure-spring-boot\pom.xml +spring_io.micrometer:micrometer-core;1.3.0 +spring_io.micrometer:micrometer-registry-azure-monitor;1.3.0 diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index 47727e35469e..8fcc84649f77 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -46,6 +46,8 @@ com.microsoft.azure:azure-spring-boot;2.2.4;2.2.5-beta.1 com.microsoft.azure:azure-spring-boot-starter;2.2.4;2.2.5-beta.1 com.microsoft.azure:azure-active-directory-spring-boot-starter;2.2.4;2.2.5-beta.1 com.microsoft.azure:azure-keyvault-secrets-spring-boot-starter;2.2.4;2.2.5-beta.1 +com.microsoft.azure:azure-servicebus-jms-spring-boot-starter;2.2.4;2.2.5-beta.1 +com.microsoft.azure:azure-spring-boot-metrics-starter;2.2.4;2.2.5-beta.1 # Unreleased dependencies: Copy the entry from above, prepend "unreleased_" and remove the current # version. Unreleased dependencies are only valid for dependency versions. diff --git a/sdk/spring/README.md b/sdk/spring/README.md index 16b0600e60fd..3c908180e664 100644 --- a/sdk/spring/README.md +++ b/sdk/spring/README.md @@ -30,7 +30,7 @@ Starter Name | Version for Spring Boot 2.2.x | Version for Spring Boot 2.1.x | V [azure-servicebus-spring-boot-starter](azure-spring-boot-starter-servicebus/README.md) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-servicebus-spring-boot-starter.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.microsoft.azure%22%20AND%20a%3A%22azure-servicebus-spring-boot-starter%22) | [![](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-servicebus-spring-boot-starter/2.1.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:azure-servicebus-spring-boot-starter%20AND%20v:2.1.*) | [![](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-servicebus-spring-boot-starter/2.0.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:azure-servicebus-spring-boot-starter%20AND%20v:2.0.*) [spring-data-gremlin-boot-starter](azure-spring-boot-starter-data-gremlin/README.md) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/spring-data-gremlin-boot-starter.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.microsoft.azure%22%20AND%20a%3A%22spring-data-gremlin-boot-starter%22) | [![](https://img.shields.io/maven-central/v/com.microsoft.azure/spring-data-gremlin-boot-starter/2.1.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:spring-data-gremlin-boot-starter%20AND%20v:2.1.*) | [![](https://img.shields.io/maven-central/v/com.microsoft.azure/spring-data-gremlin-boot-starter/2.0.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:spring-data-gremlin-boot-starter%20AND%20v:2.0.*) [azure-spring-boot-metrics-starter](azure-spring-boot-starter-metrics) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-spring-boot-metrics-starter.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.microsoft.azure%22%20AND%20a%3A%22azure-spring-boot-metrics-starter%22) | [![](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-spring-boot-metrics-starter/2.1.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:azure-spring-boot-metrics-starter%20AND%20v:2.1.*) | [![](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-spring-boot-metrics-starter/2.0.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:azure-spring-boot-metrics-starter%20AND%20v:2.0.*) -[azure-servicebus-jms-spring-boot-starter](azure-spring-boot-starter-servicebus-jms/README.md) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-servicebus-jms-spring-boot-starter.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.microsoft.azure%22%20AND%20a%3A%22azure-servicebus-jms-spring-boot-starter%22) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-servicebus-jms-spring-boot-starter/2.1.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:azure-servicebus-jms-spring-boot-starter%20AND%20v:2.1.*) | N/A +[azure-servicebus-jms-spring-boot-starter](azure-servicebus-jms-spring-boot-starter/README.md) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-servicebus-jms-spring-boot-starter.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.microsoft.azure%22%20AND%20a%3A%22azure-servicebus-jms-spring-boot-starter%22) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-servicebus-jms-spring-boot-starter/2.1.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:azure-servicebus-jms-spring-boot-starter%20AND%20v:2.1.*) | N/A ### Snapshots [![Nexus OSS](https://img.shields.io/nexus/snapshots/https/oss.sonatype.org/com.microsoft.azure/azure-spring-boot.svg)](https://oss.sonatype.org/content/repositories/snapshots/com/microsoft/azure/azure-spring-boot/) diff --git a/sdk/spring/azure-spring-boot-starter-active-directory/CHANGELOG.md b/sdk/spring/azure-spring-boot-starter-active-directory/CHANGELOG.md new file mode 100644 index 000000000000..d51e263177a9 --- /dev/null +++ b/sdk/spring/azure-spring-boot-starter-active-directory/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 2.2.5-beta.1 (Unreleased) diff --git a/sdk/spring/azure-spring-boot-starter-metrics/CHANGELOG.md b/sdk/spring/azure-spring-boot-starter-metrics/CHANGELOG.md new file mode 100644 index 000000000000..d51e263177a9 --- /dev/null +++ b/sdk/spring/azure-spring-boot-starter-metrics/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 2.2.5-beta.1 (Unreleased) diff --git a/sdk/spring/azure-spring-boot-starter-metrics/README.md b/sdk/spring/azure-spring-boot-starter-metrics/README.md new file mode 100644 index 000000000000..f52028c6409b --- /dev/null +++ b/sdk/spring/azure-spring-boot-starter-metrics/README.md @@ -0,0 +1,47 @@ +#Azure Metrics Spring Boot Starter client library for Java + +## Key concepts + +## Getting started + +## Examples +### Add the dependency + +`azure-spring-boot-metrics-starter` is published on Maven Central Repository. +If you are using Maven, add the following dependency. + +[//]: # ({x-version-update-start;com.azure:azure-spring-boot-metrics-starter;current}) +```xml + + com.microsoft.azure + azure-spring-boot-metrics-starter + 2.2.5-beta.1 + +``` +[//]: # ({x-version-update-end}) + +### Add the property setting + +Open `application.properties` file and add below properties with your instrumentation key. + +``` +management.metrics.export.azuremonitor.instrumentation-key= +``` + +## Troubleshooting +If the JDK version you use is greater than 1.8, You may meet this problem: +``` +NoClassDefFoundError: javax/xml/bind/JAXBException +``` + +To solve this issue, you need to add the dependency below into your classpath: +``` + + javax.xml.bind + jaxb-api + 2.3.0 + +``` + +## Next steps +## Contributing diff --git a/sdk/spring/azure-spring-boot-starter-metrics/pom.xml b/sdk/spring/azure-spring-boot-starter-metrics/pom.xml new file mode 100644 index 000000000000..2251f0ddc870 --- /dev/null +++ b/sdk/spring/azure-spring-boot-starter-metrics/pom.xml @@ -0,0 +1,143 @@ + + + 4.0.0 + + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.microsoft.azure + azure-spring-boot-metrics-starter + 2.2.5-beta.1 + + Azure Metrics Spring Boot Starter + Spring Boot Starter for Micrometer Metrics + https://github.com/Azure/azure-sdk-for-java + + + + org.springframework.boot + spring-boot-starter + 2.2.0.RELEASE + + + org.springframework.boot + spring-boot-starter-validation + 2.2.0.RELEASE + + + com.microsoft.azure + azure-spring-boot + 2.2.5-beta.1 + + + io.micrometer + micrometer-registry-azure-monitor + 1.3.0 + + + org.springframework.boot + spring-boot-actuator-autoconfigure + 2.2.0.RELEASE + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + + + com.microsoft.azure:* + io.micrometer:micrometer-core:[1.3.0] + io.micrometer:micrometer-registry-azure-monitor:[1.3.0] + org.springframework.boot:spring-boot-actuator-autoconfigure:[2.2.0.RELEASE] + org.springframework.boot:spring-boot-starter:[2.2.0.RELEASE] + org.springframework.boot:spring-boot-starter-validation:[2.2.0.RELEASE] + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + + attach-javadocs + + jar + + + true + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + empty-javadoc-jar-with-readme + package + + jar + + + javadoc + ${project.basedir}/javadocTemp + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + copy-readme-to-javadocTemp + prepare-package + + + Deleting existing ${project.basedir}/javadocTemp + + + + Copying ${project.basedir}/README.md to + ${project.basedir}/javadocTemp/README.md + + + + + + run + + + + + + + + diff --git a/sdk/spring/azure-spring-boot-starter-metrics/src/main/resources/metrics.enable.config b/sdk/spring/azure-spring-boot-starter-metrics/src/main/resources/metrics.enable.config new file mode 100644 index 000000000000..2995a4d0e749 --- /dev/null +++ b/sdk/spring/azure-spring-boot-starter-metrics/src/main/resources/metrics.enable.config @@ -0,0 +1 @@ +dummy \ No newline at end of file diff --git a/sdk/spring/azure-spring-boot-starter-servicebus-jms/CHANGELOG.md b/sdk/spring/azure-spring-boot-starter-servicebus-jms/CHANGELOG.md new file mode 100644 index 000000000000..d51e263177a9 --- /dev/null +++ b/sdk/spring/azure-spring-boot-starter-servicebus-jms/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 2.2.5-beta.1 (Unreleased) diff --git a/sdk/spring/azure-spring-boot-starter-servicebus-jms/README.md b/sdk/spring/azure-spring-boot-starter-servicebus-jms/README.md new file mode 100644 index 000000000000..81fcfffd858e --- /dev/null +++ b/sdk/spring/azure-spring-boot-starter-servicebus-jms/README.md @@ -0,0 +1,53 @@ +#Azure Service Bus JMS Spring Boot Starter client library for Java + +## Key concepts +With this starter you could easily use Spring JMS Queue and Topic with Azure Service Bus. + +### Java agent based monitoring + +Azure Application Insights has released one Java agent that can be used to capture metrics inside JVM. Consider use the Java agent based approach. + +Refer following document for more details: + +https://docs.microsoft.com/azure/azure-monitor/app/java-in-process-agent + + +## Getting started + +### Add the dependency + +`azure-servicebus-jms-spring-boot-starter` is published on Maven Central Repository. +Add the following dependency to your project: + +[//]: # ({x-version-update-start;com.azure:azure-spring-boot-metrics-starter;current}) +```xml + + com.microsoft.azure + azure-servicebus-jms-spring-boot-starter + 2.2.5-beta.1 + +``` +[//]: # ({x-version-update-end}) + + +## Examples +These code [Service Bus Queue Sample](../../azure-spring-boot-samples/azure-spring-boot-sample-servicebus-jms-queue/) +and [Service Bus Topic Sample](../../azure-spring-boot-samples/azure-spring-boot-sample-servicebus-jms-topic/) +respectively demonstrates how to use Spring JMS Queue and Topic for Azure Service Bus via the Starter. + +Running these samples will be charged by Azure. You can check the usage and bill at this [link](https://azure.microsoft.com/account/). + + +## Troubleshooting + +## Next steps + +### Allow telemetry +Microsoft would like to collect data about how users use this Spring boot starter. Microsoft uses this information to improve our tooling experience. Participation is voluntary. If you don't want to participate, just simply disable it by setting below configuration in `application.properties`. +``` +azure.servicebus.allow-telemetry=false +``` +When telemetry is enabled, an HTTP request will be sent to URL `https://dc.services.visualstudio.com/v2/track`. So please make sure it's not blocked by your firewall. +Find more information about Azure Service Privacy Statement, please check [Microsoft Online Services Privacy Statement](https://www.microsoft.com/privacystatement/OnlineServices/Default.aspx). + +## Contributing diff --git a/sdk/spring/azure-spring-boot-starter-servicebus-jms/pom.xml b/sdk/spring/azure-spring-boot-starter-servicebus-jms/pom.xml new file mode 100644 index 000000000000..5e8ee73ed3cd --- /dev/null +++ b/sdk/spring/azure-spring-boot-starter-servicebus-jms/pom.xml @@ -0,0 +1,142 @@ + + + 4.0.0 + + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.microsoft.azure + azure-servicebus-jms-spring-boot-starter + 2.2.5-beta.1 + + Azure Service Bus JMS Spring Boot Starter + Spring Boot Starter for Azure Service Bus JMS + https://github.com/Azure/azure-sdk-for-java + + + + com.microsoft.azure + azure-spring-boot + 2.2.5-beta.1 + + + + + org.springframework + spring-jms + 5.2.5.RELEASE + + + + + org.apache.qpid + qpid-jms-client + 0.43.0 + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + + false + + + *:*:*:*:runtime + *:*:*:*:compile + *:*:*:*:provided + + + com.microsoft.azure:* + org.apache.qpid:qpid-jms-client:[0.43.0] + org.springframework:spring-jms:[5.2.5.RELEASE] + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + + attach-javadocs + + jar + + + true + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + empty-javadoc-jar-with-readme + package + + jar + + + javadoc + ${project.basedir}/javadocTemp + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + copy-readme-to-javadocTemp + prepare-package + + + Deleting existing ${project.basedir}/javadocTemp + + + + Copying ${project.basedir}/README.md to + ${project.basedir}/javadocTemp/README.md + + + + + + run + + + + + + + + diff --git a/sdk/spring/azure-spring-boot-starter-servicebus-jms/src/main/resources/servicebusjms.enable.config b/sdk/spring/azure-spring-boot-starter-servicebus-jms/src/main/resources/servicebusjms.enable.config new file mode 100644 index 000000000000..2995a4d0e749 --- /dev/null +++ b/sdk/spring/azure-spring-boot-starter-servicebus-jms/src/main/resources/servicebusjms.enable.config @@ -0,0 +1 @@ +dummy \ No newline at end of file diff --git a/sdk/spring/azure-spring-boot-starter/CHANGELOG.md b/sdk/spring/azure-spring-boot-starter/CHANGELOG.md new file mode 100644 index 000000000000..d51e263177a9 --- /dev/null +++ b/sdk/spring/azure-spring-boot-starter/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 2.2.5-beta.1 (Unreleased) diff --git a/sdk/spring/azure-spring-boot/CHANGELOG.md b/sdk/spring/azure-spring-boot/CHANGELOG.md new file mode 100644 index 000000000000..d51e263177a9 --- /dev/null +++ b/sdk/spring/azure-spring-boot/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 2.2.5-beta.1 (Unreleased) diff --git a/sdk/spring/azure-spring-boot/pom.xml b/sdk/spring/azure-spring-boot/pom.xml index f864e4b4bf8e..7a21682a9994 100644 --- a/sdk/spring/azure-spring-boot/pom.xml +++ b/sdk/spring/azure-spring-boot/pom.xml @@ -106,6 +106,42 @@ true + + + io.micrometer + micrometer-registry-azure-monitor + 1.3.0 + true + + + io.micrometer + micrometer-core + 1.3.0 + true + + + org.springframework.boot + spring-boot-actuator-autoconfigure + 2.2.0.RELEASE + true + + + + + org.springframework + spring-jms + 5.2.5.RELEASE + true + + + + + org.apache.qpid + qpid-jms-client + 0.43.0 + true + + com.microsoft.azure @@ -211,19 +247,22 @@ com.google.code.findbugs:jsr305:[3.0.2] com.microsoft.azure:msal4j:[1.3.0] com.nimbusds:nimbus-jose-jwt:[7.9] + io.micrometer:micrometer-core:[1.3.0] + io.micrometer:micrometer-registry-azure-monitor:[1.3.0] javax.servlet:javax.servlet-api:[4.0.1] javax.annotation:javax.annotation-api:[1.3.2] javax.validation:validation-api:[2.0.1.Final] + org.apache.qpid:qpid-jms-client:[0.43.0] org.slf4j:slf4j-api:[1.7.28] org.hibernate.validator:hibernate-validator:[6.0.17.Final] org.springframework:spring-web:[5.2.5.RELEASE] + org.springframework:spring-jms:[5.2.5.RELEASE] org.springframework.boot:spring-boot-actuator-autoconfigure:[2.2.0.RELEASE] org.springframework.boot:spring-boot-autoconfigure-processor:[2.2.0.RELEASE] org.springframework.boot:spring-boot-autoconfigure:[2.2.0.RELEASE] org.springframework.boot:spring-boot-configuration-processor:[2.2.0.RELEASE] org.springframework.boot:spring-boot-starter-test:[2.2.0.RELEASE] org.springframework.boot:spring-boot-starter-web:[2.2.0.RELEASE] - org.springframework:spring-web:[5.2.5.RELEASE] org.springframework.security:spring-security-config:[5.2.0.RELEASE] org.springframework.security:spring-security-core:[5.2.0.RELEASE] org.springframework.security:spring-security-oauth2-client:[5.2.0.RELEASE] diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/AzureServiceBusJMSProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/AzureServiceBusJMSProperties.java new file mode 100644 index 000000000000..8ac2d8c2ae85 --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/AzureServiceBusJMSProperties.java @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.jms; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.StringUtils; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.PostConstruct; + +/** + * {@link ConfigurationProperties} for configuring Azure Service Bus JMS. + */ +@Validated +@ConfigurationProperties("spring.jms.servicebus") +public class AzureServiceBusJMSProperties { + + private String connectionString; + + /** + * JMS clientID + */ + private String topicClientId; + + private int idleTimeout = 1800000; + + public String getConnectionString() { + return connectionString; + } + + public void setConnectionString(String connectionString) { + this.connectionString = connectionString; + } + + public String getTopicClientId() { + return topicClientId; + } + + public void setTopicClientId(String topicClientId) { + this.topicClientId = topicClientId; + } + + public int getIdleTimeout() { + return idleTimeout; + } + + public void setIdleTimeout(int idleTimeout) { + this.idleTimeout = idleTimeout; + } + + @PostConstruct + public void validate() { + + if (!StringUtils.hasText(connectionString)) { + throw new IllegalArgumentException("'spring.jms.servicebus.connection-string' should be provided"); + } + + } +} diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/ConnectionStringResolver.java b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/ConnectionStringResolver.java new file mode 100644 index 000000000000..d83b04f0051d --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/ConnectionStringResolver.java @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.jms; + +import java.util.HashMap; + +/** + * Resolve Service Bus host, shared access key name, shared access key from Service Bus connection string. + */ +public class ConnectionStringResolver { + + private static final String ENDPOINT = "Endpoint"; + private static final String HOST = "host"; + private static final String SAS_KEY_NAME = "SharedAccessKeyName"; + private static final String SAS_KEY = "SharedAccessKey"; + + public static ServiceBusKey getServiceBusKey(String connectionString) { + final String[] segments = connectionString.split(";"); + final HashMap hashMap = new HashMap<>(); + + for (final String segment : segments) { + final int indexOfEqualSign = segment.indexOf("="); + final String key = segment.substring(0, indexOfEqualSign); + final String value = segment.substring(indexOfEqualSign + 1); + hashMap.put(key, value); + } + + final String endpoint = hashMap.get(ENDPOINT); + final String[] segmentsOfEndpoint = endpoint.split("/"); + final String host = segmentsOfEndpoint[segmentsOfEndpoint.length - 1]; + hashMap.put(HOST, host); + + return new ServiceBusKey(hashMap.get(HOST), hashMap.get(SAS_KEY_NAME), hashMap.get(SAS_KEY)); + } + +} diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/ServiceBusJMSAutoConfiguration.java b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/ServiceBusJMSAutoConfiguration.java new file mode 100644 index 000000000000..964dbbb8ce27 --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/ServiceBusJMSAutoConfiguration.java @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.jms; + +import org.apache.qpid.jms.JmsConnectionFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.condition.ConditionalOnResource; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jms.config.DefaultJmsListenerContainerFactory; +import org.springframework.jms.config.JmsListenerContainerFactory; +import org.springframework.jms.connection.CachingConnectionFactory; +import org.springframework.jms.core.JmsTemplate; +import org.springframework.jms.listener.MessageListenerContainer; + +import javax.jms.ConnectionFactory; + +/** + * Auto-configuration for Service Bus JMS. + *

+ * The configuration will not be activated if no {@literal spring.jms.servicebus.enabled} property provided. + */ +@Configuration +@ConditionalOnClass(JmsConnectionFactory.class) +@ConditionalOnResource(resources = "classpath:servicebusjms.enable.config") +@ConditionalOnProperty(value = "spring.jms.servicebus.enabled", matchIfMissing = true) +@EnableConfigurationProperties(AzureServiceBusJMSProperties.class) +public class ServiceBusJMSAutoConfiguration { + + private static final String AMQP_URI_FORMAT = "amqps://%s?amqp.idleTimeout=%d"; + + @Bean + @ConditionalOnMissingBean + public ConnectionFactory jmsConnectionFactory(AzureServiceBusJMSProperties serviceBusJMSProperties) { + final String connectionString = serviceBusJMSProperties.getConnectionString(); + final String clientId = serviceBusJMSProperties.getTopicClientId(); + final int idleTimeout = serviceBusJMSProperties.getIdleTimeout(); + + final ServiceBusKey serviceBusKey = ConnectionStringResolver.getServiceBusKey(connectionString); + final String host = serviceBusKey.getHost(); + final String sasKeyName = serviceBusKey.getSharedAccessKeyName(); + final String sasKey = serviceBusKey.getSharedAccessKey(); + + final String remoteUri = String.format(AMQP_URI_FORMAT, host, idleTimeout); + final JmsConnectionFactory jmsConnectionFactory = new JmsConnectionFactory(); + jmsConnectionFactory.setRemoteURI(remoteUri); + jmsConnectionFactory.setClientID(clientId); + jmsConnectionFactory.setUsername(sasKeyName); + jmsConnectionFactory.setPassword(sasKey); + return new CachingConnectionFactory(jmsConnectionFactory); + } + + @Bean + @ConditionalOnMissingBean + public JmsTemplate jmsTemplate(ConnectionFactory jmsConnectionFactory) { + final JmsTemplate jmsTemplate = new JmsTemplate(); + jmsTemplate.setConnectionFactory(jmsConnectionFactory); + return jmsTemplate; + } + + @Bean + @ConditionalOnMissingBean + public JmsListenerContainerFactory jmsListenerContainerFactory( + ConnectionFactory connectionFactory) { + final DefaultJmsListenerContainerFactory jmsListenerContainerFactory = new DefaultJmsListenerContainerFactory(); + jmsListenerContainerFactory.setConnectionFactory(connectionFactory); + return jmsListenerContainerFactory; + } + + @Bean + public JmsListenerContainerFactory topicJmsListenerContainerFactory( + ConnectionFactory connectionFactory) { + final DefaultJmsListenerContainerFactory jmsListenerContainerFactory = new DefaultJmsListenerContainerFactory(); + jmsListenerContainerFactory.setConnectionFactory(connectionFactory); + jmsListenerContainerFactory.setSubscriptionDurable(Boolean.TRUE); + return jmsListenerContainerFactory; + } + +} diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/ServiceBusKey.java b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/ServiceBusKey.java new file mode 100644 index 000000000000..afb5dab0ecf0 --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/jms/ServiceBusKey.java @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.jms; + +/** + * POJO describes Service Bus connection info + */ +public class ServiceBusKey { + private final String host; + private final String sharedAccessKeyName; + private final String sharedAccessKey; + + ServiceBusKey(String host, String sharedAccessKeyName, String sharedAccessKey) { + this.host = host; + this.sharedAccessKeyName = sharedAccessKeyName; + this.sharedAccessKey = sharedAccessKey; + } + + public String getHost() { + return host; + } + + public String getSharedAccessKeyName() { + return sharedAccessKeyName; + } + + public String getSharedAccessKey() { + return sharedAccessKey; + } + +} diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorMetricsExportAutoConfiguration.java b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorMetricsExportAutoConfiguration.java new file mode 100644 index 000000000000..d008a19a4cf2 --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorMetricsExportAutoConfiguration.java @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.metrics; + +import com.microsoft.applicationinsights.TelemetryConfiguration; +import io.micrometer.azuremonitor.AzureMonitorConfig; +import io.micrometer.azuremonitor.AzureMonitorMeterRegistry; +import io.micrometer.core.instrument.Clock; +import io.micrometer.core.instrument.util.StringUtils; +import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.condition.ConditionalOnResource; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Auto-Configuration for exporting metrics to Azure Application Insights. + * + * @author Dhaval Doshi + */ +@Configuration +@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, + SimpleMetricsExportAutoConfiguration.class}) +@AutoConfigureAfter(MetricsAutoConfiguration.class) +@ConditionalOnBean(Clock.class) +@ConditionalOnClass(AzureMonitorMeterRegistry.class) +@ConditionalOnResource(resources = "classpath:metrics.enable.config") +@ConditionalOnProperty(prefix = "management.metrics.export.azuremonitor", + name = "enabled", havingValue = "true", matchIfMissing = true) +@EnableConfigurationProperties(AzureMonitorProperties.class) +public class AzureMonitorMetricsExportAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + public AzureMonitorConfig azureConfig(AzureMonitorProperties properties) { + return new AzureMonitorPropertiesConfigAdapter(properties); + } + + /** + * This bean is already available when the + * Azure Application Insights starter + * is present. + * + * @param config Azure monitor config + * @return telemetry configuration + */ + @Bean + @ConditionalOnMissingBean + public TelemetryConfiguration telemetryConfiguration(AzureMonitorConfig config) { + // Gets the active instance of TelemetryConfiguration either created by starter or xml + final TelemetryConfiguration telemetryConfiguration = TelemetryConfiguration.getActive(); + if (StringUtils.isEmpty(telemetryConfiguration.getInstrumentationKey())) { + telemetryConfiguration.setInstrumentationKey(config.instrumentationKey()); + } + return telemetryConfiguration; + } + + @Bean + @ConditionalOnMissingBean + public AzureMonitorMeterRegistry azureMeterRegistry(AzureMonitorConfig config, + TelemetryConfiguration configuration, Clock clock) { + return AzureMonitorMeterRegistry.builder(config) + .clock(clock) + .telemetryConfiguration(configuration) + .build(); + } +} diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorProperties.java new file mode 100644 index 000000000000..3e288e01cf9f --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorProperties.java @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.metrics; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * {@link ConfigurationProperties} for configuring Azure Application Insights metrics export. + * + * @author Dhaval Doshi + */ +@ConfigurationProperties(prefix = "management.metrics.export.azuremonitor") +public class AzureMonitorProperties extends StepRegistryProperties { + private String instrumentationKey; + + public String getInstrumentationKey() { + return this.instrumentationKey; + } + + public void setInstrumentationKey(String instrumentationKey) { + this.instrumentationKey = instrumentationKey; + } +} diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorPropertiesConfigAdapter.java b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorPropertiesConfigAdapter.java new file mode 100644 index 000000000000..93646aadc7ed --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorPropertiesConfigAdapter.java @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.metrics; + +import io.micrometer.azuremonitor.AzureMonitorConfig; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapter; + +/** + * Adapter to convert {@link AzureMonitorProperties} to a {@link AzureMonitorConfig}. + * + * @author Dhaval Doshi + */ +public class AzureMonitorPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter + implements AzureMonitorConfig { + + AzureMonitorPropertiesConfigAdapter(AzureMonitorProperties properties) { + super(properties); + } + + @Override + public String instrumentationKey() { + return get(AzureMonitorProperties::getInstrumentationKey, AzureMonitorConfig.super::instrumentationKey); + } +} diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/jms/ConnectionStringResolverTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/jms/ConnectionStringResolverTest.java new file mode 100644 index 000000000000..d6eaa34ae05a --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/jms/ConnectionStringResolverTest.java @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.jms; + +import org.junit.Assert; +import org.junit.Test; + +public class ConnectionStringResolverTest { + @Test + public void testConnectionStringResolver() { + final String connectionString = "Endpoint=sb://host/;SharedAccessKeyName=sasKeyName;SharedAccessKey=sasKey"; + + final ServiceBusKey serviceBusKey = ConnectionStringResolver.getServiceBusKey(connectionString); + final String host = serviceBusKey.getHost(); + final String sasKeyName = serviceBusKey.getSharedAccessKeyName(); + final String sasKey = serviceBusKey.getSharedAccessKey(); + + Assert.assertEquals("host", host); + Assert.assertEquals("sasKeyName", sasKeyName); + Assert.assertEquals("sasKey", sasKey); + } +} diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/jms/ServiceBusJMSAutoConfigurationTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/jms/ServiceBusJMSAutoConfigurationTest.java new file mode 100644 index 000000000000..20db17a65d59 --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/jms/ServiceBusJMSAutoConfigurationTest.java @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.jms; + +import org.apache.qpid.jms.JmsConnectionFactory; +import org.junit.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.FilteredClassLoader; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ServiceBusJMSAutoConfigurationTest { + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(ServiceBusJMSAutoConfiguration.class)); + + @Test + public void testAzureServiceBusDisabled() { + this.contextRunner.withPropertyValues("spring.jms.servicebus.enabled=false") + .run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusJMSProperties.class)); + } + + @Test + public void testWithoutServiceBusJMSNamespace() { + this.contextRunner.withClassLoader(new FilteredClassLoader(JmsConnectionFactory.class)) + .run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusJMSProperties.class)); + } + + @Test(expected = IllegalStateException.class) + public void testAzureServiceBusJMSPropertiesValidation() { + this.contextRunner.run(context -> context.getBean(AzureServiceBusJMSProperties.class)); + } + + @Test + public void testAzureServiceBusJMSPropertiesConfigured() { + + final String connectionString = "Endpoint=sb://host/;SharedAccessKeyName=sasKeyName;SharedAccessKey=sasKey"; + + this.contextRunner = this.contextRunner.withPropertyValues( + "spring.jms.servicebus.connection-string=" + connectionString + ); + + this.contextRunner = this.contextRunner.withPropertyValues( + "spring.jms.servicebus.topic-client-id=cid" + ); + + this.contextRunner = this.contextRunner.withPropertyValues( + "spring.jms.servicebus.idle-timeout=123" + ); + + this.contextRunner.run( + context -> { + assertThat(context).hasSingleBean(AzureServiceBusJMSProperties.class); + assertThat(context.getBean(AzureServiceBusJMSProperties.class).getConnectionString()).isEqualTo( + connectionString); + assertThat(context.getBean(AzureServiceBusJMSProperties.class).getTopicClientId()).isEqualTo("cid"); + assertThat(context.getBean(AzureServiceBusJMSProperties.class).getIdleTimeout()).isEqualTo(123); + } + ); + } + +} diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorMetricsExportAutoConfigurationTests.java b/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorMetricsExportAutoConfigurationTests.java new file mode 100644 index 000000000000..5c3c1a198cf4 --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorMetricsExportAutoConfigurationTests.java @@ -0,0 +1,158 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.metrics; + +import io.micrometer.azuremonitor.AzureMonitorConfig; +import io.micrometer.azuremonitor.AzureMonitorMeterRegistry; +import io.micrometer.core.instrument.Clock; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.assertj.AssertableApplicationContext; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +/** + * Tests for autoconfiguration of {@link AzureMonitorMetricsExportAutoConfiguration} + * + * @author Dhaval Doshi + */ +public class AzureMonitorMetricsExportAutoConfigurationTests { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations + .of(AzureMonitorMetricsExportAutoConfiguration.class)); + + @Test + public void backsOffWithoutAClock() { + this.contextRunner.run((context) -> assertThat(context) + .doesNotHaveBean(AzureMonitorMeterRegistry.class)); + } + + @Test + @Ignore("Somewhere in the class path there is xml from where the config is picked for AI") + public void failsWithoutAnApiKey() { + this.contextRunner.withUserConfiguration(BaseConfiguration.class) + .run((context) -> assertThat(context).hasFailed()); + } + + @Test + public void autoConfiguresConfigAndMeterRegistry() { + this.contextRunner.withUserConfiguration(BaseConfiguration.class) + .withPropertyValues( + "management.metrics.export.azuremonitor.instrumentation-key=fakekey") + .run((context) -> assertThat(context) + .hasSingleBean(AzureMonitorMeterRegistry.class) + .hasSingleBean(AzureMonitorConfig.class)); + } + + @Test + public void autoConfigurationCanBeDisabled() { + this.contextRunner.withUserConfiguration(BaseConfiguration.class) + .withPropertyValues( + "management.metrics.export.azuremonitor.enabled=false") + .run((context) -> assertThat(context) + .doesNotHaveBean(AzureMonitorMeterRegistry.class) + .doesNotHaveBean(AzureMonitorConfig.class)); + } + + @Test + public void allowsCustomConfigToBeUsed() { + this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class) + .run((context) -> assertThat(context) + .hasSingleBean(AzureMonitorMeterRegistry.class) + .hasSingleBean(AzureMonitorConfig.class).hasBean("customConfig")); + } + + @Test + public void allowsCustomRegistryToBeUsed() { + this.contextRunner.withUserConfiguration(CustomRegistryConfiguration.class) + .withPropertyValues( + "management.metrics.export.azuremonitor.instrumentation-key=fakekey") + .run((context) -> assertThat(context) + .hasSingleBean(AzureMonitorMeterRegistry.class) + .hasBean("customRegistry") + .hasSingleBean(AzureMonitorConfig.class)); + } + + @Test + public void stopsMeterRegistryWhenContextIsClosed() { + this.contextRunner.withUserConfiguration(BaseConfiguration.class) + .withPropertyValues( + "management.metrics.export.azuremonitor.instrumentation-key=fakekey") + .run((context) -> { + final AzureMonitorMeterRegistry registry = spyOnDisposableBean( + AzureMonitorMeterRegistry.class, context); + context.close(); + verify(registry).stop(); + }); + } + + @SuppressWarnings("unchecked") + private T spyOnDisposableBean(Class type, + AssertableApplicationContext context) { + final String[] names = context.getBeanNamesForType(type); + assertThat(names).hasSize(1); + final String registryBeanName = names[0]; + final Map disposableBeans = (Map) ReflectionTestUtils + .getField(context.getAutowireCapableBeanFactory(), "disposableBeans"); + final Object registryAdapter = disposableBeans.get(registryBeanName); + final T registry = (T) spy(ReflectionTestUtils.getField(registryAdapter, "bean")); + ReflectionTestUtils.setField(registryAdapter, "bean", registry); + return registry; + } + + @Configuration + static class BaseConfiguration { + + @Bean + public Clock clock() { + return Clock.SYSTEM; + } + + } + + @Configuration + @Import(BaseConfiguration.class) + static class CustomConfigConfiguration { + + @Bean + public AzureMonitorConfig customConfig() { + return new AzureMonitorConfig() { + + @Override + public String get(String k) { + if ("azuremonitor.instrumentation-key".equals(k)) { + return "12345"; + } + return null; + } + + }; + } + + } + + @Configuration + @Import(BaseConfiguration.class) + static class CustomRegistryConfiguration { + + @Bean + public AzureMonitorMeterRegistry customRegistry(AzureMonitorConfig config, + Clock clock) { + return AzureMonitorMeterRegistry.builder(config) + .clock(clock) + .build(); + } + } +} diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorPropertiesTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorPropertiesTest.java new file mode 100644 index 000000000000..f180bfe3152a --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/metrics/AzureMonitorPropertiesTest.java @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.azure.spring.autoconfigure.metrics; + +import io.micrometer.azuremonitor.AzureMonitorConfig; +import io.micrometer.core.instrument.step.StepRegistryConfig; +import org.junit.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link AzureMonitorProperties}. + * + * @author Dhaval Doshi + */ + +public class AzureMonitorPropertiesTest { + + @SuppressWarnings("depreciation") + private void assertStepRegistryDefaultValues(StepRegistryProperties properties, + StepRegistryConfig config) { + assertThat(properties.getStep()).isEqualTo(config.step()); + assertThat(properties.isEnabled()).isEqualTo(config.enabled()); + assertThat(properties.getConnectTimeout()).isEqualTo(config.connectTimeout()); + assertThat(properties.getReadTimeout()).isEqualTo(config.readTimeout()); + assertThat(properties.getNumThreads()).isEqualTo(config.numThreads()); + assertThat(properties.getBatchSize()).isEqualTo(config.batchSize()); + } + + @Test + public void defaultValuesAreConsistent() { + final AzureMonitorProperties properties = new AzureMonitorProperties(); + final AzureMonitorConfig config = (key) -> null; + assertStepRegistryDefaultValues(properties, config); + } + +} diff --git a/sdk/spring/ci.yml b/sdk/spring/ci.yml index 0fe9bd266f5c..084ee09aed6e 100644 --- a/sdk/spring/ci.yml +++ b/sdk/spring/ci.yml @@ -50,7 +50,12 @@ stages: - name: azure-keyvault-secrets-spring-boot-starter groupId: com.microsoft.azure safeName: azurespringbootstarterkeyvaultsecrets - + - name: azure-spring-boot-metrics-starter + groupId: com.microsoft.azure + safeName: azurespringbootstartermetrics + - name: azure-servicebus-jms-spring-boot-starter + groupId: com.microsoft.azure + safeName: azurespringbootstarterservicebusjms diff --git a/sdk/spring/pom.xml b/sdk/spring/pom.xml index d251259a85ad..2c21d69c6f93 100644 --- a/sdk/spring/pom.xml +++ b/sdk/spring/pom.xml @@ -13,6 +13,8 @@ azure-spring-boot-starter azure-spring-boot-starter-active-directory azure-spring-boot-starter-keyvault-secrets + azure-spring-boot-starter-metrics + azure-spring-boot-starter-servicebus-jms