Skip to content

Commit 40eb9fe

Browse files
Cherry-pick health and version API enhancements to release-3.6.1 (#124)
* feat(health,version): add health and version endponts * fix(health): add constant and remove duplicates * fix(health): avoid permanent DEGRADED from historical deadlocks * fix(health): Removed the unnecessary boolean literal * fix(health): Fixed the broken lock-wait detection * fix(health): avoid blocking DB I/O under write lock and restore interrupt flag * fix(health): add cancelFutures in healthservice * fix(health): close basic DB connection before advanced checks and remove shared-map race
1 parent bffa971 commit 40eb9fe

4 files changed

Lines changed: 631 additions & 1 deletion

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* AMRIT – Accessible Medical Records via Integrated Technology
3+
* Integrated EHR (Electronic Health Records) Solution
4+
*
5+
* Copyright (C) "Piramal Swasthya Management and Research Institute"
6+
*
7+
* This file is part of AMRIT.
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program. If not, see https://www.gnu.org/licenses/.
21+
*/
22+
package com.iemr.admin.controller.health;
23+
24+
import java.time.Instant;
25+
import java.util.Map;
26+
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
import org.springframework.http.HttpStatus;
30+
import org.springframework.http.ResponseEntity;
31+
import org.springframework.web.bind.annotation.GetMapping;
32+
import org.springframework.web.bind.annotation.RequestMapping;
33+
import org.springframework.web.bind.annotation.RestController;
34+
35+
import com.iemr.admin.service.health.HealthService;
36+
37+
import io.swagger.v3.oas.annotations.Operation;
38+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
39+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
40+
import io.swagger.v3.oas.annotations.tags.Tag;
41+
42+
@RestController
43+
@RequestMapping("/health")
44+
@Tag(name = "Health Check", description = "APIs for checking infrastructure health status")
45+
public class HealthController {
46+
47+
private static final Logger logger = LoggerFactory.getLogger(HealthController.class);
48+
49+
private final HealthService healthService;
50+
51+
public HealthController(HealthService healthService) {
52+
this.healthService = healthService;
53+
}
54+
55+
@GetMapping
56+
@Operation(summary = "Check infrastructure health",
57+
description = "Returns the health status of MySQL, Redis, and other configured services")
58+
@ApiResponses({
59+
@ApiResponse(responseCode = "200", description = "Services are UP or DEGRADED (operational with warnings)"),
60+
@ApiResponse(responseCode = "503", description = "One or more critical services are DOWN")
61+
})
62+
public ResponseEntity<Map<String, Object>> checkHealth() {
63+
logger.debug("Health check endpoint called");
64+
65+
try {
66+
Map<String, Object> healthStatus = healthService.checkHealth();
67+
String overallStatus = (String) healthStatus.get("status");
68+
69+
HttpStatus httpStatus = "DOWN".equals(overallStatus) ? HttpStatus.SERVICE_UNAVAILABLE : HttpStatus.OK;
70+
71+
logger.debug("Health check completed with status: {}", overallStatus);
72+
return new ResponseEntity<>(healthStatus, httpStatus);
73+
74+
} catch (Exception e) {
75+
logger.error("Unexpected error during health check", e);
76+
77+
Map<String, Object> errorResponse = Map.of(
78+
"status", "DOWN",
79+
"timestamp", Instant.now().toString()
80+
);
81+
82+
return new ResponseEntity<>(errorResponse, HttpStatus.SERVICE_UNAVAILABLE);
83+
}
84+
}
85+
}
86+

src/main/java/com/iemr/admin/controller/version/VersionController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* You should have received a copy of the GNU General Public License
2020
* along with this program. If not, see https://www.gnu.org/licenses/.
2121
*/
22+
2223
package com.iemr.admin.controller.version;
2324

2425
import java.io.BufferedReader;
@@ -36,6 +37,11 @@
3637
import com.iemr.admin.utils.response.OutputResponse;
3738

3839
import io.swagger.v3.oas.annotations.Operation;
40+
import java.io.IOException;
41+
import java.io.InputStream;
42+
import java.util.LinkedHashMap;
43+
import java.util.Properties;
44+
import org.springframework.http.MediaType;
3945

4046

4147
@RestController

0 commit comments

Comments
 (0)