Skip to content

Commit e85bd44

Browse files
committed
Use InvalidEndpointRequestException for MetricsEndpoint.metric()
1 parent 314cd34 commit e85bd44

File tree

1 file changed

+7
-3
lines changed
  • spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
import io.micrometer.core.instrument.Tag;
3535
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
3636

37+
import org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException;
3738
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
3839
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
3940
import org.springframework.boot.actuate.endpoint.annotation.Selector;
4041
import org.springframework.lang.Nullable;
41-
import org.springframework.util.Assert;
4242

4343
/**
4444
* An {@link Endpoint} for exposing the metrics held by a {@link MeterRegistry}.
@@ -80,8 +80,12 @@ private String getName(Meter meter) {
8080
@ReadOperation
8181
public MetricResponse metric(@Selector String requiredMetricName,
8282
@Nullable List<String> tag) {
83-
Assert.isTrue(tag == null || tag.stream().allMatch((t) -> t.contains(":")),
84-
"Each tag parameter must be in the form key:value");
83+
if (tag != null && tag.stream().anyMatch((t) -> !t.contains(":"))) {
84+
throw new InvalidEndpointRequestException(
85+
"Each tag parameter must be in the form 'key:value' but tags are: "
86+
+ tag,
87+
"Each tag parameter must be in the form 'key:value'");
88+
}
8589
List<Tag> tags = parseTags(tag);
8690
List<Meter> meters = new ArrayList<>();
8791
collectMeters(meters, this.registry, requiredMetricName, tags);

0 commit comments

Comments
 (0)