Skip to content

Commit 2bbc638

Browse files
committed
Merge branch '1.13.x' into 1.14.x
2 parents f6d2255 + 2ee39cc commit 2bbc638

File tree

13 files changed

+564
-14
lines changed

13 files changed

+564
-14
lines changed

Diff for: micrometer-core/src/main/java/io/micrometer/core/aop/CountedAspect.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.micrometer.core.aop;
1717

18+
import io.micrometer.common.KeyValue;
1819
import io.micrometer.common.lang.NonNullApi;
1920
import io.micrometer.common.lang.Nullable;
2021
import io.micrometer.common.util.internal.logging.WarnThenDebugLogger;
@@ -83,7 +84,7 @@ public class CountedAspect {
8384

8485
private static final Predicate<ProceedingJoinPoint> DONT_SKIP_ANYTHING = pjp -> false;
8586

86-
public final String DEFAULT_EXCEPTION_TAG_VALUE = "none";
87+
public final String DEFAULT_EXCEPTION_TAG_VALUE = KeyValue.NONE_VALUE;
8788

8889
public final String RESULT_TAG_FAILURE_VALUE = "failure";
8990

Diff for: micrometer-core/src/main/java/io/micrometer/core/aop/TimedAspect.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.micrometer.core.aop;
1717

18+
import io.micrometer.common.KeyValue;
1819
import io.micrometer.common.lang.NonNullApi;
1920
import io.micrometer.common.lang.Nullable;
2021
import io.micrometer.common.util.internal.logging.WarnThenDebugLogger;
@@ -96,7 +97,7 @@ public class TimedAspect {
9697

9798
public static final String DEFAULT_METRIC_NAME = "method.timed";
9899

99-
public static final String DEFAULT_EXCEPTION_TAG_VALUE = "none";
100+
public static final String DEFAULT_EXCEPTION_TAG_VALUE = KeyValue.NONE_VALUE;
100101

101102
/**
102103
* Tag key for an exception.

Diff for: micrometer-core/src/main/java/io/micrometer/core/instrument/binder/commonspool2/CommonsObjectPool2Metrics.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.micrometer.core.instrument.binder.commonspool2;
1717

18+
import io.micrometer.common.KeyValue;
1819
import io.micrometer.common.lang.NonNull;
1920
import io.micrometer.common.lang.Nullable;
2021
import io.micrometer.common.util.internal.logging.InternalLogger;
@@ -129,17 +130,18 @@ public void bindTo(@NonNull MeterRegistry registry) {
129130

130131
private Iterable<Tag> nameTag(ObjectName name, String type)
131132
throws AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException {
132-
return Tags.of("name", name.getKeyProperty("name"), "type", type, "factoryType", getFactoryType(name, type));
133+
return Tags.of("name", name.getKeyProperty("name"), "type", type, "factoryType",
134+
getFactoryTypeTagValue(name, type));
133135
}
134136

135-
private String getFactoryType(ObjectName name, String type)
137+
private String getFactoryTypeTagValue(ObjectName name, String type)
136138
throws ReflectionException, AttributeNotFoundException, InstanceNotFoundException, MBeanException {
137139
if (Objects.equals(type, "GenericObjectPool")) {
138140
// for GenericObjectPool, we want to include the name and factoryType as tags
139141
return mBeanServer.getAttribute(name, "FactoryType").toString();
140142
}
141143
else {
142-
return "none";
144+
return KeyValue.NONE_VALUE;
143145
}
144146
}
145147

Diff for: micrometer-core/src/main/java/io/micrometer/core/instrument/binder/db/JooqExecuteListener.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.micrometer.core.instrument.binder.db;
1717

18+
import io.micrometer.common.KeyValue;
1819
import io.micrometer.common.util.StringUtils;
1920
import io.micrometer.core.instrument.MeterRegistry;
2021
import io.micrometer.core.instrument.Tag;
@@ -84,8 +85,8 @@ private void stopTimerIfStillRunning(ExecuteContext ctx) {
8485
if (sample == null)
8586
return;
8687

87-
String exceptionName = "none";
88-
String exceptionSubclass = "none";
88+
String exceptionName = KeyValue.NONE_VALUE;
89+
String exceptionSubclass = KeyValue.NONE_VALUE;
8990

9091
Exception exception = ctx.exception();
9192
if (exception != null) {
@@ -94,7 +95,7 @@ private void stopTimerIfStillRunning(ExecuteContext ctx) {
9495
exceptionName = dae.sqlStateClass().name().toLowerCase().replace('_', ' ');
9596
exceptionSubclass = dae.sqlStateSubclass().name().toLowerCase().replace('_', ' ');
9697
if (exceptionSubclass.contains("no subclass")) {
97-
exceptionSubclass = "none";
98+
exceptionSubclass = KeyValue.NONE_VALUE;
9899
}
99100
}
100101
else {

Diff for: micrometer-core/src/main/java/io/micrometer/core/instrument/binder/okhttp3/OkHttpMetricsEventListener.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.micrometer.core.instrument.binder.okhttp3;
1717

18+
import io.micrometer.common.KeyValue;
1819
import io.micrometer.common.lang.NonNullApi;
1920
import io.micrometer.common.lang.NonNullFields;
2021
import io.micrometer.common.lang.Nullable;
@@ -269,7 +270,7 @@ public static class Builder {
269270
private final String name;
270271

271272
private Function<Request, String> uriMapper = (request) -> Optional.ofNullable(request.header(URI_PATTERN))
272-
.orElse("none");
273+
.orElse(KeyValue.NONE_VALUE);
273274

274275
private Tags tags = Tags.empty();
275276

Diff for: micrometer-core/src/main/java/io/micrometer/core/instrument/binder/okhttp3/OkHttpObservationInterceptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static class Builder {
144144
private final ObservationRegistry registry;
145145

146146
private Function<Request, String> uriMapper = (request) -> Optional.ofNullable(request.header(URI_PATTERN))
147-
.orElse("none");
147+
.orElse(KeyValue.NONE_VALUE);
148148

149149
private KeyValues tags = KeyValues.empty();
150150

Diff for: micrometer-core/src/main/java/io/micrometer/core/instrument/observation/DefaultMeterObservationHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void onEvent(Observation.Event event, Observation.Context context) {
105105

106106
private String getErrorValue(Observation.Context context) {
107107
Throwable error = context.getError();
108-
return error != null ? error.getClass().getSimpleName() : "none";
108+
return error != null ? error.getClass().getSimpleName() : KeyValue.NONE_VALUE;
109109
}
110110

111111
private List<Tag> createTags(Observation.Context context) {

Diff for: micrometer-core/src/test/java/io/micrometer/core/instrument/binder/kafka/KafkaMetricsTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import io.micrometer.core.instrument.MeterRegistry;
2222
import io.micrometer.core.instrument.Tag;
2323
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
24+
import io.micrometer.core.testsupport.system.CapturedOutput;
25+
import io.micrometer.core.testsupport.system.OutputCaptureExtension;
2426
import org.apache.kafka.common.Metric;
2527
import org.apache.kafka.common.MetricName;
2628
import org.apache.kafka.common.metrics.KafkaMetric;
@@ -29,6 +31,7 @@
2931
import org.apache.kafka.common.utils.Time;
3032
import org.junit.jupiter.api.AfterEach;
3133
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.extension.ExtendWith;
3235

3336
import java.util.Collections;
3437
import java.util.HashMap;
@@ -42,6 +45,7 @@
4245
import static org.assertj.core.api.Assertions.assertThat;
4346
import static org.awaitility.Awaitility.await;
4447

48+
@ExtendWith(OutputCaptureExtension.class)
4549
class KafkaMetricsTest {
4650

4751
private KafkaMetrics kafkaMetrics;
@@ -286,7 +290,7 @@ void shouldRemoveOlderMeterWithLessTagsWhenCommonTagsConfigured() {
286290

287291
@Issue("#2212")
288292
@Test
289-
void shouldRemoveMeterWithLessTagsWithMultipleClients() {
293+
void shouldRemoveMeterWithLessTagsWithMultipleClients(CapturedOutput output) {
290294
// Given
291295
AtomicReference<Map<MetricName, KafkaMetric>> metrics = new AtomicReference<>(new LinkedHashMap<>());
292296
Supplier<Map<MetricName, ? extends Metric>> supplier = () -> metrics.updateAndGet(map -> {
@@ -349,6 +353,8 @@ void shouldRemoveMeterWithLessTagsWithMultipleClients() {
349353
registry.getMeters()
350354
.forEach(meter -> assertThat(meter.getId().getTags()).extracting(Tag::getKey)
351355
.containsOnly("key0", "key1", "client.id", "kafka.version"));
356+
357+
assertThat(output).doesNotContain("This Gauge has been already registered");
352358
}
353359

354360
@Issue("#2726")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.micrometer.core.testsupport.system;
18+
19+
/**
20+
* Provides access to {@link System#out System.out} and {@link System#err System.err}
21+
* output that has been captured by the {@link OutputCaptureExtension}. Can be used to
22+
* apply assertions either using AssertJ or standard JUnit assertions. For example:
23+
* <pre class="code">
24+
* assertThat(output).contains("started"); // Checks all output
25+
* assertThat(output.getErr()).contains("failed"); // Only checks System.err
26+
* assertThat(output.getOut()).contains("ok"); // Only checks System.out
27+
* </pre>
28+
* <p>
29+
* Copied from <a href=
30+
* "https://github.com/spring-projects/spring-boot/blob/88c9ae97b5638491964537bb5b1f7dfbea1ae047/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/system/CapturedOutput.java">org.springframework.boot.test.system.CapturedOutput</a>
31+
* in Spring Boot.
32+
*
33+
* @author Madhura Bhave
34+
* @author Phillip Webb
35+
* @author Andy Wilkinson
36+
* @see OutputCaptureExtension
37+
*/
38+
public interface CapturedOutput extends CharSequence {
39+
40+
@Override
41+
default int length() {
42+
return toString().length();
43+
}
44+
45+
@Override
46+
default char charAt(int index) {
47+
return toString().charAt(index);
48+
}
49+
50+
@Override
51+
default CharSequence subSequence(int start, int end) {
52+
return toString().subSequence(start, end);
53+
}
54+
55+
/**
56+
* Return all content (both {@link System#out System.out} and {@link System#err
57+
* System.err}) in the order that it was captured.
58+
* @return all captured output
59+
*/
60+
String getAll();
61+
62+
/**
63+
* Return {@link System#out System.out} content in the order that it was captured.
64+
* @return {@link System#out System.out} captured output
65+
*/
66+
String getOut();
67+
68+
/**
69+
* Return {@link System#err System.err} content in the order that it was captured.
70+
* @return {@link System#err System.err} captured output
71+
*/
72+
String getErr();
73+
74+
}

0 commit comments

Comments
 (0)