Skip to content

Commit

Permalink
gh-265 Fixes for fast liveness check on ep creation
Browse files Browse the repository at this point in the history
(cherry picked from commit c9debd3)
  • Loading branch information
TrekkieCoder committed May 24, 2023
1 parent 45d777a commit 0a36bde
Showing 1 changed file with 52 additions and 44 deletions.
96 changes: 52 additions & 44 deletions loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ func (a *ruleAct) String() string {
for _, n := range na.endPoints {
ks += fmt.Sprintf("eip-%s,ep-%d,w-%d,",
n.xIP.String(), n.xPort, n.weight)
if n.inActive {
if n.inActive || n.noService {
ks += fmt.Sprintf("dead|")
} else {
ks += fmt.Sprintf("alive|")
Expand Down Expand Up @@ -882,6 +882,49 @@ func (R *RuleH) GetNatLbRuleSecIPs(serv cmn.LbServiceArg) []string {
return ips
}

func (R *RuleH) syncEPHostState2Rule(rule *ruleEnt, checkNow bool) bool {
var sType string
rChg := false
if checkNow || time.Duration(time.Now().Sub(rule.sT).Seconds()) >= time.Duration(R.Cfg.RuleInactChkTime) {
switch na := rule.act.action.(type) {
case *ruleNatActs:
if rule.tuples.l4Prot.val == 6 {
sType = HostProbeConnectTcp
} else if rule.tuples.l4Prot.val == 17 {
sType = HostProbeConnectUdp
} else if rule.tuples.l4Prot.val == 1 {
sType = HostProbePing
} else if rule.tuples.l4Prot.val == 132 {
sType = HostProbeConnectSctp
} else {
return rChg
}

for idx, n := range na.endPoints {
sOk := R.IsEpHostActive(makeEPKey(n.xIP.String(), sType, n.xPort))
np := &na.endPoints[idx]
if sOk == false {
if np.noService == false {
np.noService = true
rChg = true
tk.LogIt(tk.LogDebug, "nat lb-rule service-down ep - %s:%s\n", sType, n.xIP.String())
}
} else {
if n.noService {
np.noService = false
np.inActTries = 0
rChg = true
tk.LogIt(tk.LogDebug, "nat lb-rule service-up ep - %s:%s\n", sType, n.xIP.String())
}
}
}
rule.sT = time.Now()
}
}

return rChg
}

// AddNatLbRule - Add a service LB nat rule. The service details are passed in serv argument,
// and end-point information is passed in the slice servEndPoints. On success,
// it will return 0 and nil error, else appropriate return code and error string will be set
Expand Down Expand Up @@ -1084,6 +1127,10 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIpArg,

R.modNatEpHost(r, natActs.endPoints, true)

if r.ActChk {
R.syncEPHostState2Rule(r, true)
}

tk.LogIt(tk.LogDebug, "nat lb-rule added - %d:%s-%s\n", r.ruleNum, r.tuples.String(), r.act.String())

R.Tables[RtLB].eMap[rt.ruleKey()] = r
Expand Down Expand Up @@ -1503,6 +1550,9 @@ func (R *RuleH) AddEpHost(apiCall bool, hostName string, name string, args epHos

R.epMap[epKey] = ep

// Liveness check upfront
R.epCheckNow(ep)

tk.LogIt(tk.LogDebug, "ep-host added %v:%d\n", epKey, ep.hID)

return 0, nil
Expand Down Expand Up @@ -1731,9 +1781,6 @@ func epTicker(R *RuleH, helper int) {
// 1. Syncs rule statistics counts
// 2. Check health of lb-rule end-points
func (R *RuleH) RulesSync() {
var sType string
var rChg bool
now := time.Now()
for _, rule := range R.Tables[RtLB].eMap {
ruleKeys := rule.tuples.String()
ruleActs := rule.act.String()
Expand All @@ -1749,46 +1796,7 @@ func (R *RuleH) RulesSync() {
continue
}

rChg = false

// Check if we need to check health of LB endpoints
if time.Duration(now.Sub(rule.sT).Seconds()) >= time.Duration(R.Cfg.RuleInactChkTime) {
switch na := rule.act.action.(type) {
case *ruleNatActs:
if rule.tuples.l4Prot.val == 6 {
sType = HostProbeConnectTcp
} else if rule.tuples.l4Prot.val == 17 {
sType = HostProbeConnectUdp
} else if rule.tuples.l4Prot.val == 1 {
sType = HostProbePing
} else if rule.tuples.l4Prot.val == 132 {
sType = HostProbeConnectSctp
} else {
break
}

for idx, n := range na.endPoints {
sOk := R.IsEpHostActive(makeEPKey(n.xIP.String(), sType, n.xPort))
np := &na.endPoints[idx]
if sOk == false {
if np.noService == false {
np.noService = true
rChg = true
tk.LogIt(tk.LogDebug, "nat lb-rule service-down ep - %s:%s\n", sType, n.xIP.String())
}
} else {
if n.noService {
np.noService = false
np.inActTries = 0
rChg = true
tk.LogIt(tk.LogDebug, "nat lb-rule service-up ep - %s:%s\n", sType, n.xIP.String())
}
}
}
}
rule.sT = now
}

rChg := R.syncEPHostState2Rule(rule, false)
if rChg {
tk.LogIt(tk.LogDebug, "nat lb-Rule updated %d:%s,%s\n", rule.ruleNum, ruleKeys, ruleActs)
rule.DP(DpCreate)
Expand Down

0 comments on commit 0a36bde

Please sign in to comment.