SpringCloud RPC

2023-12-01 16:23 更新

Sleuth會(huì)自動(dòng)配置RpcTracing bean,它是RPC工具(例如gRPC或Dubbo)的基礎(chǔ)。

如果需要自定義RPC跟蹤的客戶端/服務(wù)器采樣,只需注冊(cè)類型為brave.sampler.SamplerFunction<RpcRequest>的bean,并將bean sleuthRpcClientSampler命名為客戶端采樣器,將sleuthRpcServerSampler命名為服務(wù)器采樣器。

為了方便起見,可以使用@RpcClientSampler@RpcServerSampler批注來注入正確的beans或通過其靜態(tài)字符串NAME字段引用bean名稱。

例如 這是一個(gè)每秒跟蹤100個(gè)“ GetUserToken”服務(wù)器請(qǐng)求的采樣器。這不會(huì)啟動(dòng)對(duì)運(yùn)行狀況檢查服務(wù)的請(qǐng)求的新跟蹤。其他請(qǐng)求將使用全局采樣配置。

@Configuration
class Config {
  @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();
  }
}

有關(guān)更多信息,請(qǐng)參見https://github.com/openzipkin/brave/tree/master/instrumentation/rpc#sampling-policy

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)