Duplicate observations recorded with RestClient #33068
Closed
Description
Hi,
I'm using spring-boot 3.3.0 (spring-framework 6.1.8). After migration from spring-boot 3.2.5, the metrics are false because the timer for RestClient counts twice the calls (http.client.request
).
This can be reproduced with a simple spring boot test:
@Test
void restClientMetricsBug() {
// registry and clientBuilder are injected
clientBuilder.baseUrl("http://localhost:8080").build().get().retrieve().toEntity(String.class);
var tm = registry.get("http.client.requests").timer();
assertEquals(1, tm.count()); // fails with 1 != 2
}
The problem seems to be (to my opinion) that Timer.stop is called twice:
- the first time on DefaultRestClient L230 because
clientResponse
isAutoClosable
(close stops the observation), - the second time in
finally
on L254 (observation.stop is called a second time) (observation.stop() calls indirectly Timer$Sample.stop()).
I hope my analysis will be helpfull.
Thanks.