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
51a26a4d
Commit
51a26a4d
authored
Jul 23, 2020
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
0a756b53
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
31 deletions
+31
-31
RedisHealthIndicator.java
...ingframework/boot/actuate/redis/RedisHealthIndicator.java
+15
-15
RedisReactiveHealthIndicator.java
...work/boot/actuate/redis/RedisReactiveHealthIndicator.java
+16
-16
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java
View file @
51a26a4d
...
@@ -16,8 +16,6 @@
...
@@ -16,8 +16,6 @@
package
org
.
springframework
.
boot
.
actuate
.
redis
;
package
org
.
springframework
.
boot
.
actuate
.
redis
;
import
java.util.Properties
;
import
org.springframework.boot.actuate.health.AbstractHealthIndicator
;
import
org.springframework.boot.actuate.health.AbstractHealthIndicator
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
...
@@ -38,9 +36,7 @@ import org.springframework.util.Assert;
...
@@ -38,9 +36,7 @@ import org.springframework.util.Assert;
*/
*/
public
class
RedisHealthIndicator
extends
AbstractHealthIndicator
{
public
class
RedisHealthIndicator
extends
AbstractHealthIndicator
{
static
final
String
VERSION
=
"version"
;
private
static
final
String
REDIS_VERSION_PROPERTY
=
"redis_version"
;
static
final
String
REDIS_VERSION
=
"redis_version"
;
private
final
RedisConnectionFactory
redisConnectionFactory
;
private
final
RedisConnectionFactory
redisConnectionFactory
;
...
@@ -54,6 +50,14 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
...
@@ -54,6 +50,14 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
protected
void
doHealthCheck
(
Health
.
Builder
builder
)
throws
Exception
{
protected
void
doHealthCheck
(
Health
.
Builder
builder
)
throws
Exception
{
RedisConnection
connection
=
RedisConnectionUtils
.
getConnection
(
this
.
redisConnectionFactory
);
RedisConnection
connection
=
RedisConnectionUtils
.
getConnection
(
this
.
redisConnectionFactory
);
try
{
try
{
doHealthCheck
(
builder
,
connection
);
}
finally
{
RedisConnectionUtils
.
releaseConnection
(
connection
,
this
.
redisConnectionFactory
,
false
);
}
}
private
void
doHealthCheck
(
Health
.
Builder
builder
,
RedisConnection
connection
)
{
if
(
connection
instanceof
RedisClusterConnection
)
{
if
(
connection
instanceof
RedisClusterConnection
)
{
ClusterInfo
clusterInfo
=
((
RedisClusterConnection
)
connection
).
clusterGetClusterInfo
();
ClusterInfo
clusterInfo
=
((
RedisClusterConnection
)
connection
).
clusterGetClusterInfo
();
builder
.
up
().
withDetail
(
"cluster_size"
,
clusterInfo
.
getClusterSize
())
builder
.
up
().
withDetail
(
"cluster_size"
,
clusterInfo
.
getClusterSize
())
...
@@ -61,12 +65,8 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
...
@@ -61,12 +65,8 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
.
withDetail
(
"slots_fail"
,
clusterInfo
.
getSlotsFail
());
.
withDetail
(
"slots_fail"
,
clusterInfo
.
getSlotsFail
());
}
}
else
{
else
{
Properties
info
=
connection
.
info
();
String
version
=
connection
.
info
().
getProperty
(
REDIS_VERSION_PROPERTY
);
builder
.
up
().
withDetail
(
VERSION
,
info
.
getProperty
(
REDIS_VERSION
));
builder
.
up
().
withDetail
(
"version"
,
version
);
}
}
finally
{
RedisConnectionUtils
.
releaseConnection
(
connection
,
this
.
redisConnectionFactory
,
false
);
}
}
}
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java
View file @
51a26a4d
...
@@ -39,6 +39,8 @@ import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
...
@@ -39,6 +39,8 @@ import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
*/
*/
public
class
RedisReactiveHealthIndicator
extends
AbstractReactiveHealthIndicator
{
public
class
RedisReactiveHealthIndicator
extends
AbstractReactiveHealthIndicator
{
private
static
final
String
REDIS_VERSION_PROPERTY
=
"redis_version"
;
private
final
ReactiveRedisConnectionFactory
connectionFactory
;
private
final
ReactiveRedisConnectionFactory
connectionFactory
;
public
RedisReactiveHealthIndicator
(
ReactiveRedisConnectionFactory
connectionFactory
)
{
public
RedisReactiveHealthIndicator
(
ReactiveRedisConnectionFactory
connectionFactory
)
{
...
@@ -52,8 +54,8 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
...
@@ -52,8 +54,8 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
}
}
private
Mono
<
Health
>
doHealthCheck
(
Health
.
Builder
builder
,
ReactiveRedisConnection
connection
)
{
private
Mono
<
Health
>
doHealthCheck
(
Health
.
Builder
builder
,
ReactiveRedisConnection
connection
)
{
return
connection
.
serverCommands
().
info
()
boolean
isClusterConnection
=
connection
instanceof
ReactiveRedisClusterConnection
;
.
map
((
info
)
->
up
(
builder
,
info
,
(
connection
instanceof
ReactiveRedisClusterConnection
)
))
return
connection
.
serverCommands
().
info
().
map
((
info
)
->
up
(
builder
,
info
,
isClusterConnection
))
.
onErrorResume
((
ex
)
->
Mono
.
just
(
down
(
builder
,
ex
)))
.
onErrorResume
((
ex
)
->
Mono
.
just
(
down
(
builder
,
ex
)))
.
flatMap
((
health
)
->
connection
.
closeLater
().
thenReturn
(
health
));
.
flatMap
((
health
)
->
connection
.
closeLater
().
thenReturn
(
health
));
}
}
...
@@ -64,24 +66,22 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
...
@@ -64,24 +66,22 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
}
}
private
Health
up
(
Health
.
Builder
builder
,
Properties
info
,
boolean
isClusterConnection
)
{
private
Health
up
(
Health
.
Builder
builder
,
Properties
info
,
boolean
isClusterConnection
)
{
if
(
isClusterConnection
)
{
String
version
=
isClusterConnection
?
getClusterVersionProperty
(
info
)
return
builder
.
up
().
withDetail
(
RedisHealthIndicator
.
VERSION
,
getClusterVersionProperty
(
info
)).
build
();
:
info
.
getProperty
(
REDIS_VERSION_PROPERTY
);
}
return
builder
.
up
().
withDetail
(
"version"
,
version
).
build
();
else
{
return
builder
.
up
()
.
withDetail
(
RedisHealthIndicator
.
VERSION
,
info
.
getProperty
(
RedisHealthIndicator
.
REDIS_VERSION
))
.
build
();
}
}
private
Object
getClusterVersionProperty
(
Properties
info
)
{
return
info
.
keySet
().
stream
().
map
(
String
.
class
::
cast
)
.
filter
((
key
)
->
key
.
endsWith
(
RedisHealthIndicator
.
REDIS_VERSION
)).
findFirst
().
map
(
info:
:
get
)
.
orElse
(
""
);
}
}
private
Health
down
(
Health
.
Builder
builder
,
Throwable
cause
)
{
private
Health
down
(
Health
.
Builder
builder
,
Throwable
cause
)
{
return
builder
.
down
(
cause
).
build
();
return
builder
.
down
(
cause
).
build
();
}
}
private
String
getClusterVersionProperty
(
Properties
info
)
{
for
(
String
propertyName
:
info
.
stringPropertyNames
())
{
if
(
propertyName
.
endsWith
(
REDIS_VERSION_PROPERTY
))
{
return
info
.
getProperty
(
propertyName
);
}
}
return
""
;
}
}
}
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