Feign metrics are incompatible with RestTemplate metrics when using Prometheus
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- java, prometheus, spring, spring-boot
調査の方向性
リンクされた再現の DemoTestApplicationTests から始め、Prometheus 構成で Feign と RestTemplate のメトリクスがどのように登録されるかを確認します。Feign メトリクスが互換性のあるタグキーを使用し、actuator Prometheus endpoint を通じてメトリクスを公開しながら、テストで登録警告が発生しなければ修正は完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
When a spring boot/cloud project has observations, metrics and prometheus enabled with Feign, the http_client_requests_active metric registered by Feign is not compatible with the one registered by notably RestTemplate (maybe others). This is a problem as soon as you have for exemplle a DiscoveryClient like EurekaDiscoveryClient that uses RestTemplates under the hood.
This results in the following warning when first calling a method of the FeignClient :
The meter (MeterId{name='http.client.requests.active', tags=[tag(clientName=com.example.demo.TestFeignClient),tag(http.method=GET),tag(http.status_code=CLIENT_ERROR),tag(http.url=/outside/test)]}) registration has failed: Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named 'http_client_requests_active_seconds' containing tag keys [client_name, exception, method, outcome, status, uri]. The meter you are attempting to register has keys [clientName, http_method, http_status_code, http_url]. Note that subsequent logs will be logged at debug level.
Consequently, et more importantly, the feign metrics are not exported by prometheus.
The metrics are effectively not compatible :
RestTemplate http_client_requests_active_seconds_count :
http_client_requests_active_seconds_count{client_name="localhost",exception="none",method="GET",outcome="UNKNOWN",status="CLIENT_ERROR",uri="/test"} 0
http_client_requests_active_seconds_sum{client_name="localhost",exception="none",method="GET",outcome="UNKNOWN",status="CLIENT_ERROR",uri="/test"} 0.0
FeignClient http_client_requests_active_seconds_count :
http_client_requests_active_seconds_count{clientName="com.example.demo.TestFeignClient",http_method="GET",http_status_code="CLIENT_ERROR",http_url="/outside/test"} 0
http_client_requests_active_seconds_sum{clientName="com.example.demo.TestFeignClient",http_method="GET",http_status_code="CLIENT_ERROR",http_url="/outside/test"} 0.0
The FeignClient metric tags should probly look like this instead :
http_client_requests_active_seconds_count{client_name="com.example.demo.TestFeignClient",method="GET",status="CLIENT_ERROR",uri="/outside/test"} 0
http_client_requests_active_seconds_sum{client_name="com.example.demo.TestFeignClient",method="GET",status="CLIENT_ERROR",uri="/outside/test"} 0.0
Sample
I have a simple repro here
Just run the tests and they will fail. If you replace the restTemplateBuilder.build() by new RestTemplate() the test passes. Demonstrating that the problem effectively comes from the restTemplate being observerd.
Below the classes in the project :
@SpringBootApplication
@RestController
@EnableFeignClients
@RequiredArgsConstructor
public class TestApplication {
private final TestFeignClient testFeignClient;
@GetMapping("/test")
public String test() {
return testFeignClient.test();
}
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
@FeignClient(value = "TestFeignClient", name = "TestFeignClient", url = "http://localhost:9004")
public interface TestFeignClient {
@GetMapping("/outside/test")
String test();
}
@SpringBootTest(classes = TestApplication.class, webEnvironment = WebEnvironment.DEFINED_PORT, properties = {
"spring.application.name=demo",
"server.port=18080",
"management.tracing.enabled=true",
"management.prometheus.metrics.export.enabled=true",
"management.endpoints.web.exposure.include=prometheus"
})
@WireMockTest(httpPort = 9004)
class DemoTestApplicationTests {
@Autowired
private RestTemplateBuilder restTemplateBuilder;
@Test
void repro() {
WireMock.stubFor(get(urlPathEqualTo("/outside/test")) //
.willReturn(aResponse() //
.withStatus(200) //
.withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) //
.withBody("hello world")));
RestTemplate restTemplate = restTemplateBuilder.build(); // replace by "new RestTemplate()" for test to pass
String response = restTemplate.getForObject("http://localhost:18080/test", String.class);
assertAll(
() -> assertThat(response).isEqualTo("hello world"),
() -> assertThat(logAppender.list)
.extracting(ILoggingEvent::getMessage)
.noneMatch(msg -> msg.contains("registration has failed")),
() -> assertThat(restTemplate.getForObject("http://localhost:18080/actuator/prometheus", String.class))
.contains("http_client_requests_active_seconds_count{clientName=\"com.example.demo.TestFeignClient")
);
}
// setup of log appender to capture logs
private ListAppender<ILoggingEvent> logAppender;
private Logger logger;
@BeforeEach
void setUp() {
logger = (Logger) LoggerFactory.getLogger(io.micrometer.prometheusmetrics.PrometheusMeterRegistry.class);
logAppender = new ListAppender<>();
logAppender.start();
logger.addAppender(logAppender);
}
@AfterEach
void tearDown() {
logger.detachAppender(logAppender);
}
}
- 主要言語
- Java
- スター
- 1.3k
- フォーク
- 834
- 平均マージ
- 3日 6時間
- マージ済み PR(30日)
- 14
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
spring-cloud/spring-cloud-openfeign のほかの issue
-
@RequestHeader overrides @PathVariable with the same name再び着手できるかも @rajeshvasa が 11 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンwaiting-for-triage
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
spring-cloud/spring-cloud-openfeign#1465 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
question
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
spring-cloud/spring-cloud-openfeign#1392 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
FeignClientsConfiguration$MicrometerConfiguration.class cannot be opened because it does not existオープンfeedback-provided
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
spring-cloud/spring-cloud-openfeign#1379 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
waiting-for-triage
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
spring-cloud/spring-cloud-openfeign#1340 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
dependencies
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
spring-cloud/spring-cloud-openfeign#1334 · コメント 11 件 · リアクション 4 件 ·
メンテナーはふだん 1 日以内に返信
spring-cloud/spring-cloud-openfeign の issue をすべて見る
似ている issue
-
Add contributing guide対応中かも @WadekarPrashant が今日担当しました。 オープンgood first issue
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
jenkinsci/gitea-checks-plugin#382 · コメント 1 件 ·
-
enhancement infra
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
メンテナーはふだん 1 日以内に返信
-
5.0.x backport bug
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
spring-cloud/spring-cloud-function#1569 ·
メンテナーはふだん 1 日以内に返信
-
Move the spring-cloud-commons version and BOM import from the bus parent to the stream parent対応中かも @olegz が今日担当しました。 オープンtask
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
spring-cloud/spring-cloud-stream#3355 ·
メンテナーはふだん 1 日以内に返信
-
bug untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
opensearch-project/opensearch-java#2342 ·
メンテナーはふだん 1 日以内に返信