diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsRegistrarConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsRegistrarConfiguration.java index d1b402ec36f..9c074c77da9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsRegistrarConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsRegistrarConfiguration.java @@ -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); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfigurationTests.java index 556b5312895..5c16b62c693 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfigurationTests.java @@ -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(); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListener.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListener.java index 90d682b34ae..3c6cc84cb46 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListener.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListener.java @@ -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 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; } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java index df7c74a50cd..cb22d65a025 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java @@ -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); } /** diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java index 6d0af88c6b7..c75aaa67602 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java @@ -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); } /** diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListenerTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListenerTests.java index 34763a6fbcd..8c0cd13534a 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListenerTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListenerTests.java @@ -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()); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTagsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTagsTests.java index 17be58c7031..5c3b092aff4 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTagsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTagsTests.java @@ -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")); + } + } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProviderTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProviderTests.java index 5358fd35776..f30dd37f26f 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProviderTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProviderTests.java @@ -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 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 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 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 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 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")); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java index 3ba0a4eed9e..1a7b5538e6c 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java @@ -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