I am trying to remove the name in the detail of each service in the health check result since the application name repeatedly printed in the response:
{
"name": "myservice-api",
"status": "UP",
"details": {
"Auth0": {
"name": "myservice-api",
"status": "UP",
"details": {
"url": "http://localhost:8082/auth0/testall"
}
},
"VerificationCode": {
"name": "myservice-api",
"status": "UP",
"details": {
"url": "http://localhost:8082/verificationcode/v2//_admin/health"
}
},
"SAP": {
"name": "myservice-api",
"status": "UP",
"details": {
"url": "http://localhost:8082/sap/crm_consumer_management/v1/$metadata"
}
}
}
I want to show health check like this:
{
"name": "myservice-api",
"status": "UP",
"details": {
"Auth0": {
"status": "UP",
"details": {
"url": "http://localhost:8082/auth0/testall"
}
},
"VerificationCode": {
"status": "UP",
"details": {
"url": "http://localhost:8082/verificationcode/v2//_admin/health"
}
},
"SAP": {
"status": "UP",
"details": {
"url": "http://localhost:8082/sap/crm_consumer_management/v1/$metadata"
}
}
}
I notice DefaultHealthAggregator has method uses application name as following, that's the cause of same service name keeps showing in other service health details:
protected HealthResult buildResult(HealthStatus status, Object details, HealthLevelOfDetail healthLevelOfDetail) {
if (healthLevelOfDetail == HealthLevelOfDetail.STATUS) {
return HealthResult.builder(null, status).build();
}
return HealthResult.builder(
applicationConfiguration.getName().orElse(Environment.DEFAULT_NAME),
status
).details(details).build();
}
I am trying to override that method in Kotlin, remain rest of the class intact, I am not sure if it is possible, I have tried following:
@Singleton
@Replaces(DefaultHealthAggregator::class)
class ServicesHealthAggregator @Inject constructor(
applicationConfiguration: ApplicationConfiguration
) : DefaultHealthAggregator(applicationConfiguration) {
override fun aggregateDetails(results: MutableList<HealthResult>?): Any {
val details = mutableMapOf<String, Any>()
results?.forEach { details[it.name] = buildDetailResult(it.status, it.details) }
return details
}
private fun buildDetailResult(status: HealthStatus, details: Any): HealthResult {
return HealthResult.builder(null, status).details(details).build()
}
}
I also tried to only implement HealthAggregator and replaces DefaultHealthAggregator as documentation suggested, but that requires rewrite the whole class (this approach Micronaut does pick up the bean though).
Is it possible?
Micronaut Version: 3.8.7