hanzhenfang commented on code in PR #13894:
URL: https://github.com/apache/apisix/pull/13894#discussion_r4491211557


##########
apisix/healthcheck_manager.lua:
##########
@@ -250,12 +251,46 @@ function _M.fetch_checker(resource_path, resource_ver)
 end
 
 
+-- resty.healthcheck INTERNAL_STATES: 1=healthy, 2=unhealthy,
+-- 3=mostly_healthy, 4=mostly_unhealthy. Routing treats 1 and 3 as usable.
+local SHM_HEALTHY = {
+    [1] = true,
+    [3] = true,
+}

Review Comment:
   This hard-codes resty.healthcheck internals into APISIX:
   
   - `1`/`3` mirror the dependency's private `INTERNAL_STATES` table 
([healthcheck.lua#L212-L221](https://github.com/api7/lua-resty-healthcheck/blob/v3.2.3/lib/resty/healthcheck.lua#L212-L221)),
 which is a `local` and not part of its public API. The numbers are just the 
list positions of the state names.
   - The key built in `fetch_shm_target_status` (`TARGET_STATE .. ":" .. ip .. 
":" .. port .. ":" .. hostname`) re-implements the private `key_for()` 
([#L248](https://github.com/api7/lua-resty-healthcheck/blob/v3.2.3/lib/resty/healthcheck.lua#L248)).
   
   If the library ever reorders/adds a state or changes its key layout, nothing 
errors: we'd either misread the state, or `shm:get()` returns nil and we 
silently fall back to the worker-local cache — i.e. this fix stops working 
without any test failing.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to