Polish "Use server version from database in Neo4j health details"
See gh-27294
This commit is contained in:
parent
f7fd0ac527
commit
9f9c89a357
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2012-2021 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
|
||||
*
|
||||
* https://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.neo4j;
|
||||
|
||||
import org.neo4j.driver.Record;
|
||||
import org.neo4j.driver.summary.ResultSummary;
|
||||
|
||||
/**
|
||||
* Health details for a Neo4j server.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class Neo4jHealthDetails {
|
||||
|
||||
private final Record record;
|
||||
|
||||
private final ResultSummary summary;
|
||||
|
||||
Neo4jHealthDetails(Record record, ResultSummary summary) {
|
||||
this.record = record;
|
||||
this.summary = summary;
|
||||
}
|
||||
|
||||
String getVersion() {
|
||||
return this.record.get("version").asString();
|
||||
}
|
||||
|
||||
String getEdition() {
|
||||
return this.record.get("edition").asString();
|
||||
}
|
||||
|
||||
ResultSummary getSummary() {
|
||||
return this.summary;
|
||||
}
|
||||
|
||||
}
|
|
@ -33,14 +33,14 @@ class Neo4jHealthDetailsHandler {
|
|||
/**
|
||||
* Add health details for the specified {@link ResultSummary} and {@code edition}.
|
||||
* @param builder the {@link Builder} to use
|
||||
* @param version the version of the server
|
||||
* @param edition the edition of the server
|
||||
* @param resultSummary server information
|
||||
* @param healthDetails the health details of the server
|
||||
*/
|
||||
void addHealthDetails(Builder builder, String version, String edition, ResultSummary resultSummary) {
|
||||
ServerInfo serverInfo = resultSummary.server();
|
||||
builder.up().withDetail("server", version + "@" + serverInfo.address()).withDetail("edition", edition);
|
||||
DatabaseInfo databaseInfo = resultSummary.database();
|
||||
void addHealthDetails(Builder builder, Neo4jHealthDetails healthDetails) {
|
||||
ResultSummary summary = healthDetails.getSummary();
|
||||
ServerInfo serverInfo = summary.server();
|
||||
builder.up().withDetail("server", healthDetails.getVersion() + "@" + serverInfo.address()).withDetail("edition",
|
||||
healthDetails.getEdition());
|
||||
DatabaseInfo databaseInfo = summary.database();
|
||||
if (StringUtils.hasText(databaseInfo.name())) {
|
||||
builder.withDetail("database", databaseInfo.name());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
|
@ -93,10 +93,8 @@ public class Neo4jHealthIndicator extends AbstractHealthIndicator {
|
|||
try (Session session = this.driver.session(DEFAULT_SESSION_CONFIG)) {
|
||||
Result result = session.run(CYPHER);
|
||||
Record record = result.single();
|
||||
String edition = record.get("edition").asString();
|
||||
String version = record.get("version").asString();
|
||||
ResultSummary resultSummary = result.consume();
|
||||
this.healthDetailsHandler.addHealthDetails(builder, version, edition, resultSummary);
|
||||
this.healthDetailsHandler.addHealthDetails(builder, new Neo4jHealthDetails(record, resultSummary));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
|
@ -22,10 +22,7 @@ import org.neo4j.driver.Driver;
|
|||
import org.neo4j.driver.exceptions.SessionExpiredException;
|
||||
import org.neo4j.driver.reactive.RxResult;
|
||||
import org.neo4j.driver.reactive.RxSession;
|
||||
import org.neo4j.driver.summary.ResultSummary;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuples;
|
||||
import reactor.util.retry.Retry;
|
||||
|
||||
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
|
||||
|
@ -58,22 +55,19 @@ public final class Neo4jReactiveHealthIndicator extends AbstractReactiveHealthIn
|
|||
return runHealthCheckQuery()
|
||||
.doOnError(SessionExpiredException.class,
|
||||
(e) -> logger.warn(Neo4jHealthIndicator.MESSAGE_SESSION_EXPIRED))
|
||||
.retryWhen(Retry.max(1).filter(SessionExpiredException.class::isInstance)).map((result) -> {
|
||||
this.healthDetailsHandler.addHealthDetails(builder, result.getT1().getT1(), result.getT1().getT2(),
|
||||
result.getT2());
|
||||
.retryWhen(Retry.max(1).filter(SessionExpiredException.class::isInstance)).map((healthDetails) -> {
|
||||
this.healthDetailsHandler.addHealthDetails(builder, healthDetails);
|
||||
return builder.build();
|
||||
});
|
||||
}
|
||||
|
||||
Mono<Tuple2<Tuple2<String, String>, ResultSummary>> runHealthCheckQuery() {
|
||||
Mono<Neo4jHealthDetails> runHealthCheckQuery() {
|
||||
// We use WRITE here to make sure UP is returned for a server that supports
|
||||
// all possible workloads
|
||||
return Mono.using(() -> this.driver.rxSession(Neo4jHealthIndicator.DEFAULT_SESSION_CONFIG), (session) -> {
|
||||
RxResult result = session.run(Neo4jHealthIndicator.CYPHER);
|
||||
return Mono.from(result.records())
|
||||
.flatMap((record) -> Mono
|
||||
.just(Tuples.of(record.get("version").asString(), record.get("edition").asString()))
|
||||
.zipWhen((edition) -> Mono.from(result.consume())));
|
||||
return Mono.from(result.records()).zipWhen((record) -> Mono.from(result.consume()))
|
||||
.map((tuple) -> new Neo4jHealthDetails(tuple.getT1(), tuple.getT2()));
|
||||
}, RxSession::close);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
|
|
Loading…
Reference in New Issue