This repository has been archived by the owner on Dec 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds storage component for Application Insights (AppInsights)
- Loading branch information
1 parent
de546ef
commit e304bcd
Showing
18 changed files
with
1,417 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2017 The OpenZipkin Authors | ||
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. | ||
--> | ||
<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>io.zipkin.azure</groupId> | ||
<version>0.1.6-SNAPSHOT</version> | ||
<artifactId>zipkin-autoconfigure-parent</artifactId> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>zipkin-autoconfigure-storage-applicationinsights</artifactId> | ||
<name>Zipkin Auto Configuration: Azure Application Insights Storage</name> | ||
|
||
<properties> | ||
<main.basedir>${project.basedir}/../..</main.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.zipkin.azure</groupId> | ||
<artifactId>zipkin-storage-applicationinsights</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<!--<version>3.8.1</version>--> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>19.0</version> | ||
</dependency> | ||
<!--<dependency>--> | ||
<!--<groupId>io.zipkin.brave</groupId>--> | ||
<!--<artifactId>brave-core</artifactId>--> | ||
<!--<version>${brave.version}</version>--> | ||
<!--<optional>true</optional>--> | ||
<!--</dependency>--> | ||
</dependencies> | ||
<!--to do: got to check build contents - got it from autoconfigure-collector-eventhub--> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<layout>MODULE</layout> | ||
<classifier>module</classifier> | ||
<!-- https://github.com/spring-projects/spring-boot/issues/3426 transitive exclude doesn't work --> | ||
<excludeGroupIds> | ||
io.zipkin.java,org.springframework.boot,org.springframework,commons-codec,com.fasterxml.jackson.core,com.fasterxml.jackson.dataformat,org.apache.httpcomponents,commons-logging,joda-time,software.amazon.ion | ||
</excludeGroupIds> | ||
<!-- already packaged in zipkin-server --> | ||
<excludeArtifactIds>jmespath-java</excludeArtifactIds> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
56 changes: 56 additions & 0 deletions
56
...figure/storage/applicationinsights/ZipkinApplicationInsightsStorageAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright 2017 The OpenZipkin Authors | ||
* | ||
* 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. | ||
*/ | ||
package zipkin.autoconfigure.storage.applicationinsights; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
import zipkin.storage.StorageComponent; | ||
import zipkin.storage.applicationinsights.ApplicationInsightsStorage; | ||
import java.util.concurrent.Executor; | ||
|
||
/** | ||
* This storage accepts ApplicationInsights logs in a specified category. Each log entry is expected | ||
* to contain a single span, which is TBinaryProtocol big-endian, then base64 encoded. Decoded spans | ||
* are stored asynchronously. | ||
*/ | ||
@Configuration | ||
@EnableConfigurationProperties(ZipkinApplicationInsightsStorageProperties.class) | ||
@ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "applicationinsights") | ||
@ConditionalOnMissingBean(StorageComponent.class) | ||
public class ZipkinApplicationInsightsStorageAutoConfiguration { | ||
|
||
@Bean @ConditionalOnMissingBean(Executor.class) Executor executor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setThreadNamePrefix("ZipkinApplicationInsightsStorage-"); | ||
executor.initialize(); | ||
return executor; | ||
} | ||
|
||
@Bean StorageComponent storage(Executor executor, | ||
ZipkinApplicationInsightsStorageProperties properties, | ||
@Value("${zipkin.storage.strict-trace-id:true}") boolean strictTraceId) { | ||
return ApplicationInsightsStorage.builder() | ||
.strictTraceId(strictTraceId) | ||
.instrumentationKey(properties.getInstrumentationKey()) | ||
.applicationId(properties.getApplicationId()) | ||
.apikey(properties.getApiKey()) | ||
.executor(executor) | ||
.build(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...autoconfigure/storage/applicationinsights/ZipkinApplicationInsightsStorageProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright 2017 The OpenZipkin Authors | ||
* | ||
* 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. | ||
*/ | ||
package zipkin.autoconfigure.storage.applicationinsights; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import zipkin.storage.applicationinsights.ApplicationInsightsStorage; | ||
|
||
@ConfigurationProperties("zipkin.storage.applicationinsights") | ||
public class ZipkinApplicationInsightsStorageProperties { | ||
|
||
private String instrumentationKey; | ||
private String applicationId; | ||
private String apiKey; | ||
|
||
public String getInstrumentationKey() { | ||
return instrumentationKey; | ||
} | ||
|
||
public void setInstrumentationKey(String key) { | ||
this.instrumentationKey = key; | ||
} | ||
|
||
public String getApplicationId() { | ||
return applicationId; | ||
} | ||
|
||
public void setApplicationId(String key) { | ||
this.applicationId = key; | ||
} | ||
|
||
public String getApiKey() { | ||
return apiKey; | ||
} | ||
|
||
public void setApiKey(String key) { | ||
this.apiKey = key; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
autoconfigure/storage-applicationinsights/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
zipkin.autoconfigure.storage.applicationinsights.ZipkinApplicationInsightsStorageAutoConfiguration |
7 changes: 7 additions & 0 deletions
7
...gure/storage-applicationinsights/src/main/resources/zipkin-server-applicationinsights.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# When enabled, this allows shorter env properties (ex -Dspring.profiles.active=applicationinsights) | ||
zipkin: | ||
storage: | ||
applicationinsights: | ||
instrumentationKey: ${AI_INSTRUMENTATION_KEY:} | ||
applicationId: ${AI_APPLICATION_ID:} | ||
apiKey: ${AI_API_KEY:} |
82 changes: 82 additions & 0 deletions
82
...in.storage.applicationinsights/ZipkinApplicationInsightsStorageAutoConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Copyright 2017 The OpenZipkin Authors | ||
* | ||
* 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. | ||
*/ | ||
package zipkin.storage.applicationinsights; | ||
|
||
import org.junit.After; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.springframework.beans.factory.NoSuchBeanDefinitionException; | ||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import zipkin.autoconfigure.storage.applicationinsights.ZipkinApplicationInsightsStorageAutoConfiguration; | ||
import zipkin.autoconfigure.storage.applicationinsights.ZipkinApplicationInsightsStorageProperties; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment; | ||
|
||
public class ZipkinApplicationInsightsStorageAutoConfigurationTest { | ||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
AnnotationConfigApplicationContext context; | ||
|
||
@After | ||
public void close() { | ||
if (context != null) { | ||
context.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void doesntProvidesStorageComponent_whenStorageTypeNotApplicationInsights() { | ||
context = new AnnotationConfigApplicationContext(); | ||
addEnvironment(context, "zipkin.storage.type:elasticsearch"); | ||
context.register(PropertyPlaceholderAutoConfiguration.class, | ||
ZipkinApplicationInsightsStorageAutoConfiguration.class); | ||
context.refresh(); | ||
|
||
thrown.expect(NoSuchBeanDefinitionException.class); | ||
context.getBean(ApplicationInsightsStorage.class); | ||
} | ||
|
||
@Test | ||
public void providesStorageComponent_whenStorageTypeApplicationInsights() { | ||
context = new AnnotationConfigApplicationContext(); | ||
addEnvironment(context, "zipkin.storage.type:applicationinsights"); | ||
context.register(PropertyPlaceholderAutoConfiguration.class, | ||
ZipkinApplicationInsightsStorageAutoConfiguration.class); | ||
context.refresh(); | ||
|
||
assertThat(context.getBean(ApplicationInsightsStorage.class)).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void canOverridesProperty_InstrumentationKey() { | ||
context = new AnnotationConfigApplicationContext(); | ||
addEnvironment(context, | ||
"zipkin.storage.type:applicationinsights", | ||
"zipkin.storage.applicationinsights.instrumentationKey:xyz", | ||
"zipkin.storage.applicationinsights.applicationId:abc", | ||
"zipkin.storage.applicationinsights.apiKey:mnm" | ||
); | ||
context.register(PropertyPlaceholderAutoConfiguration.class, | ||
ZipkinApplicationInsightsStorageAutoConfiguration.class); | ||
context.refresh(); | ||
|
||
assertThat( | ||
context.getBean(ZipkinApplicationInsightsStorageProperties.class).getInstrumentationKey()) | ||
.isEqualTo("xyz"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.