将spring-cloud-feign
与HystrixCodaHaleMetricsPublisher
和Graphite
结合使用时遇到了一个奇怪的问题。已创建度量标准节点,但没有数据进入。
我的配置:
@Configuration
@RequiredArgsConstructor
@EnableConfigurationProperties(ApiGatewayProperties.class)
@EnableFeignClients
public class AccountSettingsClientConfig {
private final ApiGatewayProperties apiGatewayProperties;
@Bean
public RequestInterceptor oauth2FeignRequestInterceptor() {
return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), resource());
}
@Bean
public okhttp3.OkHttpClient okHttpClient() {
return new OkHttpClient.Builder().hostnameVerifier((s, sslSession) -> true)
.build();
}
@Bean
public AccountSettingsClientFallbackFactory accountSettingsClientFallbackFactory() {
return new AccountSettingsClientFallbackFactory();
}
答案 0 :(得分:1)
最后,我找到了解决问题的方法。问题是,FeignHistrix的默认SetterFactory生成的commandKey包含无效(石墨)字符,即development.local.AccountSettingsClient.AccountSettingsClient#accountSettings(String).countBadRequests
。在这种情况下,无效的字符是#和()。当GraphiteReport开始将数据发送到Graphite时,一切正常并且数据被发送,但Graphite无法处理它。因此没有数据持续存在。
作为解决方法,我注册了一个自定义的SetterFactory:
@Bean
public SetterFactory setterFactoryThatGeneratesGraphiteConformCommandKey() {
return (target, method) -> {
String groupKey = target.name();
//allowed chars for graphite are a-z, A-Z, 0-9, "-", "_", "." and "/".
//We don't use default SetterFactory.Default because it generates command key with parenthesis () and #
String commandKey = target.type().getSimpleName() + "-" + method.getName();
return HystrixCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
};
}
现在一切正常。