Skip to content

Commit e7b7512

Browse files
DurgaPrasad-54vishwab1
authored andcommitted
Release 3.6.1 (#374)
* feat(health,version): update version and health endpoints and add advance check for database * fix(health): normalize severity and fix slow query false positives * fix(health): avoid false CRITICAL on single long-running MySQL transaction * fix(health): enforce 3s DB connection timeout via HikariCP * feat(health): add healthcontroller and fix versioncontroller issues
1 parent 90db8b4 commit e7b7512

File tree

2 files changed

+126
-49
lines changed

2 files changed

+126
-49
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.
17+
* See the 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+
23+
package com.iemr.common.controller.health;
24+
25+
import com.iemr.common.service.health.HealthService;
26+
import java.util.Map;
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.RestController;
33+
34+
/**
35+
* Health check controller for Common-API.
36+
* Verifies application liveness and dependency health (DB, Redis).
37+
*
38+
* @author vaishnavbhosale
39+
*/
40+
@RestController
41+
public class HealthController {
42+
43+
private static final Logger logger = LoggerFactory.getLogger(HealthController.class);
44+
45+
private final HealthService healthService;
46+
47+
public HealthController(HealthService healthService) {
48+
this.healthService = healthService;
49+
}
50+
51+
@GetMapping("/health")
52+
public ResponseEntity<Map<String, Object>> health() {
53+
logger.info("Health check endpoint called");
54+
55+
56+
Map<String, Object> healthStatus = healthService.checkHealth();
57+
58+
// Standard HTTP Status logic
59+
String status = (String) healthStatus.get("status");
60+
HttpStatus httpStatus = "UP".equals(status) ? HttpStatus.OK : HttpStatus.SERVICE_UNAVAILABLE;
61+
62+
logger.info("Health check completed with status: {}", status);
63+
64+
return ResponseEntity.status(httpStatus).body(healthStatus);
65+
}
66+
}
Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
/*
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-
*/
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.
17+
* See the 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+
/**
23+
* REST controller exposing application version and build metadata.
24+
* <p>
25+
* Provides the <code>/version</code> endpoint which returns Git metadata
26+
* in a standardized JSON format consistent across all AMRIT APIs.
27+
* </p>
28+
*
29+
* @author Vaishnav Bhosale
30+
*/
2231
package com.iemr.common.controller.version;
2332

24-
import java.io.BufferedReader;
25-
import java.io.IOException;
2633
import java.io.InputStream;
27-
import java.io.InputStreamReader;
34+
import java.io.IOException;
35+
import java.util.LinkedHashMap;
36+
import java.util.Map;
37+
import java.util.Properties;
2838

2939
import org.slf4j.Logger;
3040
import org.slf4j.LoggerFactory;
@@ -33,49 +43,50 @@
3343
import org.springframework.web.bind.annotation.GetMapping;
3444
import org.springframework.web.bind.annotation.RestController;
3545

36-
import com.iemr.common.utils.response.OutputResponse;
37-
3846
import io.swagger.v3.oas.annotations.Operation;
3947

40-
4148
@RestController
4249
public class VersionController {
4350

44-
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
51+
private final Logger logger =
52+
LoggerFactory.getLogger(this.getClass().getSimpleName());
53+
54+
private static final String UNKNOWN_VALUE = "unknown";
4555

46-
@Operation(summary = "Get version")
47-
@RequestMapping(value = "/version", method = { RequestMethod.GET })
48-
public String versionInformation() {
49-
OutputResponse output = new OutputResponse();
56+
@Operation(summary = "Get version information")
57+
@GetMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE)
58+
public ResponseEntity<Map<String, String>> versionInformation() {
59+
Map<String, String> response = new LinkedHashMap<>();
5060
try {
5161
logger.info("version Controller Start");
52-
output.setResponse(readGitProperties());
62+
Properties gitProperties = loadGitProperties();
63+
response.put("buildTimestamp", gitProperties.getProperty("git.build.time", UNKNOWN_VALUE));
64+
response.put("version", gitProperties.getProperty("git.build.version", UNKNOWN_VALUE));
65+
response.put("branch", gitProperties.getProperty("git.branch", UNKNOWN_VALUE));
66+
response.put("commitHash", gitProperties.getProperty("git.commit.id.abbrev", UNKNOWN_VALUE));
5367
} catch (Exception e) {
54-
output.setError(e);
68+
logger.error("Failed to load version information", e);
69+
response.put("buildTimestamp", UNKNOWN_VALUE);
70+
response.put("version", UNKNOWN_VALUE);
71+
response.put("branch", UNKNOWN_VALUE);
72+
response.put("commitHash", UNKNOWN_VALUE);
5573
}
5674
logger.info("version Controller End");
5775
return ResponseEntity.ok(response);
5876
}
5977

6078
logger.info("version Controller End");
61-
return output.toString();
62-
}
63-
64-
private String readGitProperties() throws Exception {
65-
ClassLoader classLoader = getClass().getClassLoader();
66-
InputStream inputStream = classLoader.getResourceAsStream("git.properties");
67-
68-
return readFromInputStream(inputStream);
79+
return ResponseEntity.ok(response);
6980
}
7081
71-
private String readFromInputStream(InputStream inputStream) throws IOException {
72-
StringBuilder resultStringBuilder = new StringBuilder();
73-
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
74-
String line;
75-
while ((line = br.readLine()) != null) {
76-
resultStringBuilder.append(line).append("\n");
82+
private Properties loadGitProperties() throws IOException {
83+
Properties properties = new Properties();
84+
try (InputStream input = getClass().getClassLoader()
85+
.getResourceAsStream("git.properties")) {
86+
if (input != null) {
87+
properties.load(input);
7788
}
7889
}
79-
return resultStringBuilder.toString();
90+
return properties;
8091
}
81-
}
92+
}

0 commit comments

Comments
 (0)