在将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();
}发布于 2017-09-19 06:35:42
最后,我找到了解决这个问题的办法。问题是,默认的SetterFactory of FeignHistrix生成具有无效字符(对于石墨)的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));
};
}现在一切都正常了。
https://stackoverflow.com/questions/46281080
复制相似问题