在 spring-boot 应用程序中将 Micrometer 与 OpenFeign 结合使用

Use Micrometer with OpenFeign in spring-boot application

OpenApi documentation说支持千分尺。整合如何运作?除了这个小文档,我找不到任何东西。

我在 spring 启动应用程序中有一个 FeignClient

@FeignClient(name = "SomeService", url = "xxx", configuration = FeignConfiguration.class)
public interface SomeService {

    @GET
    @Path("/something")
    Something getSomething();
}

配置

public class FeignConfiguration {
    @Bean
    public Capability capability() {
        return new MicrometerCapability();
    }
}

并将千分尺集成作为依赖项

<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-micrometer</artifactId>
    <version>10.12</version>
</dependency>

代码进行了调用,但我无法通过 actuator 概览找到任何新指标,希望获得有关我的 HTTP 请求的一些一般信息。缺少什么部分?

更新

我为此将 support 添加到 spring-cloud-openfeign。在下一个版本 (2020.0.2) 之后,如果设置了 micrometer,您唯一需要做的就是将 feign-micrometer 放到类路径中。

旧答案

我不确定你是否这样做,但我建议使用 spring-cloud-openfeign,它会为你自动配置 Feign 组件。不幸的是,它似乎没有自动配置 Capability(这就是您的解决方案不起作用的原因之一)所以您需要手动进行配置,please see the docs how to do it.

我能够结合 OpenFeign 和 Spring Cloud OpenFeign 文档中的示例来完成这项工作:

@Import(FeignClientsConfiguration.class)
class FooController {
    private final FooClient fooClient;

    public FooController(Decoder decoder, Encoder encoder, Contract contract, MeterRegistry meterRegistry) {
        this.fooClient = Feign.builder()
                .encoder(encoder)
                .decoder(decoder)
                .contract(contract)
                .addCapability(new MicrometerCapability(meterRegistry))
                .target(FooClient.class, "https://PROD-SVC");
    }
}

我做了什么:

  • 二手spring-cloud-openfeign
  • 已添加 feign-micrometer(参见 feign-bom
  • 按照您在上面看到的方式创建客户端 导入 FeignClientsConfiguration 并将 MeterRegistry 传递给 MicrometerCapability 至关重要

在这些之后,并致电客户,我有了新指标:

  • feign.Client
  • feign.Feign
  • feign.codec.Decoder
  • feign.codec.Decoder.response_size