HystrixCodaHaleMetricsPublisher не работает в сочетании с hystrix spring-cloud-feign

У меня возникла странная проблема при использовании 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();
    }

person Roman T    schedule 18.09.2017    source источник
comment
Как вы зарегистрировали HystrixCodaHaleMetricsPublisher?   -  person Indra Basak    schedule 18.09.2017
comment
Через HystrixPlugins.reset(); HystrixPlugins.getInstance().registerMetricsPublisher(new HystrixCodaHaleMetricsPublisher(this.metricRegistry));   -  person Roman T    schedule 19.09.2017


Ответы (1)


Наконец-то я нашел решение проблемы. Проблема в том, что SetterFactory FeignHisttrix по умолчанию генерирует 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));
    };
}

и все работает сейчас.

person Roman T    schedule 19.09.2017