fix: fallback hostname to ip like add_target and get_target#51
Merged
Conversation
Signed-off-by: Nic <qianyong@api7.ai>
4f50958 to
4cc586e
Compare
Signed-off-by: Nic <qianyong@api7.ai>
|
|
Signed-off-by: Nic <qianyong@api7.ai>
AlinsRan
approved these changes
Feb 5, 2026
| --- no_error_log | ||
| healthy SUCCESS increment | ||
| event: target status '127.0.0.1 (127.0.0.1:2119)' from 'false' to 'true' | ||
| event: target status '127.0.0.1(127.0.0.1:2119)' from 'false' to 'true' |
Author
There was a problem hiding this comment.
lua-resty-healthcheck/lib/resty/healthcheck.lua
Line 1361 in f1e644c
Actually, there is no space between
hostname and ( .
Because the assertion is no_error_log, the mistake wasn't detected. So the previous test was actually ineffective; if there was really a problem with the code, this test wouldn't have found it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Because when using
add_targetandget_target, ifhostnameis not specified, it will fallback to ip:lua-resty-healthcheck/lib/resty/healthcheck.lua
Lines 490 to 493 in f1e644c
lua-resty-healthcheck/lib/resty/healthcheck.lua
Line 473 in f1e644c
However, the same logic is missing in the
incr_counterfunction. This causes the hostname to be missing in the counter key in the shared memory when using thereport_http_statusfunction to report passive health check data, which further results in theget_target_listfunction being unable to correctly retrieve the counter data:lua-resty-healthcheck/lib/resty/healthcheck.lua
Lines 1842 to 1849 in f1e644c
However,
get_target_listneeds to retrieve data from the shared dict through a key that includeshostname. Since the keys do not match, it cannot work.