-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix k8s frontend and backend sync issue (#694)
* - Add health check controller * - Fix neo4j url * - Fix endpoint url * - Add Readiness Probe * - Adjust Readiness Probe Timings * - Adjust Readiness Probe params * - Use external url * - Update port config in deployment * - Update port config in deployment * - Update Health Check * - Update Health Check timings * - Remove Unnecessary Code * - Add changes to prod k8 charts
- Loading branch information
1 parent
6fb0c6a
commit 89bdeec
Showing
7 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v2/HealthCheckController.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,72 @@ | ||
package uk.ac.ebi.spot.ols.controller.api.v2; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.HttpStatus; | ||
import uk.ac.ebi.spot.ols.controller.api.v2.responses.V2PagedAndFacetedResponse; | ||
import uk.ac.ebi.spot.ols.model.v2.V2Entity; | ||
import uk.ac.ebi.spot.ols.repository.neo4j.OlsNeo4jClient; | ||
import uk.ac.ebi.spot.ols.repository.v2.V2OntologyRepository; | ||
|
||
import java.util.Map; | ||
|
||
@RestController | ||
@RequestMapping("/api/v2") | ||
public class HealthCheckController { | ||
@Autowired | ||
V2OntologyRepository ontologyRepository; | ||
|
||
@Autowired | ||
OlsNeo4jClient neo4jClient; | ||
private static final Logger logger = LoggerFactory.getLogger(HealthCheckController.class); | ||
|
||
@RequestMapping("/health") | ||
public ResponseEntity<String> checkHealth() { | ||
if (!checkSolr()) { | ||
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).body("Solr is not initialized."); | ||
} | ||
if (!checkNeo4j()) { | ||
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).body("Neo4j is not initialized."); | ||
} | ||
return ResponseEntity.ok("All systems are operational."); | ||
} | ||
|
||
private boolean checkNeo4j() { | ||
try { | ||
if (neo4jClient.getDatabaseNodeCount() > 0) { | ||
logger.info("Neo4J is initialized."); | ||
return true; | ||
} else { | ||
logger.error("Neo4J is not initialized yet as Neo4J node elements were less than 1."); | ||
return false; | ||
} | ||
} catch (Exception e) { | ||
logger.error("Neo4j endpoint returned an error.", e); | ||
return false; | ||
} | ||
} | ||
|
||
private boolean checkSolr() { | ||
Pageable pageable = Pageable.ofSize(20); | ||
try { | ||
V2PagedAndFacetedResponse<V2Entity> result = new V2PagedAndFacetedResponse<>( | ||
ontologyRepository.find(pageable, "en", null, null, null, | ||
false, Map.of())); | ||
if (result.totalElements > 0) { | ||
logger.info("Solr is initialized."); | ||
return true; | ||
} else { | ||
logger.error("Solr is not initialized yet as 'totalElements' in jsonResponse not found or less than 1."); | ||
return false; | ||
} | ||
} catch (Exception e) { | ||
logger.error("Solr health check returned an error.", e); | ||
return false; | ||
} | ||
} | ||
} |
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