Skip to content

Commit b09d5d2

Browse files
bmscompsnicoll
authored andcommitted
Improve details of neo4h health indicator
This commit changes the neo4j health indicator to provide the version and edition of the neo4j database. See gh-20356
1 parent 89e5c28 commit b09d5d2

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/neo4j/Neo4jHealthIndicator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public class Neo4jHealthIndicator extends AbstractHealthIndicator {
4040
/**
4141
* The Cypher statement used to verify Neo4j is up.
4242
*/
43-
static final String CYPHER = "match (n) return count(n) as nodes";
43+
static final String CYPHER = "CALL dbms.components() YIELD versions, edition"
44+
+ " UNWIND versions as version return version, edition";
4445

4546
private final SessionFactory sessionFactory;
4647

@@ -69,7 +70,7 @@ protected void doHealthCheck(Health.Builder builder) throws Exception {
6970
*/
7071
protected void extractResult(Session session, Health.Builder builder) throws Exception {
7172
Result result = session.query(CYPHER, Collections.emptyMap());
72-
builder.up().withDetail("nodes", result.queryResults().iterator().next().get("nodes"));
73+
builder.up().withDetails(result.queryResults().iterator().next());
7374
}
7475

7576
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/neo4j/Neo4jHealthIndicatorTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,21 @@ void before() {
6161
void neo4jUp() {
6262
Result result = mock(Result.class);
6363
given(this.session.query(Neo4jHealthIndicator.CYPHER, Collections.emptyMap())).willReturn(result);
64-
int nodeCount = 500;
6564
Map<String, Object> expectedCypherDetails = new HashMap<>();
66-
expectedCypherDetails.put("nodes", nodeCount);
65+
String edition = "community";
66+
String version = "4.0.0";
67+
expectedCypherDetails.put("edition", edition);
68+
expectedCypherDetails.put("version", version);
6769
List<Map<String, Object>> queryResults = new ArrayList<>();
6870
queryResults.add(expectedCypherDetails);
6971
given(result.queryResults()).willReturn(queryResults);
7072
Health health = this.neo4jHealthIndicator.health();
7173
assertThat(health.getStatus()).isEqualTo(Status.UP);
7274
Map<String, Object> details = health.getDetails();
73-
int nodeCountFromDetails = (int) details.get("nodes");
74-
assertThat(nodeCountFromDetails).isEqualTo(nodeCount);
75+
String editionFromDetails = details.get("edition").toString();
76+
String versionFromDetails = details.get("version").toString();
77+
assertThat(editionFromDetails).isEqualTo(edition);
78+
assertThat(versionFromDetails).isEqualTo(version);
7579
}
7680

7781
@Test

0 commit comments

Comments
 (0)