Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
3eef9274
Commit
3eef9274
authored
Sep 03, 2018
by
Johnny Lim
Committed by
Stephane Nicoll
Sep 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use InvalidEndpointRequestException for MetricsEndpoint
Closes gh-14291
parent
72ebfb03
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
3 deletions
+19
-3
MetricsEndpoint.java
...springframework/boot/actuate/metrics/MetricsEndpoint.java
+6
-3
MetricsEndpointTests.java
...gframework/boot/actuate/metrics/MetricsEndpointTests.java
+13
-0
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java
View file @
3eef9274
...
...
@@ -34,11 +34,11 @@ import io.micrometer.core.instrument.Statistic;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.composite.CompositeMeterRegistry
;
import
org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.ReadOperation
;
import
org.springframework.boot.actuate.endpoint.annotation.Selector
;
import
org.springframework.lang.Nullable
;
import
org.springframework.util.Assert
;
/**
* An {@link Endpoint} for exposing the metrics held by a {@link MeterRegistry}.
...
...
@@ -80,8 +80,6 @@ public class MetricsEndpoint {
@ReadOperation
public
MetricResponse
metric
(
@Selector
String
requiredMetricName
,
@Nullable
List
<
String
>
tag
)
{
Assert
.
isTrue
(
tag
==
null
||
tag
.
stream
().
allMatch
((
t
)
->
t
.
contains
(
":"
)),
"Each tag parameter must be in the form key:value"
);
List
<
Tag
>
tags
=
parseTags
(
tag
);
List
<
Meter
>
meters
=
new
ArrayList
<>();
collectMeters
(
meters
,
this
.
registry
,
requiredMetricName
,
tags
);
...
...
@@ -106,6 +104,11 @@ public class MetricsEndpoint {
private
Tag
parseTag
(
String
tag
)
{
String
[]
parts
=
tag
.
split
(
":"
,
2
);
if
(
parts
.
length
!=
2
)
{
throw
new
InvalidEndpointRequestException
(
"Each tag parameter must be in the form 'key:value' but was: "
+
tag
,
"Each tag parameter must be in the form 'key:value'"
);
}
return
Tag
.
of
(
parts
[
0
],
parts
[
1
]);
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointTests.java
View file @
3eef9274
...
...
@@ -27,7 +27,11 @@ import io.micrometer.core.instrument.Statistic;
import
io.micrometer.core.instrument.composite.CompositeMeterRegistry
;
import
io.micrometer.core.instrument.simple.SimpleConfig
;
import
io.micrometer.core.instrument.simple.SimpleMeterRegistry
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -39,6 +43,9 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public
class
MetricsEndpointTests
{
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
private
final
MeterRegistry
registry
=
new
SimpleMeterRegistry
(
SimpleConfig
.
DEFAULT
,
new
MockClock
());
...
...
@@ -109,6 +116,12 @@ public class MetricsEndpointTests {
assertThat
(
getCount
(
response
)).
hasValue
(
2.0
);
}
@Test
public
void
metricWithInvalidTag
()
{
this
.
thrown
.
expect
(
InvalidEndpointRequestException
.
class
);
this
.
endpoint
.
metric
(
"counter"
,
Collections
.
singletonList
(
"key"
));
}
@Test
public
void
metricPresentInOneRegistryOfACompositeAndNotAnother
()
{
CompositeMeterRegistry
composite
=
new
CompositeMeterRegistry
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment