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
87977886
Commit
87977886
authored
Apr 09, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gh-2399'
parents
1dcf18b1
03b109a2
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
466 additions
and
13 deletions
+466
-13
.gitignore
spring-boot-actuator/.gitignore
+1
-0
pom.xml
spring-boot-actuator/pom.xml
+19
-9
HealthIndicatorAutoConfiguration.java
...tuate/autoconfigure/HealthIndicatorAutoConfiguration.java
+32
-1
ElasticsearchHealthIndicator.java
...ork/boot/actuate/health/ElasticsearchHealthIndicator.java
+73
-0
ElasticsearchHealthIndicatorProperties.java
...ctuate/health/ElasticsearchHealthIndicatorProperties.java
+56
-0
spring.factories
...oot-actuator/src/main/resources/META-INF/spring.factories
+1
-1
HealthIndicatorAutoConfigurationTests.java
.../autoconfigure/HealthIndicatorAutoConfigurationTests.java
+36
-0
ElasticsearchHealthIndicatorTests.java
...oot/actuate/health/ElasticsearchHealthIndicatorTests.java
+238
-0
pom.xml
spring-boot-dependencies/pom.xml
+6
-0
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+4
-2
No files found.
spring-boot-actuator/.gitignore
0 → 100644
View file @
87977886
/data
spring-boot-actuator/pom.xml
View file @
87977886
...
@@ -96,6 +96,11 @@
...
@@ -96,6 +96,11 @@
<artifactId>
spring-data-solr
</artifactId>
<artifactId>
spring-data-solr
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.security
</groupId>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-web
</artifactId>
<artifactId>
spring-security-web
</artifactId>
...
@@ -168,19 +173,25 @@
...
@@ -168,19 +173,25 @@
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<!-- Test -->
<!-- Test -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot
</artifactId>
<type>
test-jar
</type>
<scope>
test
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
<artifactId>
logback-classic
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.
crashub
</groupId>
<groupId>
org.
apache.tomcat.embed
</groupId>
<artifactId>
crash.connectors.telnet
</artifactId>
<artifactId>
tomcat-embed-logging-juli
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.
springframework
</groupId>
<groupId>
org.
crashub
</groupId>
<artifactId>
spring-tes
t
</artifactId>
<artifactId>
crash.connectors.telne
t
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
...
@@ -189,14 +200,13 @@
...
@@ -189,14 +200,13 @@
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-boot
</artifactId>
<artifactId>
spring-test
</artifactId>
<type>
test-jar
</type>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.
apache.tomcat.embed
</groupId>
<groupId>
org.
springframework.data
</groupId>
<artifactId>
tomcat-embed-logging-juli
</artifactId>
<artifactId>
spring-data-elasticsearch
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
</dependencies>
</dependencies>
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java
View file @
87977886
...
@@ -23,6 +23,7 @@ import javax.jms.ConnectionFactory;
...
@@ -23,6 +23,7 @@ import javax.jms.ConnectionFactory;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
org.apache.solr.client.solrj.SolrServer
;
import
org.apache.solr.client.solrj.SolrServer
;
import
org.elasticsearch.client.Client
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -31,6 +32,8 @@ import org.springframework.boot.actuate.health.CompositeHealthIndicator;
...
@@ -31,6 +32,8 @@ import org.springframework.boot.actuate.health.CompositeHealthIndicator;
import
org.springframework.boot.actuate.health.DataSourceHealthIndicator
;
import
org.springframework.boot.actuate.health.DataSourceHealthIndicator
;
import
org.springframework.boot.actuate.health.DiskSpaceHealthIndicator
;
import
org.springframework.boot.actuate.health.DiskSpaceHealthIndicator
;
import
org.springframework.boot.actuate.health.DiskSpaceHealthIndicatorProperties
;
import
org.springframework.boot.actuate.health.DiskSpaceHealthIndicatorProperties
;
import
org.springframework.boot.actuate.health.ElasticsearchHealthIndicator
;
import
org.springframework.boot.actuate.health.ElasticsearchHealthIndicatorProperties
;
import
org.springframework.boot.actuate.health.HealthAggregator
;
import
org.springframework.boot.actuate.health.HealthAggregator
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.actuate.health.JmsHealthIndicator
;
import
org.springframework.boot.actuate.health.JmsHealthIndicator
;
...
@@ -47,6 +50,7 @@ import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
...
@@ -47,6 +50,7 @@ import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata
;
import
org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata
;
import
org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider
;
import
org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider
;
...
@@ -79,7 +83,8 @@ import org.springframework.mail.javamail.JavaMailSenderImpl;
...
@@ -79,7 +83,8 @@ import org.springframework.mail.javamail.JavaMailSenderImpl;
@AutoConfigureAfter
({
DataSourceAutoConfiguration
.
class
,
MongoAutoConfiguration
.
class
,
@AutoConfigureAfter
({
DataSourceAutoConfiguration
.
class
,
MongoAutoConfiguration
.
class
,
MongoDataAutoConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
MongoDataAutoConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
RabbitAutoConfiguration
.
class
,
SolrAutoConfiguration
.
class
,
RabbitAutoConfiguration
.
class
,
SolrAutoConfiguration
.
class
,
MailSenderAutoConfiguration
.
class
,
JmsAutoConfiguration
.
class
})
MailSenderAutoConfiguration
.
class
,
JmsAutoConfiguration
.
class
,
ElasticsearchAutoConfiguration
.
class
})
@EnableConfigurationProperties
({
HealthIndicatorAutoConfigurationProperties
.
class
})
@EnableConfigurationProperties
({
HealthIndicatorAutoConfigurationProperties
.
class
})
public
class
HealthIndicatorAutoConfiguration
{
public
class
HealthIndicatorAutoConfiguration
{
...
@@ -306,4 +311,30 @@ public class HealthIndicatorAutoConfiguration {
...
@@ -306,4 +311,30 @@ public class HealthIndicatorAutoConfiguration {
}
}
@Configuration
@ConditionalOnBean
(
Client
.
class
)
@ConditionalOnProperty
(
prefix
=
"management.health.elasticsearch"
,
name
=
"enabled"
,
matchIfMissing
=
true
)
@EnableConfigurationProperties
(
ElasticsearchHealthIndicatorProperties
.
class
)
public
static
class
ElasticsearchHealthIndicatorConfiguration
extends
CompositeHealthIndicatorConfiguration
<
ElasticsearchHealthIndicator
,
Client
>
{
@Autowired
private
Map
<
String
,
Client
>
clients
;
@Autowired
private
ElasticsearchHealthIndicatorProperties
properties
;
@Bean
@ConditionalOnMissingBean
(
name
=
"elasticsearchHealthIndicator"
)
public
HealthIndicator
elasticsearchHealthIndicator
()
{
return
createHealthIndicator
(
this
.
clients
);
}
@Override
protected
ElasticsearchHealthIndicator
createHealthIndicator
(
Client
client
)
{
return
new
ElasticsearchHealthIndicator
(
client
,
this
.
properties
);
}
}
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicator.java
0 → 100644
View file @
87977886
/*
* Copyright 2012-2015 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
.
health
;
import
java.util.List
;
import
org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse
;
import
org.elasticsearch.client.Client
;
import
org.elasticsearch.client.Requests
;
/**
* {@link HealthIndicator} for an Elasticsearch cluster.
*
* @author Binwei Yang
* @author Andy Wilkinson
* @since 1.3.0
*/
public
class
ElasticsearchHealthIndicator
extends
AbstractHealthIndicator
{
private
final
Client
client
;
private
final
ElasticsearchHealthIndicatorProperties
properties
;
public
ElasticsearchHealthIndicator
(
Client
client
,
ElasticsearchHealthIndicatorProperties
properties
)
{
this
.
client
=
client
;
this
.
properties
=
properties
;
}
@Override
protected
void
doHealthCheck
(
Health
.
Builder
builder
)
throws
Exception
{
List
<
String
>
indices
=
this
.
properties
.
getIndices
();
ClusterHealthResponse
response
=
this
.
client
.
admin
()
.
cluster
()
.
health
(
Requests
.
clusterHealthRequest
(
indices
.
isEmpty
()
?
null
:
indices
.
toArray
(
new
String
[
indices
.
size
()])))
.
actionGet
(
this
.
properties
.
getResponseTimeout
());
switch
(
response
.
getStatus
())
{
case
GREEN:
case
YELLOW:
builder
.
up
();
break
;
case
RED:
default
:
builder
.
down
();
break
;
}
builder
.
withDetail
(
"clusterName"
,
response
.
getClusterName
());
builder
.
withDetail
(
"numberOfNodes"
,
response
.
getNumberOfNodes
());
builder
.
withDetail
(
"numberOfDataNodes"
,
response
.
getNumberOfDataNodes
());
builder
.
withDetail
(
"activePrimaryShards"
,
response
.
getActivePrimaryShards
());
builder
.
withDetail
(
"activeShards"
,
response
.
getActiveShards
());
builder
.
withDetail
(
"relocatingShards"
,
response
.
getRelocatingShards
());
builder
.
withDetail
(
"initializingShards"
,
response
.
getInitializingShards
());
builder
.
withDetail
(
"unassignedShards"
,
response
.
getUnassignedShards
());
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorProperties.java
0 → 100644
View file @
87977886
/*
* Copyright 2012-2015 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
.
health
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* External configuration properties for {@link ElasticsearchHealthIndicator}
*
* @author Binwei Yang
* @author Andy Wilkinson
* @since 1.3.0
*/
@ConfigurationProperties
(
"management.health.elasticsearch"
)
public
class
ElasticsearchHealthIndicatorProperties
{
/**
* Comma-separated index names
*/
private
List
<
String
>
indices
=
new
ArrayList
<
String
>();
/**
* The time, in milliseconds, to wait for a response from the cluster
*/
private
long
responseTimeout
=
100L
;
public
List
<
String
>
getIndices
()
{
return
this
.
indices
;
}
public
long
getResponseTimeout
()
{
return
this
.
responseTimeout
;
}
public
void
setResponseTimeout
(
long
responseTimeout
)
{
this
.
responseTimeout
=
responseTimeout
;
}
}
spring-boot-actuator/src/main/resources/META-INF/spring.factories
View file @
87977886
...
@@ -12,4 +12,4 @@ org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration,\
...
@@ -12,4 +12,4 @@ org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.PublicMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.PublicMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.TraceRepositoryAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.TraceRepositoryAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.TraceWebFilterAutoConfiguration
org.springframework.boot.actuate.autoconfigure.TraceWebFilterAutoConfiguration
\ No newline at end of file
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java
View file @
87977886
...
@@ -26,6 +26,7 @@ import org.junit.Test;
...
@@ -26,6 +26,7 @@ import org.junit.Test;
import
org.springframework.boot.actuate.health.ApplicationHealthIndicator
;
import
org.springframework.boot.actuate.health.ApplicationHealthIndicator
;
import
org.springframework.boot.actuate.health.DataSourceHealthIndicator
;
import
org.springframework.boot.actuate.health.DataSourceHealthIndicator
;
import
org.springframework.boot.actuate.health.DiskSpaceHealthIndicator
;
import
org.springframework.boot.actuate.health.DiskSpaceHealthIndicator
;
import
org.springframework.boot.actuate.health.ElasticsearchHealthIndicator
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.actuate.health.JmsHealthIndicator
;
import
org.springframework.boot.actuate.health.JmsHealthIndicator
;
import
org.springframework.boot.actuate.health.MailHealthIndicator
;
import
org.springframework.boot.actuate.health.MailHealthIndicator
;
...
@@ -35,6 +36,7 @@ import org.springframework.boot.actuate.health.RedisHealthIndicator;
...
@@ -35,6 +36,7 @@ import org.springframework.boot.actuate.health.RedisHealthIndicator;
import
org.springframework.boot.actuate.health.SolrHealthIndicator
;
import
org.springframework.boot.actuate.health.SolrHealthIndicator
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration
;
import
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration
;
import
org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration
;
...
@@ -59,6 +61,7 @@ import static org.junit.Assert.assertEquals;
...
@@ -59,6 +61,7 @@ import static org.junit.Assert.assertEquals;
*
*
* @author Christian Dupuis
* @author Christian Dupuis
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Andy Wilkinson
*/
*/
public
class
HealthIndicatorAutoConfigurationTests
{
public
class
HealthIndicatorAutoConfigurationTests
{
...
@@ -362,6 +365,39 @@ public class HealthIndicatorAutoConfigurationTests {
...
@@ -362,6 +365,39 @@ public class HealthIndicatorAutoConfigurationTests {
.
getClass
());
.
getClass
());
}
}
@Test
public
void
elasticSearchHealthIndicator
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"management.health.diskspace.enabled:false"
);
this
.
context
.
register
(
ElasticsearchAutoConfiguration
.
class
,
ManagementServerProperties
.
class
,
HealthIndicatorAutoConfiguration
.
class
);
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assertEquals
(
1
,
beans
.
size
());
assertEquals
(
ElasticsearchHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
()
.
getClass
());
}
@Test
public
void
notElasticSearchHealthIndicator
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"management.health.elasticsearch.enabled:false"
,
"management.health.diskspace.enabled:false"
);
this
.
context
.
register
(
ElasticsearchAutoConfiguration
.
class
,
ManagementServerProperties
.
class
,
HealthIndicatorAutoConfiguration
.
class
);
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assertEquals
(
1
,
beans
.
size
());
assertEquals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
()
.
getClass
());
}
@Configuration
@Configuration
@EnableConfigurationProperties
@EnableConfigurationProperties
protected
static
class
DataSourceConfig
{
protected
static
class
DataSourceConfig
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java
0 → 100644
View file @
87977886
/*
* Copyright 2012-2015 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
.
health
;
import
java.util.Arrays
;
import
java.util.Map
;
import
org.elasticsearch.ElasticsearchException
;
import
org.elasticsearch.ElasticsearchTimeoutException
;
import
org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
;
import
org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse
;
import
org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus
;
import
org.elasticsearch.action.support.PlainActionFuture
;
import
org.elasticsearch.client.AdminClient
;
import
org.elasticsearch.client.Client
;
import
org.elasticsearch.client.ClusterAdminClient
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
Matchers
.
arrayContaining
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
any
;
/**
* Test for {@link ElasticsearchHealthIndicator}.
*
* @author Andy Wilkinson
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
ElasticsearchHealthIndicatorTests
{
@Mock
private
Client
client
;
@Mock
private
AdminClient
admin
;
@Mock
private
ClusterAdminClient
cluster
;
private
ElasticsearchHealthIndicator
indicator
;
private
ElasticsearchHealthIndicatorProperties
properties
=
new
ElasticsearchHealthIndicatorProperties
();
@Before
public
void
setUp
()
throws
Exception
{
given
(
this
.
client
.
admin
()).
willReturn
(
this
.
admin
);
given
(
this
.
admin
.
cluster
()).
willReturn
(
this
.
cluster
);
this
.
indicator
=
new
ElasticsearchHealthIndicator
(
this
.
client
,
this
.
properties
);
}
@Test
public
void
defaultConfigurationQueriesAllIndicesWith100msTimeout
()
{
TestActionFuture
responseFuture
=
new
TestActionFuture
();
responseFuture
.
onResponse
(
new
StubClusterHealthResponse
());
ArgumentCaptor
<
ClusterHealthRequest
>
requestCaptor
=
ArgumentCaptor
.
forClass
(
ClusterHealthRequest
.
class
);
given
(
this
.
cluster
.
health
(
requestCaptor
.
capture
())).
willReturn
(
responseFuture
);
Health
health
=
this
.
indicator
.
health
();
assertThat
(
responseFuture
.
getTimeout
,
is
(
100L
));
assertThat
(
requestCaptor
.
getValue
().
indices
(),
is
(
nullValue
()));
assertThat
(
health
.
getStatus
(),
is
(
Status
.
UP
));
}
@Test
public
void
certainIndices
()
{
PlainActionFuture
<
ClusterHealthResponse
>
responseFuture
=
new
PlainActionFuture
<
ClusterHealthResponse
>();
responseFuture
.
onResponse
(
new
StubClusterHealthResponse
());
ArgumentCaptor
<
ClusterHealthRequest
>
requestCaptor
=
ArgumentCaptor
.
forClass
(
ClusterHealthRequest
.
class
);
given
(
this
.
cluster
.
health
(
requestCaptor
.
capture
())).
willReturn
(
responseFuture
);
this
.
properties
.
getIndices
()
.
addAll
(
Arrays
.
asList
(
"test-index-1"
,
"test-index-2"
));
Health
health
=
this
.
indicator
.
health
();
assertThat
(
requestCaptor
.
getValue
().
indices
(),
is
(
arrayContaining
(
"test-index-1"
,
"test-index-2"
)));
assertThat
(
health
.
getStatus
(),
is
(
Status
.
UP
));
}
@Test
public
void
customTimeout
()
{
TestActionFuture
responseFuture
=
new
TestActionFuture
();
responseFuture
.
onResponse
(
new
StubClusterHealthResponse
());
ArgumentCaptor
<
ClusterHealthRequest
>
requestCaptor
=
ArgumentCaptor
.
forClass
(
ClusterHealthRequest
.
class
);
given
(
this
.
cluster
.
health
(
requestCaptor
.
capture
())).
willReturn
(
responseFuture
);
this
.
properties
.
setResponseTimeout
(
1000L
);
this
.
indicator
.
health
();
assertThat
(
responseFuture
.
getTimeout
,
is
(
1000L
));
}
@Test
public
void
healthDetails
()
{
PlainActionFuture
<
ClusterHealthResponse
>
responseFuture
=
new
PlainActionFuture
<
ClusterHealthResponse
>();
responseFuture
.
onResponse
(
new
StubClusterHealthResponse
());
given
(
this
.
cluster
.
health
(
any
(
ClusterHealthRequest
.
class
))).
willReturn
(
responseFuture
);
Health
health
=
this
.
indicator
.
health
();
assertThat
(
health
.
getStatus
(),
is
(
Status
.
UP
));
Map
<
String
,
Object
>
details
=
health
.
getDetails
();
assertDetail
(
details
,
"clusterName"
,
"test-cluster"
);
assertDetail
(
details
,
"activeShards"
,
1
);
assertDetail
(
details
,
"relocatingShards"
,
2
);
assertDetail
(
details
,
"activePrimaryShards"
,
3
);
assertDetail
(
details
,
"initializingShards"
,
4
);
assertDetail
(
details
,
"unassignedShards"
,
5
);
assertDetail
(
details
,
"numberOfNodes"
,
6
);
assertDetail
(
details
,
"numberOfDataNodes"
,
7
);
}
@Test
public
void
redResponseMapsToDown
()
{
PlainActionFuture
<
ClusterHealthResponse
>
responseFuture
=
new
PlainActionFuture
<
ClusterHealthResponse
>();
responseFuture
.
onResponse
(
new
StubClusterHealthResponse
(
ClusterHealthStatus
.
RED
));
given
(
this
.
cluster
.
health
(
any
(
ClusterHealthRequest
.
class
))).
willReturn
(
responseFuture
);
assertThat
(
this
.
indicator
.
health
().
getStatus
(),
is
(
Status
.
DOWN
));
}
@Test
public
void
yellowResponseMapsToUp
()
{
PlainActionFuture
<
ClusterHealthResponse
>
responseFuture
=
new
PlainActionFuture
<
ClusterHealthResponse
>();
responseFuture
.
onResponse
(
new
StubClusterHealthResponse
(
ClusterHealthStatus
.
YELLOW
));
given
(
this
.
cluster
.
health
(
any
(
ClusterHealthRequest
.
class
))).
willReturn
(
responseFuture
);
assertThat
(
this
.
indicator
.
health
().
getStatus
(),
is
(
Status
.
UP
));
}
@Test
public
void
responseTimeout
()
{
PlainActionFuture
<
ClusterHealthResponse
>
responseFuture
=
new
PlainActionFuture
<
ClusterHealthResponse
>();
given
(
this
.
cluster
.
health
(
any
(
ClusterHealthRequest
.
class
))).
willReturn
(
responseFuture
);
Health
health
=
this
.
indicator
.
health
();
assertThat
(
health
.
getStatus
(),
is
(
Status
.
DOWN
));
assertThat
((
String
)
health
.
getDetails
().
get
(
"error"
),
containsString
(
ElasticsearchTimeoutException
.
class
.
getName
()));
}
@SuppressWarnings
(
"unchecked"
)
private
<
T
>
void
assertDetail
(
Map
<
String
,
Object
>
details
,
String
detail
,
T
value
)
{
assertThat
((
T
)
details
.
get
(
detail
),
is
(
equalTo
(
value
)));
}
private
static
class
StubClusterHealthResponse
extends
ClusterHealthResponse
{
private
final
ClusterHealthStatus
status
;
private
StubClusterHealthResponse
()
{
this
(
ClusterHealthStatus
.
GREEN
);
}
private
StubClusterHealthResponse
(
ClusterHealthStatus
status
)
{
super
(
"test-cluster"
,
null
);
this
.
status
=
status
;
}
@Override
public
int
getActiveShards
()
{
return
1
;
}
@Override
public
int
getRelocatingShards
()
{
return
2
;
}
@Override
public
int
getActivePrimaryShards
()
{
return
3
;
}
@Override
public
int
getInitializingShards
()
{
return
4
;
}
@Override
public
int
getUnassignedShards
()
{
return
5
;
}
@Override
public
int
getNumberOfNodes
()
{
return
6
;
}
@Override
public
int
getNumberOfDataNodes
()
{
return
7
;
}
@Override
public
ClusterHealthStatus
getStatus
()
{
return
this
.
status
;
}
}
private
static
class
TestActionFuture
extends
PlainActionFuture
<
ClusterHealthResponse
>
{
private
long
getTimeout
=
-
1L
;
@Override
public
ClusterHealthResponse
actionGet
(
long
timeoutMillis
)
throws
ElasticsearchException
{
this
.
getTimeout
=
timeoutMillis
;
return
super
.
actionGet
(
timeoutMillis
);
}
}
}
spring-boot-dependencies/pom.xml
View file @
87977886
...
@@ -63,6 +63,7 @@
...
@@ -63,6 +63,7 @@
<ehcache.version>
2.9.1
</ehcache.version>
<ehcache.version>
2.9.1
</ehcache.version>
<flyway.version>
3.2
</flyway.version>
<flyway.version>
3.2
</flyway.version>
<freemarker.version>
2.3.22
</freemarker.version>
<freemarker.version>
2.3.22
</freemarker.version>
<elasticsearch.version>
1.4.4
</elasticsearch.version>
<gemfire.version>
7.0.2
</gemfire.version>
<gemfire.version>
7.0.2
</gemfire.version>
<glassfish-el.version>
3.0.0
</glassfish-el.version>
<glassfish-el.version>
3.0.0
</glassfish-el.version>
<gradle.version>
1.12
</gradle.version>
<gradle.version>
1.12
</gradle.version>
...
@@ -1084,6 +1085,11 @@
...
@@ -1084,6 +1085,11 @@
<artifactId>
websocket-server
</artifactId>
<artifactId>
websocket-server
</artifactId>
<version>
${jetty.version}
</version>
<version>
${jetty.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
<version>
${elasticsearch.version}
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.flywaydb
</groupId>
<groupId>
org.flywaydb
</groupId>
<artifactId>
flyway-core
</artifactId>
<artifactId>
flyway-core
</artifactId>
...
...
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
87977886
...
@@ -542,13 +542,15 @@ content into your application; rather pick only the properties that you need.
...
@@ -542,13 +542,15 @@ content into your application; rather pick only the properties that you need.
# HEALTH INDICATORS (previously health.*)
# HEALTH INDICATORS (previously health.*)
management.health.db.enabled=true
management.health.db.enabled=true
management.health.elasticsearch.enabled=true
management.health.elasticsearch.response-timeout=100 # the time, in milliseconds, to wait for a response from the cluster
management.health.diskspace.enabled=true
management.health.diskspace.enabled=true
management.health.diskspace.path=.
management.health.diskspace.threshold=10485760
management.health.mongo.enabled=true
management.health.mongo.enabled=true
management.health.rabbit.enabled=true
management.health.rabbit.enabled=true
management.health.redis.enabled=true
management.health.redis.enabled=true
management.health.solr.enabled=true
management.health.solr.enabled=true
management.health.diskspace.path=.
management.health.diskspace.threshold=10485760
management.health.status.order=DOWN, OUT_OF_SERVICE, UNKNOWN, UP
management.health.status.order=DOWN, OUT_OF_SERVICE, UNKNOWN, UP
# MVC ONLY ENDPOINTS
# MVC ONLY ENDPOINTS
...
...
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