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
49bab63c
Commit
49bab63c
authored
Sep 19, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update metrics endpoint to return list of distinct names
Closes gh-10336
parent
2ac6c107
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
2 deletions
+75
-2
MetricsEndpoint.java
...springframework/boot/actuate/metrics/MetricsEndpoint.java
+1
-1
MetricsEndpointTests.java
...gframework/boot/actuate/metrics/MetricsEndpointTests.java
+73
-0
MetricsEndpointWebIntegrationTests.java
...t/actuate/metrics/MetricsEndpointWebIntegrationTests.java
+1
-1
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java
View file @
49bab63c
...
...
@@ -53,7 +53,7 @@ public class MetricsEndpoint {
@ReadOperation
public
Map
<
String
,
List
<
String
>>
listNames
()
{
return
Collections
.
singletonMap
(
"names"
,
this
.
registry
.
getMeters
().
stream
()
.
map
(
this
::
getMeterIdName
).
collect
(
Collectors
.
toList
()));
.
map
(
this
::
getMeterIdName
).
distinct
().
collect
(
Collectors
.
toList
()));
}
private
String
getMeterIdName
(
Meter
meter
)
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointTests.java
0 → 100644
View file @
49bab63c
/*
* Copyright 2012-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
actuate
.
metrics
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
io.micrometer.core.instrument.Meter
;
import
io.micrometer.core.instrument.Meter.Id
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.simple.SimpleCounter
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link MetricsEndpoint}.
*
* @author Andy Wilkinson
*/
public
class
MetricsEndpointTests
{
private
final
MeterRegistry
registry
=
mock
(
MeterRegistry
.
class
);
private
final
MetricsEndpoint
endpoint
=
new
MetricsEndpoint
(
this
.
registry
);
@Test
public
void
listNamesHandlesEmptyListOfMeters
()
{
given
(
this
.
registry
.
getMeters
()).
willReturn
(
Arrays
.
asList
());
Map
<
String
,
List
<
String
>>
result
=
this
.
endpoint
.
listNames
();
assertThat
(
result
).
containsOnlyKeys
(
"names"
);
assertThat
(
result
.
get
(
"names"
)).
isEmpty
();
}
@Test
public
void
listNamesProducesListOfUniqueMeterNames
()
{
List
<
Meter
>
meters
=
Arrays
.
asList
(
createCounter
(
"com.example.foo"
),
createCounter
(
"com.example.bar"
),
createCounter
(
"com.example.foo"
));
given
(
this
.
registry
.
getMeters
()).
willReturn
(
meters
);
Map
<
String
,
List
<
String
>>
result
=
this
.
endpoint
.
listNames
();
assertThat
(
result
).
containsOnlyKeys
(
"names"
);
assertThat
(
result
.
get
(
"names"
)).
containsOnlyOnce
(
"com.example.foo"
,
"com.example.bar"
);
}
private
Meter
createCounter
(
String
name
)
{
return
new
SimpleCounter
(
createMeterId
(
name
));
}
private
Id
createMeterId
(
String
name
)
{
Id
id
=
mock
(
Id
.
class
);
given
(
id
.
getName
()).
willReturn
(
name
);
return
id
;
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointWebIntegrationTests.java
View file @
49bab63c
...
...
@@ -54,7 +54,7 @@ public class MetricsEndpointWebIntegrationTests {
.
uri
(
"/application/metrics"
).
exchange
().
expectStatus
().
isOk
()
.
expectBody
(
String
.
class
).
returnResult
().
getResponseBody
();
Map
<
String
,
List
<
String
>>
names
=
this
.
mapper
.
readValue
(
responseBody
,
Map
.
class
);
assertThat
(
names
.
get
(
"names"
)).
contains
(
"jvm.memory.used"
);
assertThat
(
names
.
get
(
"names"
)).
contains
OnlyOnce
(
"jvm.memory.used"
);
}
@Test
...
...
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