Skip to content

[TT-15507] Reverting /hello endpoint to always return 200 status code #7279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

mativm02
Copy link
Contributor

@mativm02 mativm02 commented Aug 7, 2025

User description

Description

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

PR Type

Bug fix


Description

  • Reverts /hello endpoint to always return HTTP 200 status

  • Refactors health check status calculation logic

  • Adds error logging for JSON encoding failures

  • Ensures consistent HTTP headers and response structure


Diagram Walkthrough

flowchart LR
  oldStatus["Old health check status logic"]
  newStatus["New status: always HTTP 200"]
  errorHandling["Add error logging for JSON encoding"]
  headers["Consistent HTTP headers"]
  oldStatus -- "replaced by" --> newStatus
  newStatus -- "includes" --> errorHandling
  newStatus -- "ensures" --> headers
Loading

File Walkthrough

Relevant files
Bug fix
health_check.go
Refactor health check to always return HTTP 200 and improve error
handling

gateway/health_check.go

  • Refactored health check status logic to always return HTTP 200
  • Removed use of determineHealthStatus for HTTP status code
  • Added error logging for JSON encoding failures in readiness handler
  • Ensured consistent HTTP headers and response structure
+24/-4   

@buger
Copy link
Member

buger commented Aug 7, 2025

💔 The detected issue is not in one of the allowed statuses 💔

Detected Status Open
Allowed Statuses In Dev,In Code Review,Ready for Testing,In Test,In Progress,In Review ✔️

Please ensure your jira story is in one of the allowed statuses

Copy link
Contributor

github-actions bot commented Aug 7, 2025

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Health Status Logic Change

The logic for determining the health status in the /hello endpoint has been refactored to use a local fail count and a switch statement. Reviewers should ensure this new logic matches the intended health check semantics and does not introduce regressions compared to the previous implementation.

var failCount int

for _, v := range checks {
	if v.Status == Fail {
		failCount++
	}
}

var status HealthCheckStatus

switch failCount {
case 0:
	status = Pass

case len(checks):
	status = Fail

default:
	status = Warn
}
Error Logging Consistency

Error logging for JSON encoding failures has been added to both liveness and readiness handlers. Confirm that the log messages are consistent and provide sufficient context for troubleshooting.

err := json.NewEncoder(w).Encode(res)
if err != nil {
	mainLog.Warning(fmt.Sprintf("[Readiness] Could not encode response, error: %s", err.Error()))
}

Copy link
Contributor

github-actions bot commented Aug 7, 2025

API Changes

no api changes detected

Copy link
Contributor

github-actions bot commented Aug 7, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Handle empty health checks case safely

The switch statement using case len(checks): will never match because failCount
cannot equal len(checks) unless all checks fail, but this logic may be unclear and
could lead to subtle bugs if the checks slice is empty. Add a guard to ensure
len(checks) is not zero before using it in the switch, or handle the zero-checks
case explicitly.

gateway/health_check.go [192-209]

 for _, v := range checks {
 	if v.Status == Fail {
 		failCount++
 	}
 }
 
 var status HealthCheckStatus
 
-switch failCount {
-case 0:
-	status = Pass
-
-case len(checks):
-	status = Fail
-
-default:
+if len(checks) == 0 {
 	status = Warn
+} else {
+	switch failCount {
+	case 0:
+		status = Pass
+	case len(checks):
+		status = Fail
+	default:
+		status = Warn
+	}
 }
Suggestion importance[1-10]: 8

__

Why: This suggestion correctly identifies a subtle bug: if checks is empty, case len(checks): will always match 0, causing all-empty health checks to be marked as Fail instead of a more appropriate status (like Warn). The improved code safely handles the empty case, improving correctness and robustness.

Medium

Copy link

sonarqubecloud bot commented Aug 7, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
61.5% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@mativm02 mativm02 closed this Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants