-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
101ed7c
commit 0419967
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/it/gov/pagopa/payhub/auth/config/MongoHealthIndicator.java
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,25 @@ | ||
package it.gov.pagopa.payhub.auth.config; | ||
|
||
import org.bson.Document; | ||
import org.springframework.boot.actuate.health.AbstractHealthIndicator; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.Assert; | ||
|
||
/** The actual version of cosmosDb-MongoDB doesn't support hello command,introduced by Spring-boot 3.3.4, rollback to previous command */ | ||
@Component | ||
public class MongoHealthIndicator extends AbstractHealthIndicator { | ||
private final MongoTemplate mongoTemplate; | ||
|
||
public MongoHealthIndicator(MongoTemplate mongoTemplate) { | ||
super("MongoDB health check failed"); | ||
Assert.notNull(mongoTemplate, "MongoTemplate must not be null"); | ||
this.mongoTemplate = mongoTemplate; | ||
} | ||
|
||
protected void doHealthCheck(Health.Builder builder) { | ||
Document result = this.mongoTemplate.executeCommand("{ isMaster: 1 }"); | ||
builder.up().withDetail("maxWireVersion", result.getInteger("maxWireVersion")); | ||
} | ||
} |