HystrixCodaHaleMetricsPublisher doesn't work in conjunction with spring-cloud-feign hystrix

123 views Asked by At

I experienced a strange issue when using spring-cloud-feign in conjunction HystrixCodaHaleMetricsPublisher and Graphite. Metrics nodes were created but no data came in.

My config:

@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();
    }
1

There are 1 answers

0
Roman T On BEST ANSWER

Finally I found solution for the issue. The problem is, that default SetterFactory of FeignHistrix generates commandKey with invalid (for graphite) characters i.e. development.local.AccountSettingsClient.AccountSettingsClient#accountSettings(String).countBadRequests. Invalid chars in that case are # and (). When a GraphiteReport starts to send data into Graphite, everything works and the data get sent, but Graphite can't deal with it. So no data get persisted.

As workaround I registered a custom 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));
    };
}

and everything works now.