Skip to content

Commit aeadb0c

Browse files
committed
Merge branch '2.4.x' into 2.5.x
Closes gh-28351
2 parents a9df8c3 + 540468b commit aeadb0c

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValue.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ private Long getTimerValue() {
8686
* @return a {@link MeterValue} instance
8787
*/
8888
public static MeterValue valueOf(String value) {
89-
Double number = safeParseDouble(value);
90-
if (number != null) {
91-
return new MeterValue(number);
89+
Duration duration = safeParseDuration(value);
90+
if (duration != null) {
91+
return new MeterValue(duration);
9292
}
93-
return new MeterValue(DurationStyle.detectAndParse(value));
93+
return new MeterValue(Double.valueOf(value));
9494
}
9595

9696
/**
@@ -103,11 +103,11 @@ public static MeterValue valueOf(double value) {
103103
return new MeterValue(value);
104104
}
105105

106-
private static Double safeParseDouble(String value) {
106+
private static Duration safeParseDuration(String value) {
107107
try {
108-
return Double.valueOf(value);
108+
return DurationStyle.detectAndParse(value);
109109
}
110-
catch (NumberFormatException ex) {
110+
catch (IllegalArgumentException ex) {
111111
return null;
112112
}
113113
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsProperties.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,21 @@ public static class Distribution {
277277
/**
278278
* Specific service-level objective boundaries for meter IDs starting with the
279279
* specified name. The longest match wins. Counters will be published for each
280-
* specified boundary. Values can be specified as a long or as a Duration value
280+
* specified boundary. Values can be specified as a double or as a Duration value
281281
* (for timer meters, defaulting to ms if no unit specified).
282282
*/
283283
private final Map<String, ServiceLevelObjectiveBoundary[]> slo = new LinkedHashMap<>();
284284

285285
/**
286286
* Minimum value that meter IDs starting with the specified name are expected to
287-
* observe. The longest match wins. Values can be specified as a long or as a
287+
* observe. The longest match wins. Values can be specified as a double or as a
288288
* Duration value (for timer meters, defaulting to ms if no unit specified).
289289
*/
290290
private final Map<String, String> minimumExpectedValue = new LinkedHashMap<>();
291291

292292
/**
293293
* Maximum value that meter IDs starting with the specified name are expected to
294-
* observe. The longest match wins. Values can be specified as a long or as a
294+
* observe. The longest match wins. Values can be specified as a double or as a
295295
* Duration value (for timer meters, defaulting to ms if no unit specified).
296296
*/
297297
private final Map<String, String> maximumExpectedValue = new LinkedHashMap<>();

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ServiceLevelObjectiveBoundaryTests.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.metrics;
1818

19+
import java.time.Duration;
20+
1921
import io.micrometer.core.instrument.Meter.Type;
2022
import org.junit.jupiter.api.Test;
2123

@@ -42,11 +44,17 @@ void getValueForTimerWhenFromNumberStringShouldMsToNanosValue() {
4244
}
4345

4446
@Test
45-
void getValueForTimerWhenFromDurationStringShouldReturnDurationNanos() {
47+
void getValueForTimerWhenFromMillisecondDurationStringShouldReturnDurationNanos() {
4648
ServiceLevelObjectiveBoundary slo = ServiceLevelObjectiveBoundary.valueOf("123ms");
4749
assertThat(slo.getValue(Type.TIMER)).isEqualTo(123000000);
4850
}
4951

52+
@Test
53+
void getValueForTimerWhenFromDaysDurationStringShouldReturnDurationNanos() {
54+
ServiceLevelObjectiveBoundary slo = ServiceLevelObjectiveBoundary.valueOf("1d");
55+
assertThat(slo.getValue(Type.TIMER)).isEqualTo(Duration.ofDays(1).toNanos());
56+
}
57+
5058
@Test
5159
void getValueForDistributionSummaryWhenFromDoubleShouldReturnDoubleValue() {
5260
ServiceLevelObjectiveBoundary slo = ServiceLevelObjectiveBoundary.valueOf(123.42);

0 commit comments

Comments
 (0)