Commit 0669f560 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '2.4.x'

Closes gh-24873
parents c6ce97b8 59b01324
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -25,6 +25,8 @@ import java.util.concurrent.TimeUnit; ...@@ -25,6 +25,8 @@ import java.util.concurrent.TimeUnit;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.Timer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.actuate.metrics.AutoTimer; import org.springframework.boot.actuate.metrics.AutoTimer;
import org.springframework.core.NamedThreadLocal; import org.springframework.core.NamedThreadLocal;
...@@ -43,6 +45,8 @@ import org.springframework.web.util.UriTemplateHandler; ...@@ -43,6 +45,8 @@ import org.springframework.web.util.UriTemplateHandler;
*/ */
class MetricsClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { class MetricsClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
private static final Log logger = LogFactory.getLog(MetricsClientHttpRequestInterceptor.class);
private static final ThreadLocal<Deque<String>> urlTemplate = new UrlTemplateThreadLocal(); private static final ThreadLocal<Deque<String>> urlTemplate = new UrlTemplateThreadLocal();
private final MeterRegistry meterRegistry; private final MeterRegistry meterRegistry;
...@@ -82,8 +86,13 @@ class MetricsClientHttpRequestInterceptor implements ClientHttpRequestIntercepto ...@@ -82,8 +86,13 @@ class MetricsClientHttpRequestInterceptor implements ClientHttpRequestIntercepto
return response; return response;
} }
finally { finally {
getTimeBuilder(request, response).register(this.meterRegistry).record(System.nanoTime() - startTime, try {
TimeUnit.NANOSECONDS); getTimeBuilder(request, response).register(this.meterRegistry).record(System.nanoTime() - startTime,
TimeUnit.NANOSECONDS);
}
catch (Exception ex) {
logger.info("Failed to record metrics.", ex);
}
if (urlTemplate.get().isEmpty()) { if (urlTemplate.get().isEmpty()) {
urlTemplate.remove(); urlTemplate.remove();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment