Merge branch '2.7.x'

This commit is contained in:
Andy Wilkinson 2022-04-11 15:23:10 +01:00
commit 8d18e5fc0e
9 changed files with 40 additions and 30 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -72,7 +72,7 @@ class CacheMetricsRegistrarConfiguration {
}
private void bindCacheToRegistry(String beanName, Cache cache) {
Tag cacheManagerTag = Tag.of("cacheManager", getCacheManagerName(beanName));
Tag cacheManagerTag = Tag.of("cache.manager", getCacheManagerName(beanName));
this.cacheMetricsRegistrar.bindCacheToRegistry(cache, cacheManagerTag);
}

View File

@ -44,8 +44,8 @@ class CacheMetricsAutoConfigurationTests {
this.contextRunner.withPropertyValues("spring.cache.type=cache2k", "spring.cache.cache-names=cache1,cache2")
.run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
registry.get("cache.gets").tags("name", "cache1").tags("cacheManager", "cacheManager").meter();
registry.get("cache.gets").tags("name", "cache2").tags("cacheManager", "cacheManager").meter();
registry.get("cache.gets").tags("name", "cache1").tags("cache.manager", "cacheManager").meter();
registry.get("cache.gets").tags("name", "cache2").tags("cache.manager", "cacheManager").meter();
});
}
@ -54,8 +54,8 @@ class CacheMetricsAutoConfigurationTests {
this.contextRunner.withPropertyValues("spring.cache.type=caffeine", "spring.cache.cache-names=cache1,cache2")
.run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
registry.get("cache.gets").tags("name", "cache1").tags("cacheManager", "cacheManager").meter();
registry.get("cache.gets").tags("name", "cache2").tags("cacheManager", "cacheManager").meter();
registry.get("cache.gets").tags("name", "cache1").tags("cache.manager", "cacheManager").meter();
registry.get("cache.gets").tags("name", "cache2").tags("cache.manager", "cacheManager").meter();
});
}
@ -64,9 +64,9 @@ class CacheMetricsAutoConfigurationTests {
this.contextRunner.withPropertyValues("spring.cache.type=simple", "spring.cache.cache-names=cache1,cache2")
.run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
assertThat(registry.find("cache.gets").tags("name", "cache1").tags("cacheManager", "cacheManager")
assertThat(registry.find("cache.gets").tags("name", "cache1").tags("cache.manager", "cacheManager")
.meter()).isNull();
assertThat(registry.find("cache.gets").tags("name", "cache2").tags("cacheManager", "cacheManager")
assertThat(registry.find("cache.gets").tags("name", "cache2").tags("cache.manager", "cacheManager")
.meter()).isNull();
});
}
@ -77,7 +77,7 @@ class CacheMetricsAutoConfigurationTests {
"spring.cache.cache-names=cache1").run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
assertThat(registry.find("cache.requests").tags("name", "cache1")
.tags("cacheManager", "cacheManager").meter()).isNull();
.tags("cache.manager", "cacheManager").meter()).isNull();
});
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -123,7 +123,7 @@ public class StartupTimeMetricsListener implements SmartApplicationListener {
private Iterable<Tag> createTagsFrom(SpringApplication springApplication) {
Class<?> mainClass = springApplication.getMainApplicationClass();
return (mainClass != null) ? this.tags.and("main-application-class", mainClass.getName()) : this.tags;
return (mainClass != null) ? this.tags.and("main.application.class", mainClass.getName()) : this.tags;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -105,17 +105,17 @@ public final class RestTemplateExchangeTags {
}
/**
* Create a {@code clientName} {@code Tag} derived from the {@link URI#getHost host}
* Create a {@code client.name} {@code Tag} derived from the {@link URI#getHost host}
* of the {@link HttpRequest#getURI() URI} of the given {@code request}.
* @param request the request
* @return the clientName tag
* @return the client.name tag
*/
public static Tag clientName(HttpRequest request) {
String host = request.getURI().getHost();
if (host == null) {
host = "none";
}
return Tag.of("clientName", host);
return Tag.of("client.name", host);
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ public final class WebClientExchangeTags {
private static final Pattern PATTERN_BEFORE_PATH = Pattern.compile("^https?://[^/]+/");
private static final Tag CLIENT_NAME_NONE = Tag.of("clientName", "none");
private static final Tag CLIENT_NAME_NONE = Tag.of("client.name", "none");
private WebClientExchangeTags() {
}
@ -95,18 +95,18 @@ public final class WebClientExchangeTags {
}
/**
* Create a {@code clientName} {@code Tag} derived from the
* Create a {@code client.name} {@code Tag} derived from the
* {@link java.net.URI#getHost host} of the {@link ClientRequest#url() URL} of the
* given {@code request}.
* @param request the request
* @return the clientName tag
* @return the client.name tag
*/
public static Tag clientName(ClientRequest request) {
String host = request.url().getHost();
if (host == null) {
return CLIENT_NAME_NONE;
}
return Tag.of("clientName", host);
return Tag.of("client.name", host);
}
/**

View File

@ -118,7 +118,7 @@ class StartupTimeMetricsListenerTests {
private void assertMetricExistsWithCustomTagsAndValue(String metricName, Tags expectedCustomTags,
Long expectedValueInMillis) {
assertThat(this.registry.find(metricName)
.tags(Tags.concat(expectedCustomTags, "main-application-class", TestMainApplication.class.getName()))
.tags(Tags.concat(expectedCustomTags, "main.application.class", TestMainApplication.class.getName()))
.timeGauge()).isNotNull().extracting((m) -> m.value(TimeUnit.MILLISECONDS))
.isEqualTo(expectedValueInMillis.doubleValue());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,11 +17,13 @@
package org.springframework.boot.actuate.metrics.web.client;
import java.io.IOException;
import java.net.URI;
import io.micrometer.core.instrument.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.mock.http.client.MockClientHttpResponse;
@ -102,4 +104,12 @@ class RestTemplateExchangeTagsTests {
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}
@Test
void clientNameTagIsHostOfRequestUri() throws IOException {
ClientHttpRequest request = mock(ClientHttpRequest.class);
given(request.getURI()).willReturn(URI.create("https://example.org"));
Tag tag = RestTemplateExchangeTags.clientName(request);
assertThat(tag).isEqualTo(Tag.of("client.name", "example.org"));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ class DefaultWebClientExchangeTagsProviderTests {
void tagsShouldBePopulated() {
Iterable<Tag> tags = this.tagsProvider.tags(this.request, this.response, null);
assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"),
Tag.of("clientName", "example.org"), Tag.of("status", "200"), Tag.of("outcome", "SUCCESS"));
Tag.of("client.name", "example.org"), Tag.of("status", "200"), Tag.of("outcome", "SUCCESS"));
}
@Test
@ -70,28 +70,28 @@ class DefaultWebClientExchangeTagsProviderTests {
.create(HttpMethod.GET, URI.create("https://example.org/projects/spring-boot")).build();
Iterable<Tag> tags = this.tagsProvider.tags(request, this.response, null);
assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/spring-boot"),
Tag.of("clientName", "example.org"), Tag.of("status", "200"), Tag.of("outcome", "SUCCESS"));
Tag.of("client.name", "example.org"), Tag.of("status", "200"), Tag.of("outcome", "SUCCESS"));
}
@Test
void tagsWhenIoExceptionShouldReturnIoErrorStatus() {
Iterable<Tag> tags = this.tagsProvider.tags(this.request, null, new IOException());
assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"),
Tag.of("clientName", "example.org"), Tag.of("status", "IO_ERROR"), Tag.of("outcome", "UNKNOWN"));
Tag.of("client.name", "example.org"), Tag.of("status", "IO_ERROR"), Tag.of("outcome", "UNKNOWN"));
}
@Test
void tagsWhenExceptionShouldReturnClientErrorStatus() {
Iterable<Tag> tags = this.tagsProvider.tags(this.request, null, new IllegalArgumentException());
assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"),
Tag.of("clientName", "example.org"), Tag.of("status", "CLIENT_ERROR"), Tag.of("outcome", "UNKNOWN"));
Tag.of("client.name", "example.org"), Tag.of("status", "CLIENT_ERROR"), Tag.of("outcome", "UNKNOWN"));
}
@Test
void tagsWhenCancelledRequestShouldReturnClientErrorStatus() {
Iterable<Tag> tags = this.tagsProvider.tags(this.request, null, null);
assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"),
Tag.of("clientName", "example.org"), Tag.of("status", "CLIENT_ERROR"), Tag.of("outcome", "UNKNOWN"));
Tag.of("client.name", "example.org"), Tag.of("status", "CLIENT_ERROR"), Tag.of("outcome", "UNKNOWN"));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -88,7 +88,7 @@ class WebClientExchangeTagsTests {
@Test
void clientName() {
assertThat(WebClientExchangeTags.clientName(this.request)).isEqualTo(Tag.of("clientName", "example.org"));
assertThat(WebClientExchangeTags.clientName(this.request)).isEqualTo(Tag.of("client.name", "example.org"));
}
@Test