首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HystrixCodaHaleMetricsPublisher不与弹簧云假象hystrix一起工作。

HystrixCodaHaleMetricsPublisher不与弹簧云假象hystrix一起工作。
EN

Stack Overflow用户
提问于 2017-09-18 13:54:22
回答 1查看 112关注 0票数 0

在将spring-cloud-feignHystrixCodaHaleMetricsPublisherGraphite结合使用时,我遇到了一个奇怪的问题。创建了度量节点,但没有数据进入。

我的配置:

代码语言:javascript
复制
@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();
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-19 06:35:42

最后,我找到了解决这个问题的办法。问题是,默认的SetterFactory of FeignHistrix生成具有无效字符(对于石墨)的commandKey,即development.local.AccountSettingsClient.AccountSettingsClient#accountSettings(String).countBadRequests。在这种情况下无效的字符是#和()。当一个GraphiteReport开始向Graphite发送数据时,一切都正常,数据被发送,但是Graphite无法处理它。所以没有数据被持久化。

作为解决办法,我注册了一个自定义SetterFactory:

代码语言:javascript
复制
 @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));
    };
}

现在一切都正常了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46281080

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档