本文整理汇总了Java中com.github.kristofa.brave.Brave类的典型用法代码示例。如果您正苦于以下问题:Java Brave类的具体用法?Java Brave怎么用?Java Brave使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Brave类属于com.github.kristofa.brave包,在下文中一共展示了Brave类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_jedis_tracer
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Test
public void test_jedis_tracer() throws Exception {
Brave.Builder builder = new Brave.Builder("jedis-interceptor-test");
builder.spanCollector(HttpSpanCollector.create("http://192.168.150.132:9411", new EmptySpanCollectorMetricsHandler()));
builder.traceSampler(Sampler.ALWAYS_SAMPLE);
Brave brave = builder.build();
JaRedisInterceptor.setClientTracer(brave.clientTracer());
JedisPoolConfig config = new JedisPoolConfig();
JaRedisPool proxyPool = new JaRedisPool(config, "127.0.0.1", 6379);
Jedis jedis = proxyPool.getResource();
jedis.set("hello", "world");
Assert.assertEquals(jedis.get("hello"), "world");
jedis.hgetAll("hello-map");
jedis.close();
// sleep 3s in case spanCollector not flushed
Thread.sleep(3000);
}
示例2: main
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
static public void main(String[] args) throws IOException, InterruptedException {
Brave brave = Constant.brave("goodbye-service");
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080)
.usePlaintext(true)
.intercept(new BraveGrpcClientInterceptor(brave))
.build();
GreetingServiceGrpc.GreetingServiceBlockingStub greetingStub = GreetingServiceGrpc.newBlockingStub(channel);
Server goodbyeServer = ServerBuilder.forPort(9090)
.addService(ServerInterceptors.intercept(new GoodbyeServiceImpl(greetingStub),
new BraveGrpcServerInterceptor(brave),
MonitoringServerInterceptor.create(Configuration.allMetrics())))
.build();
goodbyeServer.start();
PrometheusServer prometheusServer = new PrometheusServer(CollectorRegistry.defaultRegistry, 8081);
prometheusServer.start();
System.out.println("Server started!");
goodbyeServer.awaitTermination();
prometheusServer.shutdown();
}
示例3: applySampling
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
private static Brave.Builder applySampling(final Brave.Builder builder, final JsonObject json) {
Sampler sampler;
float rate;
switch (json.getString("type", "boundary")) {
case "counting":
rate = json.getFloat("rate", 0.01f);
sampler = CountingSampler.create(rate);
break;
case "boundary":
default:
rate = json.getFloat("rate", 0.001f);
sampler = BoundarySampler.create(rate);
break;
}
logger.debug("Configuring sampler: {} at rate {}", sampler, rate);
return builder.traceSampler(sampler);
}
示例4: applySpanCollector
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
private static Brave.Builder applySpanCollector(final Brave.Builder builder, final JsonObject json) {
SpanCollector spanCollector;
switch (json.getString("type")) {
case "logging":
spanCollector = new LoggingSpanCollector();
break;
case "scribe":
spanCollector = ScribeSpanCollectorBuilder.build(json);
break;
case "kafka":
spanCollector = KafkaSpanCollectorBuilder.build(json);
break;
case "empty":
default:
spanCollector = new EmptySpanCollector();
}
logger.debug("Configuring span collector: {}", spanCollector);
return builder.spanCollector(spanCollector);
}
示例5: getBrave
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
private Brave getBrave(String serviceName) {
Brave brave = null;
if (serviceName != null) {
brave = braves.get(serviceName);
if (brave == null && useFallbackServiceNames) {
LOG.debug("Creating Brave assigned to serviceName: {}", serviceName + " as fallback");
Brave.Builder builder = new Brave.Builder(serviceName);
builder = builder.traceSampler(Sampler.create(rate));
if (spanCollector != null) {
builder = builder.spanCollector(spanCollector);
}
brave = builder.build();
braves.put(serviceName, brave);
}
}
return brave;
}
示例6: run
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Override
public void run(AppConfiguration configuration, Environment environment) throws Exception {
configuration.getZipkinClient().setTimeout(Duration.seconds(50));
configuration.getZipkinClient().setConnectionRequestTimeout(Duration.seconds(50));
Brave brave = configuration.getZipkinFactory().build(environment).get();
final Client client = new ZipkinClientBuilder(environment, brave)
.build(configuration.getZipkinClient());
new MySQLStatementInterceptorManagementBean(brave.clientTracer());
/**
* Database
*/
createDatabase();
DatabaseUtils.executeDatabaseScript("init.sql");
UserDAO userDAO = new UserDAO();
// Register resources
environment.jersey().register(new HelloHandler());
environment.jersey().register(new SyncHandler(client));
environment.jersey().register(new AsyncHandler(client, brave));
environment.jersey().register(new UsersHandler(userDAO, client, brave));
}
示例7: run
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Override
public void run(C configuration, Environment environment) throws Exception {
this.configuration = configuration;
this.environment = environment;
run(configuration, µsBundleInstance.µsEnvironment(this.environment));
if (configuration instanceof ZipkinAware) {
Brave brave = ((ZipkinAware)configuration).getZipkin().build(environment);
}
configureMapper(configuration, environment.getObjectMapper());
if (configuration instanceof ValidatorAware) {
environment.jersey().register(ValidationResource.class);
}
if (configuration instanceof SwaggerAware) {
environment.jersey().register(SwaggerSerializers.class);
environment.jersey().register(ApiListingResource.class);
environment.jersey().register(AcceptHeaderApiListingResource.class);
}
}
示例8: configure
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Override
public void configure(Map<String, ?> configs, boolean isKey) {
if (isKey) {
throw new IllegalArgumentException("this must be a value serializer");
}
brave = (Brave) configs.get("tracing.component");
if (brave == null) {
throw new IllegalArgumentException("brave must not be null in tracingSerializer");
}
}
示例9: test
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Test
public void test() throws Exception {
Properties props = new Properties();
props.put("bootstrap.servers", "127.0.0.1:9092");//该地址是集群的子集,用来探测集群。
props.put(ConsumerConfig.GROUP_ID_CONFIG, "test-consumer-group");
props.put("acks", "all");// 记录完整提交,最慢的但是最大可能的持久化
props.put("retries", 3);// 请求失败重试的次数
props.put("batch.size", 16384);// batch的大小
props.put("linger.ms", 1);// 默认情况即使缓冲区有剩余的空间,也会立即发送请求,设置一段时间用来等待从而将缓冲区填的更多,单位为毫秒,producer发送数据会延迟1ms,可以减少发送到kafka服务器的请求数据
props.put("buffer.memory", 33554432);// 提供给生产者缓冲内存总量
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer.tracing.codec", Codec.JSON);
props.put("value.deserializer", "org.apache.kafka.common.serialization.ByteArrayDeserializer");
Consumer<String, byte[]> consumer = new KafkaConsumer<>(props);
ListenableTracingConsumer<String, String> listenableTracingConsumer =
new ListenableTracingConsumer<>(consumer, Pattern.compile("test"), new StringDeserializer());
BraveFactoryBean factoryBean = new BraveFactoryBean();
factoryBean.setServiceName("kafka-test");
factoryBean.setTransport("http");
factoryBean.setTransportAddress("127.0.0.1:9411");
factoryBean.afterPropertiesSet();
Brave brave = factoryBean.getObject();
listenableTracingConsumer.addListener(new AbstractTracingListener<String, String>(brave) {
@Override
public void onPayload(Payload<String, String> payload) {
try {
System.out.println("key: " + payload.key());
System.out.println("value: " + payload.value());
Sleeper.JUST.sleepFor(2000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
listenableTracingConsumer.start();
System.in.read();
}
示例10: test
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Test
public void test() throws Exception {
BraveFactoryBean factoryBean = new BraveFactoryBean();
factoryBean.setServiceName("kafka-test");
factoryBean.setTransport("http");
factoryBean.setTransportAddress("127.0.0.1:9411");
factoryBean.afterPropertiesSet();
Brave brave = factoryBean.getObject();
Properties props = new Properties();
props.put("bootstrap.servers", "127.0.0.1:9092");//该地址是集群的子集,用来探测集群。
props.put("acks", "all");// 记录完整提交,最慢的但是最大可能的持久化
props.put("retries", 3);// 请求失败重试的次数
props.put("batch.size", 16384);// batch的大小
props.put("linger.ms", 1);// 默认情况即使缓冲区有剩余的空间,也会立即发送请求,设置一段时间用来等待从而将缓冲区填的更多,单位为毫秒,producer发送数据会延迟1ms,可以减少发送到kafka服务器的请求数据
props.put("buffer.memory", 33554432);// 提供给生产者缓冲内存总量
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("tracing.component", brave);
props.put("value.serializer", "com.github.nightawk.mq.kafka.ByteArrayTracingSerializer");
KafkaProducer<String, byte[]> producer = new KafkaProducer<>(props);
for (int i = 0; i < 1000; i++) {
producer.send(new ProducerRecord<>("test", "hello", ("kafka - " + i).getBytes()));
Thread.sleep(10000);
}
}
示例11: braveServletFilter
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Bean
public BraveServletFilter braveServletFilter(Brave brave) {
BraveServletFilter filter =
new BraveServletFilter(
brave.serverRequestInterceptor(),
brave.serverResponseInterceptor(),
new DefaultSpanNameProvider());
return filter;
}
示例12: okHttpClient
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Bean
public OkHttpClient okHttpClient(Brave brave) {
OkHttpClient client =
new OkHttpClient.Builder()
.addInterceptor(
new BraveOkHttpRequestResponseInterceptor(
brave.clientRequestInterceptor(),
brave.clientResponseInterceptor(),
new DefaultSpanNameProvider()))
.build();
return client;
}
示例13: setup
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Before
public void setup() {
boot = new CrnkBoot();
boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.test.mock.repository", new SampleJsonServiceLocator
()));
boot.boot();
localTracer = Mockito.mock(LocalTracer.class);
brave = Mockito.mock(Brave.class);
Mockito.when(brave.localTracer()).thenReturn(localTracer);
moduleContext = Mockito.mock(Module.ModuleContext.class);
Mockito.when(moduleContext.getResourceRegistry()).thenReturn(boot.getResourceRegistry());
QuerySpec querySpec = new QuerySpec(Task.class);
queryAdapter = new QuerySpecAdapter(querySpec, boot.getResourceRegistry());
ResourceInformation taskResourceInformation = boot.getResourceRegistry().getEntry(Task.class).getResourceInformation();
requestSpec = Mockito.mock(RepositoryRequestSpec.class);
Mockito.when(requestSpec.getMethod()).thenReturn(HttpMethod.GET);
Mockito.when(requestSpec.getQueryAdapter()).thenReturn(queryAdapter);
Mockito.when(requestSpec.getQuerySpec(taskResourceInformation))
.thenReturn(querySpec);
filter = new BraveRepositoryFilter(brave, moduleContext);
filterContext = Mockito.mock(RepositoryFilterContext.class);
Mockito.when(filterContext.getRequest()).thenReturn(requestSpec);
filterChain = Mockito.mock(RepositoryRequestFilterChain.class);
}
示例14: activate
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Activate
public void activate(BundleContext context) {
URLConnectionSender sender = URLConnectionSender.builder()
.endpoint("http://localhost:9411/api/v1/spans").build();
//KafkaSender sender = KafkaSender.builder().bootstrapServers("kafka:9092").build();
reporter = AsyncReporter.builder(sender).build();
Brave brave = create();
reg = context.registerService(Brave.class, brave, null);
}
示例15: inlineBraveSetup
import com.github.kristofa.brave.Brave; //导入依赖的package包/类
@Test
public void inlineBraveSetup() {
Reporter<Span> local = new Reporter<Span>() {
@Override
public void report(Span span) {
spans.add(span);
}
};
Brave brave = new Brave.Builder().reporter(local).build();
brave.localTracer().startNewSpan("test", "testop");
brave.localTracer().finishSpan();
Assert.assertThat(1, equalTo(spans.size()));
}