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
6c66ff78
Commit
6c66ff78
authored
Oct 28, 2014
by
Christian Dupuis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix health status aggregation bug
parent
cebfd44d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
13 deletions
+62
-13
HealthIndicatorAutoConfiguration.java
...tuate/autoconfigure/HealthIndicatorAutoConfiguration.java
+6
-6
HealthIndicatorAutoConfigurationProperties.java
...configure/HealthIndicatorAutoConfigurationProperties.java
+42
-0
OrderedHealthAggregator.java
...ramework/boot/actuate/health/OrderedHealthAggregator.java
+11
-3
HealthEndpointTests.java
...gframework/boot/actuate/endpoint/HealthEndpointTests.java
+2
-2
OrderedHealthAggregatorTests.java
...ork/boot/actuate/health/OrderedHealthAggregatorTests.java
+1
-2
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java
View file @
6c66ff78
...
...
@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.autoconfigure;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
javax.sql.DataSource
;
...
...
@@ -26,7 +25,6 @@ import javax.sql.DataSource;
import
org.apache.solr.client.solrj.SolrServer
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.actuate.health.ApplicationHealthIndicator
;
import
org.springframework.boot.actuate.health.CompositeHealthIndicator
;
import
org.springframework.boot.actuate.health.DataSourceHealthIndicator
;
...
...
@@ -54,6 +52,7 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import
org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration
;
import
org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration
;
import
org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
...
...
@@ -72,17 +71,18 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
@AutoConfigureAfter
({
DataSourceAutoConfiguration
.
class
,
MongoAutoConfiguration
.
class
,
MongoDataAutoConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
RabbitAutoConfiguration
.
class
,
SolrAutoConfiguration
.
class
})
@EnableConfigurationProperties
({
HealthIndicatorAutoConfigurationProperties
.
class
})
public
class
HealthIndicatorAutoConfiguration
{
@
Value
(
"${health.status.order:}"
)
private
List
<
String
>
statusOrder
=
null
;
@
Autowired
private
HealthIndicatorAutoConfigurationProperties
configurationProperties
=
new
HealthIndicatorAutoConfigurationProperties
()
;
@Bean
@ConditionalOnMissingBean
public
HealthAggregator
healthAggregator
()
{
OrderedHealthAggregator
healthAggregator
=
new
OrderedHealthAggregator
();
if
(
this
.
statusOrder
!=
null
)
{
healthAggregator
.
setStatusOrder
(
this
.
statusOrder
);
if
(
this
.
configurationProperties
.
getOrder
()
!=
null
)
{
healthAggregator
.
setStatusOrder
(
this
.
configurationProperties
.
getOrder
()
);
}
return
healthAggregator
;
}
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationProperties.java
0 → 100644
View file @
6c66ff78
/*
* Copyright 2012-2014 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
.
autoconfigure
;
import
java.util.List
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Configuration properties for some health properties
* @author Christian Dupuis
*/
@ConfigurationProperties
(
"health.status"
)
public
class
HealthIndicatorAutoConfigurationProperties
{
private
List
<
String
>
order
=
null
;
public
List
<
String
>
getOrder
()
{
return
this
.
order
;
}
public
void
setOrder
(
List
<
String
>
statusOrder
)
{
if
(
statusOrder
!=
null
&&
statusOrder
.
size
()
>
0
)
{
this
.
order
=
statusOrder
;
}
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/OrderedHealthAggregator.java
View file @
6c66ff78
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
actuate
.
health
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
...
...
@@ -67,13 +68,20 @@ public class OrderedHealthAggregator extends AbstractHealthAggregator {
@Override
protected
Status
aggregateStatus
(
List
<
Status
>
candidates
)
{
// Only sort those status instances that we know about
List
<
Status
>
filteredCandidates
=
new
ArrayList
<
Status
>();
for
(
Status
candidate
:
candidates
)
{
if
(
this
.
statusOrder
.
contains
(
candidate
.
getCode
()))
{
filteredCandidates
.
add
(
candidate
);
}
}
// If no status is given return UNKNOWN
if
(
c
andidates
.
size
()
==
0
)
{
if
(
filteredC
andidates
.
size
()
==
0
)
{
return
Status
.
UNKNOWN
;
}
// Sort given Status instances by configured order
Collections
.
sort
(
c
andidates
,
new
StatusComparator
(
this
.
statusOrder
));
return
c
andidates
.
get
(
0
);
Collections
.
sort
(
filteredC
andidates
,
new
StatusComparator
(
this
.
statusOrder
));
return
filteredC
andidates
.
get
(
0
);
}
/**
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java
View file @
6c66ff78
...
...
@@ -45,8 +45,8 @@ public class HealthEndpointTests extends AbstractEndpointTests<HealthEndpoint> {
@Test
public
void
invoke
()
throws
Exception
{
Status
result
=
new
Status
(
"FINE"
);
assertThat
(
getEndpointBean
().
invoke
().
getStatus
(),
equalTo
(
result
));
// As FINE isn't configured in the order we get UNKOWN
assertThat
(
getEndpointBean
().
invoke
().
getStatus
(),
equalTo
(
Status
.
UNKNOWN
));
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/OrderedHealthAggregatorTests.java
View file @
6c66ff78
...
...
@@ -69,8 +69,7 @@ public class OrderedHealthAggregatorTests {
healths
.
put
(
"h3"
,
new
Health
.
Builder
().
status
(
Status
.
UNKNOWN
).
build
());
healths
.
put
(
"h4"
,
new
Health
.
Builder
().
status
(
Status
.
OUT_OF_SERVICE
).
build
());
healths
.
put
(
"h5"
,
new
Health
.
Builder
().
status
(
new
Status
(
"CUSTOM"
)).
build
());
assertEquals
(
new
Status
(
"CUSTOM"
),
this
.
healthAggregator
.
aggregate
(
healths
)
.
getStatus
());
assertEquals
(
Status
.
DOWN
,
this
.
healthAggregator
.
aggregate
(
healths
).
getStatus
());
}
@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