Мы используем Spring Actuator для мониторинга и управления наше применение в различных производственных средах. В нашем application.properties у нас есть группа работоспособности, настроенная следующим образом:
Код: Выделить всё
management.health.livenessstate.enabled=true
management.endpoint.health.group.liveness.include=livenessState,rabbitMqState
management.endpoint.health.group.liveness.show-details=always
Код: Выделить всё
@Bean
public RabbitMqStateHealthIndicator rabbitMqStateHealthIndicator(RabbitMqEndpoint endpoint) {
return new RabbitMqStateHealthIndicator(endpoint);
}
Код: Выделить всё
@RequiredArgsConstructor
@Slf4j
public class RabbitMqStateHealthIndicator implements HealthIndicator {
private final RabbitMqEndpoint endpoint;
@Override
public Health health() {
return new Health.Builder()
.status(getStatus())
// Looks like "java.util.concurrent.ThreadPoolExecutor@34e1411[Running, pool size = 1, active threads = 0, queued tasks = 0, completed tasks = 3]"
.withDetail("executor", endpoint.getMessageDispatcher().getTaskExecutor().getThreadPoolExecutor().toString())
.withDetail("isQueueInitializingFailed", endpoint.isQueueInitializingFailed())
.withDetails(getConnectionDetails())
.withDetails(getSessionDetails())
.build();
}
private Status getStatus() {
JmsConnection connection = endpoint.getConnection();
Status result = Status.UP;
// Consider dispatcher healthy while we are disconnected (session.isClosed) to avoid unnecessary restarts.
boolean isDispatcherHealthy = endpoint.getSession().isClosed() ||
endpoint.getMessageDispatcher().allConsumerThreadsAreAlive();
if (connection == null ||
connection.isFailed() || // If we have unlimited reconnect attempts, isFailed will always be false
endpoint.isQueueInitializingFailed() ||
!isDispatcherHealthy) {
result = Status.DOWN;
log.warn("""
Returning {} status in health indicator \
[connection is null? {}, connection.isFailed? {}, \
isQueueInitializingFailed? {}, isDispatcherHealthy? {}]\
""",
result,
connection == null,
connection != null && connection.isFailed(),
endpoint.isQueueInitializingFailed(),
isDispatcherHealthy);
}
return result;
}
private Map getConnectionDetails() {
return Optional.ofNullable(endpoint.getConnection()).map(connection -> Map.of(
"connection.isClosed", connection.isClosed(), // seems to always be false
"connection.isFailed", connection.isFailed(), // true: when all reconnection attempts failed
"connection.isConnected", connection.isConnected(), // false: when all reconnection attempts failed
"connection.isStarted", connection.isStarted() // false: when all reconnection attempts failed
))
.orElse(Collections.emptyMap());
}
private Map getSessionDetails() {
return Optional.ofNullable(endpoint.getSession())
// true: when trying to reconnect or when all reconnection attempts failed
.map(session -> Collections.singletonMap("session.isClosed", session.isClosed()))
.orElse(Collections.emptyMap());
}
}
Код: Выделить всё
error - APPLICATION FAILED TO START
Description:
Included health contributor 'rabbitMqState' in group 'liveness' does not exist
Action:
Update your application to correct the invalid configuration.
You can also set 'management.endpoint.health.validate-group-membership' to false to disable the validation.
Вопросы:
- Есть ли новый способ регистрации или ссылки на пользовательские индикаторы работоспособности в Spring Boot 3.X?
- Существуют ли какие-либо дополнительные конфигурации или шаги, необходимые Actuator для распознавания пользовательских индикаторов работоспособности в новой версии?
Подробнее здесь: https://stackoverflow.com/questions/786 ... uator-live