I'd like an easy out-of-the-box way of timing requests done by Feign clients. I want the same behavior as we currently have for RestTemplate, but for Feign.
Adding @Timed to the method that uses the Feign client doesn't seem to do anything at all.
This is something we can address in spring-cloud-netflix for Finchley.
The way that they've integrated opentracing with Feign is via a delegating client. It is easy to do the same for micrometer:
public final class TimingClient implements Client {
private final Client delegate;
public TimingClient(Client delegate) {
super();
this.delegate = delegate;
}
@Override
public Response execute(Request request, Options options) throws IOException {
Timer timer = Metrics.timer(...);
long start = Clock.SYSTEM.monotonicTime();
try {
return delegate.execute(request, options);
} finally {
long end = Clock.SYSTEM.monotonicTime();
timer.record(end - start, TimeUnit.NANOSECONDS);
}
}
}
And then just use this with the OkHttpClient/whatever when creating your Feign instances.
Is #500 linked to this issue?
Is this issue solved already? I cannot find any information neither here nor in spring-cloud-openfeign.
Can you please confirm if jmx support is added for openfeign
@jkschneider can you please confirm when is this feature planned?
Hey good morning, any ETA for this feature?
regards
@crashodd Happy to accept a PR on this. I'm not sure what HTTP client Feign uses under the covers, but it's likely we already have metrics for that client. So it's probably just a matter of mapping the unparameterized route onto that metrics interceptor.
Hi @jkschneider :blush:, hello from Belgium! :belgium:
This is already implemented by OpenFeign the only missing part is a builtin/autoconfiguration solution.
@crashodd here is a working example that can be used as a reference.
On Spring Cloud OpenFeign there is the issue #354 which has the same goal of this issue.
So now the question for @jkschneider and @spencergibb is: Where this feature should be implemented? On micrometer or spring-cloud-openfeign?
Looks like we just need a new dependency:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-micrometer</artifactId>
<version>10.11</version>
</dependency>
And an extra configuration bean to setup the MicrometerCapability.
@Configuration
@ConditionalOnClass(MicrometerCapability.class)
public static class MicrometerCapabilityConfig {
@Bean
public Feign.Builder feignBuilder(MeterRegistry meterRegistry) {
return Feign.builder()
.addCapability(new MicrometerCapability(meterRegistry));
}
}
Hi @jkschneider 馃槉, hello from Belgium! 馃嚙馃嚜
This is already implemented by OpenFeign the only missing part is a builtin/autoconfiguration solution.
@crashodd here is a working example that can be used as a reference.
On Spring Cloud OpenFeign there is the issue #354 which has the same goal of this issue.
So now the question for @jkschneider and @spencergibb is: Where this feature should be implemented? On micrometer or spring-cloud-openfeign?
Looks like we just need a new dependency:
<dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-micrometer</artifactId> <version>10.11</version> </dependency>And an extra configuration bean to setup the MicrometerCapability.
@Configuration @ConditionalOnClass(MicrometerCapability.class) public static class MicrometerCapabilityConfig { @Bean public Feign.Builder feignBuilder(MeterRegistry meterRegistry) { return Feign.builder() .addCapability(new MicrometerCapability(meterRegistry)); } }
This only provides SUM, COUNT and MAX for requests for Client, Encoder and Decoder.
If the primary reason you need it is monitoring response statuses and more detailed tracking of request times (like histograms), you still need custom implementation using @Timed with Spring AOP (must include provided code)
@Configuration
@EnableAspectJAutoProxy
public class AutoTimingConfiguration {
@Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry);
}
}
This only provides SUM, COUNT and MAX for requests for Client, Encoder and Decoder.
If the primary reason you need it is monitoring response statuses and more detailed tracking of request times (like histograms), you still need custom implementation using@Timedwith Spring AOP
That sounds like it could/should be an enhancement request for the Feign Micrometer module. I found there is a request already open for this: https://github.com/OpenFeign/feign/issues/1301. If that gets resolved, then you shouldn't need to use AOP to time Feign requests.
I'm going to close this as I don't think there will be changes made in Micrometer for this. The support is in OpenFeign itself and that can be configured by the framework you're using, e.g. Spring Cloud OpenFeign now does this.
Most helpful comment
Is this issue solved already? I cannot find any information neither here nor in spring-cloud-openfeign.