Skip to content

Commit db93a33

Browse files
Cherry-pick health and version API enhancements to release-3.6.1 (#139)
* feat(health,version): add health and version endpoints * fix(jwt): fix the jwtvalidation issues * refactor(health): simplify MySQL health check and remove sensitive details * fix(health): harden advanced MySQL checks and throttle execution * fix(health): scope PROCESSLIST lock-wait check to application DB user * fix(health): cancel timed-out advanced MySQL checks to avoid orphaned tasks * fix(health): avoid sharing JDBC connections across threads in advanced MySQL checks * refactor(health): extract MySQL basic health query into helper method * fix(health): avoid blocking DB I/O under write lock and restore interrupt flag * feat(health): add gpl license header
1 parent c1ac206 commit db93a33

5 files changed

Lines changed: 765 additions & 1 deletion

File tree

pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,32 @@
511511
</execution>
512512
</executions>
513513
</plugin>
514+
<plugin>
515+
<groupId>io.github.git-commit-id</groupId>
516+
<artifactId>git-commit-id-maven-plugin</artifactId>
517+
<version>7.0.0</version>
518+
<executions>
519+
<execution>
520+
<id>get-the-git-infos</id>
521+
<goals>
522+
<goal>revision</goal>
523+
</goals>
524+
<phase>initialize</phase>
525+
</execution>
526+
</executions>
527+
<configuration>
528+
<generateGitPropertiesFile>true</generateGitPropertiesFile>
529+
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
530+
<includeOnlyProperties>
531+
<property>^git.branch$</property>
532+
<property>^git.commit.id.abbrev$</property>
533+
<property>^git.build.version$</property>
534+
<property>^git.build.time$</property>
535+
</includeOnlyProperties>
536+
<failOnNoGitDirectory>false</failOnNoGitDirectory>
537+
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
538+
</configuration>
539+
</plugin>
514540
<plugin>
515541
<groupId>org.springframework.boot</groupId>
516542
<artifactId>spring-boot-maven-plugin</artifactId>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
23+
package com.wipro.fhir.controller.health;
24+
25+
import java.time.Instant;
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.RequestMapping;
33+
import org.springframework.web.bind.annotation.RestController;
34+
import com.wipro.fhir.service.health.HealthService;
35+
import io.swagger.v3.oas.annotations.Operation;
36+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
37+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
38+
import io.swagger.v3.oas.annotations.tags.Tag;
39+
40+
@RestController
41+
@RequestMapping("/health")
42+
@Tag(name = "Health Check", description = "APIs for checking infrastructure health status")
43+
public class HealthController {
44+
45+
private static final Logger logger = LoggerFactory.getLogger(HealthController.class);
46+
47+
private final HealthService healthService;
48+
49+
public HealthController(HealthService healthService) {
50+
this.healthService = healthService;
51+
}
52+
53+
@GetMapping
54+
@Operation(summary = "Check infrastructure health",
55+
description = "Returns the health status of MySQL, Redis, and other configured services")
56+
@ApiResponses({
57+
@ApiResponse(responseCode = "200", description = "Services are UP or DEGRADED (operational with warnings)"),
58+
@ApiResponse(responseCode = "503", description = "One or more critical services are DOWN")
59+
})
60+
public ResponseEntity<Map<String, Object>> checkHealth() {
61+
logger.info("Health check endpoint called");
62+
63+
try {
64+
Map<String, Object> healthStatus = healthService.checkHealth();
65+
String overallStatus = (String) healthStatus.get("status");
66+
67+
// Return 503 only if DOWN; 200 for both UP and DEGRADED (DEGRADED = operational with warnings)
68+
HttpStatus httpStatus = "DOWN".equals(overallStatus) ? HttpStatus.SERVICE_UNAVAILABLE : HttpStatus.OK;
69+
70+
logger.debug("Health check completed with status: {}", overallStatus);
71+
return new ResponseEntity<>(healthStatus, httpStatus);
72+
73+
} catch (Exception e) {
74+
logger.error("Unexpected error during health check", e);
75+
76+
Map<String, Object> errorResponse = Map.of(
77+
"status", "DOWN",
78+
"timestamp", Instant.now().toString()
79+
);
80+
81+
return new ResponseEntity<>(errorResponse, HttpStatus.SERVICE_UNAVAILABLE);
82+
}
83+
}
84+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.wipro.fhir.controller.version;
23+
24+
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.util.LinkedHashMap;
27+
import java.util.Map;
28+
import java.util.Properties;
29+
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
32+
33+
import org.springframework.http.MediaType;
34+
import org.springframework.http.ResponseEntity;
35+
import org.springframework.web.bind.annotation.GetMapping;
36+
import org.springframework.web.bind.annotation.RestController;
37+
38+
import io.swagger.v3.oas.annotations.Operation;
39+
40+
@RestController
41+
public class VersionController {
42+
43+
private final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
44+
45+
private static final String UNKNOWN_VALUE = "unknown";
46+
47+
@Operation(summary = "Get version information")
48+
@GetMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE)
49+
public ResponseEntity<Map<String, String>> versionInformation() {
50+
Map<String, String> response = new LinkedHashMap<>();
51+
try {
52+
logger.info("version Controller Start");
53+
Properties gitProperties = loadGitProperties();
54+
response.put("buildTimestamp", gitProperties.getProperty("git.build.time", UNKNOWN_VALUE));
55+
response.put("version", gitProperties.getProperty("git.build.version", UNKNOWN_VALUE));
56+
response.put("branch", gitProperties.getProperty("git.branch", UNKNOWN_VALUE));
57+
response.put("commitHash", gitProperties.getProperty("git.commit.id.abbrev", UNKNOWN_VALUE));
58+
} catch (Exception e) {
59+
logger.error("Failed to load version information", e);
60+
response.put("buildTimestamp", UNKNOWN_VALUE);
61+
response.put("version", UNKNOWN_VALUE);
62+
response.put("branch", UNKNOWN_VALUE);
63+
response.put("commitHash", UNKNOWN_VALUE);
64+
}
65+
logger.info("version Controller End");
66+
return ResponseEntity.ok(response);
67+
}
68+
69+
private Properties loadGitProperties() throws IOException {
70+
Properties properties = new Properties();
71+
try (InputStream input = getClass().getClassLoader()
72+
.getResourceAsStream("git.properties")) {
73+
if (input != null) {
74+
properties.load(input);
75+
}
76+
}
77+
return properties;
78+
}
79+
}

0 commit comments

Comments
 (0)