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
42135cd5
Commit
42135cd5
authored
Jan 30, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Aggregate max statistics in metrics endpoint with Double#max"
Closes gh-11852
parent
92287f75
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
9 deletions
+11
-9
MetricsEndpoint.java
...springframework/boot/actuate/metrics/MetricsEndpoint.java
+4
-2
MetricsEndpointTests.java
...gframework/boot/actuate/metrics/MetricsEndpointTests.java
+7
-7
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java
View file @
42135cd5
...
...
@@ -120,8 +120,10 @@ public class MetricsEndpoint {
}
private
void
mergeMeasurements
(
Map
<
Statistic
,
Double
>
samples
,
Meter
meter
)
{
meter
.
measure
().
forEach
((
measurement
)
->
samples
.
merge
(
measurement
.
getStatistic
(),
measurement
.
getValue
(),
mergeFunction
(
measurement
.
getStatistic
())));
meter
.
measure
()
.
forEach
((
measurement
)
->
samples
.
merge
(
measurement
.
getStatistic
(),
measurement
.
getValue
(),
mergeFunction
(
measurement
.
getStatistic
())));
}
private
BiFunction
<
Double
,
Double
,
Double
>
mergeFunction
(
Statistic
statistic
)
{
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointTests.java
View file @
42135cd5
...
...
@@ -135,7 +135,6 @@ public class MetricsEndpointTests {
SimpleMeterRegistry
reg
=
new
SimpleMeterRegistry
();
reg
.
timer
(
"timer"
,
"k"
,
"v1"
).
record
(
1
,
TimeUnit
.
SECONDS
);
reg
.
timer
(
"timer"
,
"k"
,
"v2"
).
record
(
2
,
TimeUnit
.
SECONDS
);
assertMetricHasStatisticEqualTo
(
reg
,
"timer"
,
Statistic
.
MAX
,
2.0
);
}
...
...
@@ -144,21 +143,22 @@ public class MetricsEndpointTests {
SimpleMeterRegistry
reg
=
new
SimpleMeterRegistry
();
reg
.
counter
(
"counter"
,
"k"
,
"v1"
).
increment
();
reg
.
counter
(
"counter"
,
"k"
,
"v2"
).
increment
();
assertMetricHasStatisticEqualTo
(
reg
,
"counter"
,
Statistic
.
COUNT
,
2.0
);
}
private
void
assertMetricHasStatisticEqualTo
(
MeterRegistry
registry
,
String
metricName
,
Statistic
stat
,
Double
value
)
{
private
void
assertMetricHasStatisticEqualTo
(
MeterRegistry
registry
,
String
metricName
,
Statistic
stat
,
Double
value
)
{
MetricsEndpoint
endpoint
=
new
MetricsEndpoint
(
registry
);
assertThat
(
endpoint
.
metric
(
metricName
,
Collections
.
emptyList
()).
getMeasurements
()
.
stream
().
filter
(
s
->
s
.
getStatistic
().
equals
(
stat
)).
findAny
())
.
hasValueSatisfying
(
s
->
assertThat
(
s
.
getValue
()).
isEqualTo
(
value
));
.
stream
().
filter
((
sample
)
->
sample
.
getStatistic
().
equals
(
stat
))
.
findAny
()).
hasValueSatisfying
(
(
sample
)
->
assertThat
(
sample
.
getValue
()).
isEqualTo
(
value
));
}
private
Optional
<
Double
>
getCount
(
MetricsEndpoint
.
MetricResponse
response
)
{
return
response
.
getMeasurements
().
stream
()
.
filter
((
ms
)
->
ms
.
getStatistic
().
equals
(
Statistic
.
COUNT
)).
findAny
(
)
.
map
(
MetricsEndpoint
.
Sample
::
getValue
);
.
filter
((
sample
)
->
sample
.
getStatistic
().
equals
(
Statistic
.
COUNT
)
)
.
findAny
().
map
(
MetricsEndpoint
.
Sample
::
getValue
);
}
private
Stream
<
String
>
availableTagKeys
(
MetricsEndpoint
.
MetricResponse
response
)
{
...
...
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