Skip to content

Commit de9c880

Browse files
authored
Merging to release-5.9.1: [TT-15507] Revert changes to the "/hello" health check endpoint (#7295)
[TT-15507] Revert changes to the "/hello" health check endpoint (#7295) ### **User description** - The /hello (liveness) endpoint is reverted to always respond with HTTP 200, regardless of internal health check status. - Health status calculation in the liveness handler is refactored and simplified—now based solely on the number of failed checks (failCount), removing the previous "critical failure" logic. - Error handling is added for JSON encoding errors in the readiness handler, so encoding issues are now logged. <details open> <summary><a href="https://tyktech.atlassian.net/browse/TT-15507" title="TT-15507" target="_blank">TT-15507</a></summary> <br /> <table> <tr> <th>Summary</th> <td>Revert changes to the "/hello" health check endpoint</td> </tr> <tr> <th>Type</th> <td> <img alt="Bug" src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium" /> Bug </td> </tr> <tr> <th>Status</th> <td>In Dev</td> </tr> <tr> <th>Points</th> <td>N/A</td> </tr> <tr> <th>Labels</th> <td>-</td> </tr> </table> </details> <!-- do not remove this marker as it will break jira-lint's functionality. added_by_jira_lint --> --- <!-- Provide a general summary of your changes in the Title above --> ## Description <!-- Describe your changes in detail --> ## Related Issue <!-- This project only accepts pull requests related to open issues. --> <!-- If suggesting a new feature or change, please discuss it in an issue first. --> <!-- If fixing a bug, there should be an issue describing it with steps to reproduce. --> <!-- OSS: Please link to the issue here. Tyk: please create/link the JIRA ticket. --> ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] 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 <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the 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, Tests ___ ### **Description** Restore /hello to always return 200 Compute Pass/Warn/Fail from check counts Add extensive liveness vs readiness tests Improve JSON encode error handling logs ___ ### Diagram Walkthrough ```mermaid flowchart LR liveH["liveCheckHandler (/hello)"] -- "always 200" --> http200["HTTP 200"] liveH -- "derive Pass/Warn/Fail" --> status["Response.Status"] readyH["readinessHandler (/ready)"] -- "encode + log errors" --> logR["Warning on encode error"] tests["health_check_test.go"] -- "cover scenarios" --> liveH tests -- "compare vs readiness" --> readyH ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>health_check.go</strong><dd><code>Rework liveness logic and enforce 200 response</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> gateway/health_check.go <ul><li>Compute failCount inline and set status.<br> <li> Always write HTTP 200 for /hello.<br> <li> Add error handling for JSON encode in readiness.<br> <li> Remove determineHealthStatus usage in liveness.</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7295/files#diff-978a2d1427d9209765e541618af10683944c6396df1a6fb8b5221e4f16658a6a">+24/-4</a>&nbsp; &nbsp; </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>health_check_test.go</strong><dd><code>Add comprehensive liveness and readiness tests</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> gateway/health_check_test.go <ul><li>Add tests for /hello status and body.<br> <li> Add liveness vs readiness behavior tests.<br> <li> Add edge case coverage and headers checks.<br> <li> Validate JSON payload fields and errors.</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7295/files#diff-08e29946afc7757a9c7baaef04b1a81964640437a684ff6306d1a0c933ac3f6a">+552/-0</a>&nbsp; </td> </tr> </table></td></tr></tr></tbody></table> </details> ___
1 parent 1ff17c4 commit de9c880

File tree

2 files changed

+583
-4
lines changed

2 files changed

+583
-4
lines changed

gateway/health_check.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,26 @@ func (gw *Gateway) liveCheckHandler(w http.ResponseWriter, r *http.Request) {
187187
Details: checks,
188188
}
189189

190-
failCount, criticalFailure := gw.evaluateHealthChecks(checks)
190+
var failCount int
191191

192-
status, httpStatus := gw.determineHealthStatus(failCount, criticalFailure, len(checks))
192+
for _, v := range checks {
193+
if v.Status == Fail {
194+
failCount++
195+
}
196+
}
197+
198+
var status HealthCheckStatus
199+
200+
switch failCount {
201+
case 0:
202+
status = Pass
203+
204+
case len(checks):
205+
status = Fail
206+
207+
default:
208+
status = Warn
209+
}
193210

194211
res.Status = status
195212

@@ -200,7 +217,7 @@ func (gw *Gateway) liveCheckHandler(w http.ResponseWriter, r *http.Request) {
200217
addMascotHeaders(w)
201218
}
202219

203-
w.WriteHeader(httpStatus)
220+
w.WriteHeader(http.StatusOK)
204221
err := json.NewEncoder(w).Encode(res)
205222
if err != nil {
206223
mainLog.Warning(fmt.Sprintf("[Liveness] Could not encode response, error: %s", err.Error()))
@@ -259,7 +276,10 @@ func (gw *Gateway) readinessHandler(w http.ResponseWriter, r *http.Request) {
259276
}
260277

261278
w.WriteHeader(http.StatusOK)
262-
json.NewEncoder(w).Encode(res)
279+
err := json.NewEncoder(w).Encode(res)
280+
if err != nil {
281+
mainLog.Warning(fmt.Sprintf("[Readiness] Could not encode response, error: %s", err.Error()))
282+
}
263283
}
264284

265285
func (gw *Gateway) determineHealthStatus(failCount int, criticalFailure bool, totalChecks int) (HealthCheckStatus, int) {

0 commit comments

Comments
 (0)