Sn0rt commented on PR #10639:
URL: https://github.com/apache/apisix/pull/10639#issuecomment-1853402930

   > Hi @Sn0rt The APISIX 
[documentation](https://github.com/apache/apisix/blob/master/docs/en/latest/tutorials/health-check.md#state-transition-diagram)
 describes the state transition process for health checks, which have a total 
of 4 states, and the prometheus plugin doesn't take into account the 
`mostly_healty` and `mostly_unhealty` states. I think this can be solved by 
adding `mostly_healty` and `mostly_unhealty` states to the Prometheus 
indicator. Instead of treating `mostly_healty` as a `health` state.
   
   The reason why mostly_healthy is regarded as health is because when upstream 
selects a node, both mostly_healthy and healthy are regarded as health. The 
core logic reference screenshot is from resty-helath-check. For this reason, 
the PR is written like this.
   
   ```lua
   local function fetch_health_nodes(upstream, checker)
       local nodes = upstream.nodes
       if not checker then
           local new_nodes = core.table.new(0, #nodes)
           for _, node in ipairs(nodes) do
               new_nodes = transform_node(new_nodes, node)
           end
           return new_nodes
       end
   
       local host = upstream.checks and upstream.checks.active and 
upstream.checks.active.host
       local port = upstream.checks and upstream.checks.active and 
upstream.checks.active.port
       local up_nodes = core.table.new(0, #nodes)
       for _, node in ipairs(nodes) do
           local ok, err = checker:get_target_status(node.host, port or 
node.port, host)
           if ok then
               up_nodes = transform_node(up_nodes, node)
           elseif err then
               core.log.warn("failed to get health check target status, addr: ",
                   node.host, ":", port or node.port, ", host: ", host, ", err: 
", err)
           end
       end
   
       if core.table.nkeys(up_nodes) == 0 then
           core.log.warn("all upstream nodes is unhealthy, use default")
           for _, node in ipairs(nodes) do
               up_nodes = transform_node(up_nodes, node)
           end
       end
   
       return up_nodes
   end
   
   ```


-- 
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