generated from ministryofjustice/hmpps-template-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bc96425
commit 752d314
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...in/uk/gov/justice/digital/hmpps/prisonersearchindexer/health/OpenSearchHealthIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package uk.gov.justice.digital.hmpps.prisonersearchindexer.health | ||
|
||
import org.opensearch.data.client.orhlc.OpenSearchRestTemplate | ||
import org.springframework.boot.actuate.health.AbstractHealthIndicator | ||
import org.springframework.boot.actuate.health.Health | ||
import org.springframework.boot.actuate.health.Status | ||
import org.springframework.data.elasticsearch.core.cluster.ClusterHealth | ||
import org.springframework.stereotype.Component | ||
|
||
@Suppress("SpringJavaInjectionPointsAutowiringInspection") | ||
@Component | ||
class OpenSearchHealthIndicator(private val template: OpenSearchRestTemplate) : AbstractHealthIndicator() { | ||
override fun doHealthCheck(builder: Health.Builder): Unit = | ||
processResponse(builder, template.cluster().health()) | ||
|
||
private fun processResponse(builder: Health.Builder, response: ClusterHealth) { | ||
if (response.isTimedOut) { | ||
builder.down().build() | ||
} else { | ||
val status = response.status | ||
builder.status(if (status == "RED") Status.OUT_OF_SERVICE else Status.UP) | ||
builder.withDetail("cluster_name", response.clusterName) | ||
builder.withDetail("status", response.status) | ||
builder.withDetail("timed_out", response.isTimedOut) | ||
builder.withDetail("number_of_nodes", response.numberOfNodes) | ||
builder.withDetail("number_of_data_nodes", response.numberOfDataNodes) | ||
builder.withDetail("active_primary_shards", response.activePrimaryShards) | ||
builder.withDetail("active_shards", response.activeShards) | ||
builder.withDetail("relocating_shards", response.relocatingShards) | ||
builder.withDetail("initializing_shards", response.initializingShards) | ||
builder.withDetail("unassigned_shards", response.unassignedShards) | ||
builder.withDetail("delayed_unassigned_shards", response.delayedUnassignedShards) | ||
builder.withDetail("number_of_pending_tasks", response.numberOfPendingTasks) | ||
builder.withDetail("number_of_in_flight_fetch", response.numberOfInFlightFetch) | ||
builder.withDetail("task_max_waiting_in_queue_millis", response.taskMaxWaitingTimeMillis) | ||
builder.withDetail("active_shards_percent_as_number", response.activeShardsPercent) | ||
builder.build() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters