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
cdbdc1cb
Commit
cdbdc1cb
authored
Nov 26, 2017
by
Eddú Meléndez
Committed by
Stephane Nicoll
Dec 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add InfluxDb health indicator
See gh-11159
parent
b7c2bd9c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
259 additions
and
0 deletions
+259
-0
pom.xml
...g-boot-project/spring-boot-actuator-autoconfigure/pom.xml
+5
-0
InfluxDbHealthIndicatorAutoConfiguration.java
...gure/influx/InfluxDbHealthIndicatorAutoConfiguration.java
+64
-0
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+1
-0
InfluxDbHealthIndicatorAutoConfigurationTests.java
...influx/InfluxDbHealthIndicatorAutoConfigurationTests.java
+73
-0
pom.xml
spring-boot-project/spring-boot-actuator/pom.xml
+5
-0
InfluxDbHealthIndicator.java
...framework/boot/actuate/infux/InfluxDbHealthIndicator.java
+47
-0
InfluxDbHealthIndicatorTests.java
...ork/boot/actuate/influx/InfluxDbHealthIndicatorTests.java
+64
-0
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/pom.xml
View file @
cdbdc1cb
...
...
@@ -213,6 +213,11 @@
<artifactId>
hibernate-validator
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.influxdb
</groupId>
<artifactId>
influxdb-java
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.jolokia
</groupId>
<artifactId>
jolokia-core
</artifactId>
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/influx/InfluxDbHealthIndicatorAutoConfiguration.java
0 → 100644
View file @
cdbdc1cb
/*
* 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
.
autoconfigure
.
influx
;
import
java.util.Map
;
import
org.influxdb.InfluxDB
;
import
org.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator
;
import
org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.actuate.infux.InfluxDbHealthIndicator
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.influx.InfluxDbAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link InfluxDbHealthIndicator}.
*
* @author Eddú Meléndez
* @since 2.0.0
*/
@Configuration
@ConditionalOnClass
(
InfluxDB
.
class
)
@ConditionalOnBean
(
InfluxDB
.
class
)
@ConditionalOnEnabledHealthIndicator
(
"influxdb"
)
@AutoConfigureBefore
(
HealthIndicatorAutoConfiguration
.
class
)
@AutoConfigureAfter
(
InfluxDbAutoConfiguration
.
class
)
public
class
InfluxDbHealthIndicatorAutoConfiguration
extends
CompositeHealthIndicatorConfiguration
<
InfluxDbHealthIndicator
,
InfluxDB
>
{
private
final
Map
<
String
,
InfluxDB
>
influxDbs
;
public
InfluxDbHealthIndicatorAutoConfiguration
(
Map
<
String
,
InfluxDB
>
influxDbs
)
{
this
.
influxDbs
=
influxDbs
;
}
@Bean
@ConditionalOnMissingBean
(
name
=
"influxdbHealthIndicator"
)
public
HealthIndicator
influxdbHealthIndicator
()
{
return
createHealthIndicator
(
this
.
influxDbs
);
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
cdbdc1cb
...
...
@@ -19,6 +19,7 @@ org.springframework.boot.actuate.autoconfigure.env.EnvironmentEndpointAutoConfig
org.springframework.boot.actuate.autoconfigure.flyway.FlywayEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.influx.InfluxDbHealthIndicatorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.info.InfoContributorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration,\
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/influx/InfluxDbHealthIndicatorAutoConfigurationTests.java
0 → 100644
View file @
cdbdc1cb
/*
* 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
.
autoconfigure
.
influx
;
import
org.influxdb.InfluxDB
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration
;
import
org.springframework.boot.actuate.health.ApplicationHealthIndicator
;
import
org.springframework.boot.actuate.infux.InfluxDbHealthIndicator
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link InfluxDbHealthIndicatorAutoConfiguration}.
*
* @author Eddú Meléndez
*/
public
class
InfluxDbHealthIndicatorAutonConfigurationTests
{
private
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
InfluxDbConfiguration
.
class
,
InfluxDbHealthIndicatorAutoConfiguration
.
class
,
HealthIndicatorAutoConfiguration
.
class
));
@Test
public
void
runShouldCreateIndicator
()
throws
Exception
{
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
)
.
hasSingleBean
(
InfluxDbHealthIndicator
.
class
)
.
doesNotHaveBean
(
ApplicationHealthIndicator
.
class
));
}
@Test
public
void
runWhenDisabledShouldNotCreateIndicator
()
throws
Exception
{
this
.
contextRunner
.
withPropertyValues
(
"management.health.influxdb.enabled:false"
).
run
(
(
context
)
->
assertThat
(
context
)
.
doesNotHaveBean
(
InfluxDbHealthIndicator
.
class
)
.
hasSingleBean
(
ApplicationHealthIndicator
.
class
));
}
@Configuration
@AutoConfigureBefore
(
InfluxDbHealthIndicatorAutoConfiguration
.
class
)
protected
static
class
InfluxDbConfiguration
{
@Bean
public
InfluxDB
influxdb
()
{
return
mock
(
InfluxDB
.
class
);
}
}
}
spring-boot-project/spring-boot-actuator/pom.xml
View file @
cdbdc1cb
...
...
@@ -101,6 +101,11 @@
<artifactId>
infinispan-spring4-embedded
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.influxdb
</groupId>
<artifactId>
influxdb-java
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.liquibase
</groupId>
<artifactId>
liquibase-core
</artifactId>
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/infux/InfluxDbHealthIndicator.java
0 → 100644
View file @
cdbdc1cb
/*
* 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
.
infux
;
import
org.influxdb.InfluxDB
;
import
org.springframework.boot.actuate.health.AbstractHealthIndicator
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.util.Assert
;
/**
* {@link HealthIndicator} for InfluxDb.
*
* @author Eddú Meléndez
* @since 2.0.0
*/
public
class
InfluxDbHealthIndicator
extends
AbstractHealthIndicator
{
private
final
InfluxDB
influxDb
;
public
InfluxDbHealthIndicator
(
InfluxDB
influxDb
)
{
Assert
.
notNull
(
influxDb
,
"InfluxDB must not be null"
);
this
.
influxDb
=
influxDb
;
}
@Override
protected
void
doHealthCheck
(
Health
.
Builder
builder
)
throws
Exception
{
String
version
=
this
.
influxDb
.
version
();
builder
.
up
().
withDetail
(
"version"
,
version
);
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/influx/InfluxDbHealthIndicatorTests.java
0 → 100644
View file @
cdbdc1cb
/*
* 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
.
influx
;
import
java.io.IOException
;
import
org.influxdb.InfluxDB
;
import
org.influxdb.InfluxDBException
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.Status
;
import
org.springframework.boot.actuate.infux.InfluxDbHealthIndicator
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
* Tests for {@link InfluxDbHealthIndicator}
*
* @author Eddú Meléndez
*/
public
class
InfluxDbHealthIndicatorTests
{
@Test
public
void
influxdbIsUp
()
{
InfluxDB
influxDB
=
mock
(
InfluxDB
.
class
);
given
(
influxDB
.
version
()).
willReturn
(
"0.9"
);
InfluxDbHealthIndicator
healthIndicator
=
new
InfluxDbHealthIndicator
(
influxDB
);
Health
health
=
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
get
(
"version"
)).
isEqualTo
(
"0.9"
);
verify
(
influxDB
).
version
();
}
@Test
public
void
influxdbIsDown
()
{
InfluxDB
influxDB
=
mock
(
InfluxDB
.
class
);
given
(
influxDB
.
version
()).
willThrow
(
new
InfluxDBException
(
new
IOException
(
"Connection failed"
)));
InfluxDbHealthIndicator
healthIndicator
=
new
InfluxDbHealthIndicator
(
influxDB
);
Health
health
=
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertThat
((
String
)
health
.
getDetails
().
get
(
"error"
))
.
contains
(
"Connection failed"
);
verify
(
influxDB
).
version
();
}
}
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