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
035e27b1
Commit
035e27b1
authored
May 02, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.4.x' into 1.5.x
parents
652a5e7b
8e5bf4b2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
3 deletions
+114
-3
PublicMetricsAutoConfiguration.java
...actuate/autoconfigure/PublicMetricsAutoConfiguration.java
+6
-2
CachePublicMetrics.java
...ngframework/boot/actuate/endpoint/CachePublicMetrics.java
+11
-1
CachePublicMetricsTests.java
...mework/boot/actuate/endpoint/CachePublicMetricsTests.java
+97
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfiguration.java
View file @
035e27b1
...
@@ -16,7 +16,9 @@
...
@@ -16,7 +16,9 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
;
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.Servlet
;
import
javax.servlet.Servlet
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
...
@@ -135,8 +137,10 @@ public class PublicMetricsAutoConfiguration {
...
@@ -135,8 +137,10 @@ public class PublicMetricsAutoConfiguration {
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean
@ConditionalOnBean
(
CacheStatisticsProvider
.
class
)
@ConditionalOnBean
(
CacheStatisticsProvider
.
class
)
public
CachePublicMetrics
cachePublicMetrics
()
{
public
CachePublicMetrics
cachePublicMetrics
(
return
new
CachePublicMetrics
();
Map
<
String
,
CacheManager
>
cacheManagers
,
Collection
<
CacheStatisticsProvider
<?>>
statisticsProviders
)
{
return
new
CachePublicMetrics
(
cacheManagers
,
statisticsProviders
);
}
}
}
}
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/CachePublicMetrics.java
View file @
035e27b1
/*
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -45,6 +45,16 @@ public class CachePublicMetrics implements PublicMetrics {
...
@@ -45,6 +45,16 @@ public class CachePublicMetrics implements PublicMetrics {
@Autowired
@Autowired
private
Collection
<
CacheStatisticsProvider
<?>>
statisticsProviders
;
private
Collection
<
CacheStatisticsProvider
<?>>
statisticsProviders
;
@Deprecated
public
CachePublicMetrics
()
{
}
public
CachePublicMetrics
(
Map
<
String
,
CacheManager
>
cacheManagers
,
Collection
<
CacheStatisticsProvider
<?>>
statisticsProviders
)
{
this
.
cacheManagers
=
cacheManagers
;
this
.
statisticsProviders
=
statisticsProviders
;
}
@Override
@Override
public
Collection
<
Metric
<?>>
metrics
()
{
public
Collection
<
Metric
<?>>
metrics
()
{
Collection
<
Metric
<?>>
metrics
=
new
HashSet
<
Metric
<?>>();
Collection
<
Metric
<?>>
metrics
=
new
HashSet
<
Metric
<?>>();
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/CachePublicMetricsTests.java
0 → 100644
View file @
035e27b1
/*
* 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
.
endpoint
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.cache.CacheStatisticsProvider
;
import
org.springframework.boot.actuate.cache.CaffeineCacheStatisticsProvider
;
import
org.springframework.boot.actuate.cache.ConcurrentMapCacheStatisticsProvider
;
import
org.springframework.boot.actuate.metrics.Metric
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.concurrent.ConcurrentMapCacheManager
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
entry
;
/**
* Tests for {@link CachePublicMetrics}
*
* @author Stephane Nicoll
*/
public
class
CachePublicMetricsTests
{
private
Map
<
String
,
CacheManager
>
cacheManagers
=
new
HashMap
<
String
,
CacheManager
>();
@Before
public
void
setup
()
{
this
.
cacheManagers
.
put
(
"cacheManager"
,
new
ConcurrentMapCacheManager
(
"foo"
,
"bar"
));
}
@Test
public
void
cacheMetricsWithMatchingProvider
()
{
CachePublicMetrics
cpm
=
new
CachePublicMetrics
(
this
.
cacheManagers
,
providers
(
new
ConcurrentMapCacheStatisticsProvider
()));
Map
<
String
,
Number
>
metrics
=
metrics
(
cpm
);
assertThat
(
metrics
).
containsOnly
(
entry
(
"cache.foo.size"
,
0L
),
entry
(
"cache.bar.size"
,
0L
));
}
@Test
public
void
cacheMetricsWithNoMatchingProvider
()
{
CachePublicMetrics
cpm
=
new
CachePublicMetrics
(
this
.
cacheManagers
,
providers
(
new
CaffeineCacheStatisticsProvider
()));
Map
<
String
,
Number
>
metrics
=
metrics
(
cpm
);
assertThat
(
metrics
).
isEmpty
();
}
@Test
public
void
cacheMetricsWithMultipleCacheManagers
()
{
this
.
cacheManagers
.
put
(
"anotherCacheManager"
,
new
ConcurrentMapCacheManager
(
"foo"
));
CachePublicMetrics
cpm
=
new
CachePublicMetrics
(
this
.
cacheManagers
,
providers
(
new
ConcurrentMapCacheStatisticsProvider
()));
Map
<
String
,
Number
>
metrics
=
metrics
(
cpm
);
assertThat
(
metrics
).
containsOnly
(
entry
(
"cache.cacheManager_foo.size"
,
0L
),
entry
(
"cache.bar.size"
,
0L
),
entry
(
"cache.anotherCacheManager_foo.size"
,
0L
));
}
private
Map
<
String
,
Number
>
metrics
(
CachePublicMetrics
cpm
)
{
Collection
<
Metric
<?>>
metrics
=
cpm
.
metrics
();
assertThat
(
metrics
).
isNotNull
();
Map
<
String
,
Number
>
result
=
new
HashMap
<
String
,
Number
>();
for
(
Metric
<?>
metric
:
metrics
)
{
result
.
put
(
metric
.
getName
(),
metric
.
getValue
());
}
return
result
;
}
private
Collection
<
CacheStatisticsProvider
<?>>
providers
(
CacheStatisticsProvider
<?>...
providers
)
{
return
Arrays
.
asList
(
providers
);
}
}
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