Merge branch '2.1.x'

This commit is contained in:
Marcin Grzejszczak
2019-10-09 10:34:04 -05:00
3 changed files with 122 additions and 2 deletions

View File

@@ -35,6 +35,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<spring-boot.version>2.2.0.RC1</spring-boot.version>
<brave.version>5.8.0</brave.version>
<okhttp.version>3.11.0</okhttp.version>
</properties>
<dependencyManagement>
@@ -116,7 +117,7 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.11.0</version>
<version>${okhttp.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -158,6 +159,7 @@
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
@@ -170,6 +172,18 @@
<enabled>false</enabled>
</releases>
</repository>
<!-- ONLY FOR BRAVE -->
<repository>
<id>jfrog-snapshots</id>
<name>JFrog Snapshots</name>
<url>https://oss.jfrog.org/oss-snapshot-local/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
@@ -187,6 +201,35 @@
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<profiles>
<profile>
@@ -203,7 +246,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.3.RELEASE</version>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>
<configuration>

View File

@@ -255,6 +255,7 @@
<spring-cloud-netflix.version>2.2.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
<spring-cloud-openfeign.version>2.2.0.BUILD-SNAPSHOT
</spring-cloud-openfeign.version>
<brave.version>5.8.0</brave.version>
<spring-security-boot-autoconfigure.version>2.1.7.RELEASE
</spring-security-boot-autoconfigure.version>
<spring-cloud-aws.version>2.2.0.BUILD-SNAPSHOT</spring-cloud-aws.version>

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2013-2019 the original author or 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
*
* https://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 org.springframework.cloud.sleuth.instrument.rpc;
import brave.rpc.RpcRequest;
import brave.rpc.RpcRuleSampler;
import brave.sampler.Matcher;
import brave.sampler.RateLimitingSampler;
import brave.sampler.Sampler;
import brave.sampler.SamplerFunction;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import static brave.rpc.RpcRequestMatchers.methodEquals;
import static brave.rpc.RpcRequestMatchers.serviceEquals;
import static brave.sampler.Matchers.and;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TraceRpcAutoConfigurationIntegrationTests.Config.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class TraceRpcAutoConfigurationIntegrationTests {
@Autowired
@RpcServerSampler
SamplerFunction<RpcRequest> sampler;
@Test
public void should_inject_rpc_sampler() {
then(this.sampler).isNotNull();
}
@EnableAutoConfiguration
@Configuration
public static class Config {
@Bean
ArrayListSpanReporter reporter() {
return new ArrayListSpanReporter();
}
// tag::custom_rpc_server_sampler[]
@Bean(name = RpcServerSampler.NAME)
SamplerFunction<RpcRequest> myRpcSampler() {
Matcher<RpcRequest> userAuth = and(serviceEquals("users.UserService"),
methodEquals("GetUserToken"));
return RpcRuleSampler.newBuilder()
.putRule(serviceEquals("grpc.health.v1.Health"), Sampler.NEVER_SAMPLE)
.putRule(userAuth, RateLimitingSampler.create(100)).build();
}
// end::custom_rpc_server_sampler[]
}
}