-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from InseeFr/devHealthCheck
Dev health check
- Loading branch information
Showing
10 changed files
with
111 additions
and
32 deletions.
There are no files selected for viewing
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
74 changes: 74 additions & 0 deletions
74
kraftwerk-api/src/main/java/fr/insee/kraftwerk/api/services/HealthcheckService.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,74 @@ | ||
package fr.insee.kraftwerk.api.services; | ||
|
||
|
||
import fr.insee.kraftwerk.api.client.GenesisClient; | ||
import fr.insee.kraftwerk.api.configuration.ConfigProperties; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
|
||
@RestController | ||
@Tag(name = "${tag.health-check}") | ||
public class HealthcheckService extends KraftwerkService { | ||
|
||
public static final String OK = "OK"; | ||
public static final String KO = "FAILURE"; | ||
|
||
|
||
@Value("${fr.insee.kraftwerk.version}") | ||
private String projectVersion; | ||
|
||
private final GenesisClient client; | ||
|
||
ConfigProperties configProperties; | ||
|
||
@Autowired | ||
public HealthcheckService(ConfigProperties configProperties) { | ||
this.configProperties = configProperties; | ||
this.client = new GenesisClient(new RestTemplateBuilder(), configProperties); | ||
|
||
} | ||
|
||
|
||
@GetMapping("health-check") | ||
public ResponseEntity<String> healthcheck() { | ||
String status = OK; | ||
String fileStorageStatus = fileStorageExists(); | ||
if (!OK.equals(fileStorageStatus)){status = KO;} | ||
|
||
return ResponseEntity.ok( | ||
""" | ||
%s | ||
Version %s | ||
Genesis health-check %s | ||
File storage %s : %s | ||
""" | ||
.formatted( | ||
status, | ||
projectVersion, | ||
client.pingGenesis().split("\n")[0], | ||
configProperties.getSpecDirectory(), | ||
fileStorageStatus | ||
)); | ||
} | ||
|
||
private String fileStorageExists() { | ||
try{ | ||
Files.exists(Paths.get(configProperties.getSpecDirectory())); | ||
}catch (Exception e){ | ||
return "Disconnected " +e.getMessage(); | ||
} | ||
return OK; | ||
} | ||
|
||
|
||
} |
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
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
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
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
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
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
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
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