Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
225a698
Add /health endpoint and update /version endpoint
DurgaPrasad-54 Feb 16, 2026
e3e0ad2
Update HTTPRequests and fix issues in /health and /version
DurgaPrasad-54 Feb 16, 2026
cc3317b
fix(security): validate authentication for /health details
DurgaPrasad-54 Feb 16, 2026
62b60fc
feat: update version and health endpoints
DurgaPrasad-54 Feb 16, 2026
0a3c8af
fix(redis): fix redis timeout handling issue
DurgaPrasad-54 Feb 16, 2026
1b4fb14
fix(health): fix InterruptedException handling and add redis timeout …
DurgaPrasad-54 Feb 16, 2026
b5833ed
refactor(health): simplify MySQL health check and remove sensitive de…
DurgaPrasad-54 Feb 19, 2026
bf0586c
fix(health): removed unused methods from healthservices
DurgaPrasad-54 Feb 19, 2026
e737699
fix(health): remove unused imports
DurgaPrasad-54 Feb 19, 2026
def7bc6
fix(health): scope PROCESSLIST lock-wait check to application DB user
DurgaPrasad-54 Feb 21, 2026
f23bf9b
fix(health): avoid permanent DEGRADED from historical deadloc
DurgaPrasad-54 Feb 21, 2026
ae69b74
fix(health): handle executor rejection during shutdown in /health
DurgaPrasad-54 Feb 22, 2026
e95b3d0
refactor(health): centralize component names and fix InterruptedExcep…
DurgaPrasad-54 Feb 22, 2026
f949d14
fix(health): resolve remaining reliability issues on new code
DurgaPrasad-54 Feb 22, 2026
a2db2ab
fix(health): isolate advanced checks in dedicated executor to avoid t…
DurgaPrasad-54 Feb 22, 2026
05960d7
fix(health): cancel timed-out advanced MySQL checks to avoid orphaned…
DurgaPrasad-54 Feb 22, 2026
5dc7d1a
fix(health): make advanced MySQL checks interruptible on timeout
DurgaPrasad-54 Feb 22, 2026
4eb22ea
fix(health): remove unsafe connection sharing from advanced MySQL checks
DurgaPrasad-54 Feb 22, 2026
6d250c7
refactor(health): reduce cognitive complexity of advanced MySQL throt…
DurgaPrasad-54 Feb 22, 2026
5efc1e1
fix(health): cancel in-flight futures on generic failure
DurgaPrasad-54 Feb 22, 2026
8f1f654
feat(health): add gpl license header
DurgaPrasad-54 Mar 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,36 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>7.0.0</version>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is these plugin really required?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vanitha1822 Yes, this plugin is required. It generates the git.properties file during the build, which is used by the /version endpoint to expose build metadata such as branch, commit hash, version, and build timestamp.

<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<includeOnlyProperties>
<property>^git.branch$</property>
<property>^git.commit.id.abbrev$</property>
<property>^git.build.version$</property>
<property>^git.build.time$</property>
<property>^git.commit.message.short$</property>
<property>^git.commit.user.name$</property>
<property>^git.dirty$</property>
<property>^git.total.commit.count$</property>
</includeOnlyProperties>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
84 changes: 84 additions & 0 deletions src/main/java/com/iemr/hwc/controller/health/HealthController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

package com.iemr.hwc.controller.health;

import java.time.Instant;
import java.util.Map;
Comment thread
DurgaPrasad-54 marked this conversation as resolved.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iemr.hwc.service.health.HealthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("/health")
@Tag(name = "Health Check", description = "APIs for checking infrastructure health status")
public class HealthController {

private static final Logger logger = LoggerFactory.getLogger(HealthController.class);

private final HealthService healthService;

public HealthController(HealthService healthService) {
this.healthService = healthService;
}

@GetMapping
@Operation(summary = "Check infrastructure health",
description = "Returns the health status of MySQL, Redis, and other configured services")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Services are UP or DEGRADED (operational with warnings)"),
@ApiResponse(responseCode = "503", description = "One or more critical services are DOWN")
})
public ResponseEntity<Map<String, Object>> checkHealth() {
logger.info("Health check endpoint called");

try {
Map<String, Object> healthStatus = healthService.checkHealth();
String overallStatus = (String) healthStatus.get("status");

// Return 503 only if DOWN; 200 for both UP and DEGRADED (DEGRADED = operational with warnings)
HttpStatus httpStatus = "DOWN".equals(overallStatus) ? HttpStatus.SERVICE_UNAVAILABLE : HttpStatus.OK;

logger.debug("Health check completed with status: {}", overallStatus);
return new ResponseEntity<>(healthStatus, httpStatus);

} catch (Exception e) {
logger.error("Unexpected error during health check", e);

Map<String, Object> errorResponse = Map.of(
"status", "DOWN",
"timestamp", Instant.now().toString()
);

return new ResponseEntity<>(errorResponse, HttpStatus.SERVICE_UNAVAILABLE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,59 +21,59 @@
*/
package com.iemr.hwc.controller.version;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.iemr.hwc.utils.response.OutputResponse;

import io.swagger.v3.oas.annotations.Operation;

@RestController
public class VersionController {

private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
private final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());

private static final String UNKNOWN_VALUE = "unknown";

@Operation(summary = "Get version information")
@GetMapping(value = "/version")
public String versionInformation() {
OutputResponse output = new OutputResponse();
@GetMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, String>> versionInformation() {
Map<String, String> response = new LinkedHashMap<>();
try {
logger.info("version Controller Start");
output.setResponse(readGitProperties());
Properties gitProperties = loadGitProperties();
response.put("buildTimestamp", gitProperties.getProperty("git.build.time", UNKNOWN_VALUE));
response.put("version", gitProperties.getProperty("git.build.version", UNKNOWN_VALUE));
response.put("branch", gitProperties.getProperty("git.branch", UNKNOWN_VALUE));
response.put("commitHash", gitProperties.getProperty("git.commit.id.abbrev", UNKNOWN_VALUE));
} catch (Exception e) {
output.setError(e);
logger.error("Failed to load version information", e);
response.put("buildTimestamp", UNKNOWN_VALUE);
response.put("version", UNKNOWN_VALUE);
response.put("branch", UNKNOWN_VALUE);
response.put("commitHash", UNKNOWN_VALUE);
}

logger.info("version Controller End");
return output.toString();
}

private String readGitProperties() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("git.properties");

return readFromInputStream(inputStream);
return ResponseEntity.ok(response);
}

private String readFromInputStream(InputStream inputStream)
throws IOException {
StringBuilder resultStringBuilder = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = br.readLine()) != null) {
resultStringBuilder.append(line).append("\n");
private Properties loadGitProperties() throws IOException {
Properties properties = new Properties();
try (InputStream input = getClass().getClassLoader()
.getResourceAsStream("git.properties")) {
if (input != null) {
properties.load(input);
}
}
return resultStringBuilder.toString();
return properties;
}
}
Loading