From be87d7ccc733006155091df179d31a5548d901f8 Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Tue, 13 Jun 2023 23:37:01 +0900 Subject: [PATCH] Updated default liveness check policy #315 --- loxinet/loxinet.go | 2 ++ loxinet/rules.go | 35 +++++++++++++++++++++++++++-------- options/options.go | 1 + 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/loxinet/loxinet.go b/loxinet/loxinet.go index 7c01f3661..2d98f6206 100644 --- a/loxinet/loxinet.go +++ b/loxinet/loxinet.go @@ -67,6 +67,7 @@ type loxiNetH struct { wg sync.WaitGroup bgp *GoBgpH sumDis bool + pProbe bool has *CIStateH logger *tk.Logger ready bool @@ -181,6 +182,7 @@ func loxiNetInit() { mh.self = opts.Opts.ClusterSelf mh.sumDis = opts.Opts.CSumDisable + mh.pProbe = opts.Opts.PassiveEPProbe mh.sigCh = make(chan os.Signal, 5) signal.Notify(mh.sigCh, os.Interrupt, syscall.SIGCHLD) signal.Notify(mh.sigCh, os.Interrupt, syscall.SIGHUP) diff --git a/loxinet/rules.go b/loxinet/rules.go index d1501ebdc..39d8a7556 100644 --- a/loxinet/rules.go +++ b/loxinet/rules.go @@ -181,6 +181,7 @@ type epHostOpts struct { probeDuration uint32 currProbeDuration uint32 probePort uint16 + probeActivated bool } type epHost struct { @@ -770,7 +771,7 @@ func validateXlateEPWeights(servEndPoints []cmn.LbEndPointArg) (int, error) { return 0, nil } -func (R *RuleH) modNatEpHost(r *ruleEnt, endpoints []ruleNatEp, doAddOp bool) { +func (R *RuleH) modNatEpHost(r *ruleEnt, endpoints []ruleNatEp, doAddOp bool, liveCheckEn bool) { var hopts epHostOpts hopts.inActTryThr = DflLbaInactiveTries hopts.probeDuration = DflHostProbeTimeout @@ -790,6 +791,10 @@ func (R *RuleH) modNatEpHost(r *ruleEnt, endpoints []ruleNatEp, doAddOp bool) { hopts.probeType = HostProbePing } + if mh.pProbe == true || liveCheckEn { + hopts.probeActivated = true + } + epKey := makeEPKey(nep.xIP.String(), hopts.probeType, hopts.probePort) if doAddOp { @@ -1084,7 +1089,7 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIpArg, eRule.act.action.(*ruleNatActs).endPoints = eEps eRule.act.action.(*ruleNatActs).mode = natActs.mode - R.modNatEpHost(eRule, eEps, true) + R.modNatEpHost(eRule, eEps, true, serv.Monitor) eRule.sT = time.Now() eRule.iTo = serv.InactiveTimeout @@ -1118,7 +1123,7 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIpArg, r.BGP = serv.Bgp r.CI = cmn.CIDefault - R.modNatEpHost(r, natActs.endPoints, true) + R.modNatEpHost(r, natActs.endPoints, true, serv.Monitor) tk.LogIt(tk.LogDebug, "nat lb-rule added - %d:%s-%s\n", r.ruleNum, r.tuples.String(), r.act.String()) @@ -1174,7 +1179,7 @@ func (R *RuleH) DeleteNatLbRule(serv cmn.LbServiceArg) (int, error) { defer R.Tables[RtLB].Mark.PutCounter(rule.ruleNum) eEps := rule.act.action.(*ruleNatActs).endPoints - R.modNatEpHost(rule, eEps, false) + R.modNatEpHost(rule, eEps, false, rule.ActChk) delete(R.Tables[RtLB].eMap, rt.ruleKey()) if rule.ruleNum < RtMaximumLbs { @@ -1408,9 +1413,13 @@ func (R *RuleH) GetEpHosts() ([]cmn.EndPointMod, error) { // Make end-point ret.HostName = data.hostName ret.Name = data.epKey - ret.InActTries = data.opts.inActTryThr - ret.ProbeType = data.opts.probeType - ret.ProbeDuration = data.opts.probeDuration + if !data.opts.probeActivated { + ret.ProbeType = HostProbeNone + } else { + ret.ProbeType = data.opts.probeType + ret.ProbeDuration = data.opts.probeDuration + ret.InActTries = data.opts.inActTryThr + } ret.ProbeReq = data.opts.probeReq ret.ProbeResp = data.opts.probeResp ret.ProbePort = data.opts.probePort @@ -1483,6 +1492,10 @@ func makeEPKey(hostName string, probeType string, probePort uint16) string { func (R *RuleH) AddEPHost(apiCall bool, hostName string, name string, args epHostOpts) (int, error) { var epKey string + if apiCall && args.probeType != HostProbeNone { + args.probeActivated = true + } + R.epMx.Lock() defer R.epMx.Unlock() @@ -1624,6 +1637,12 @@ func (R *RuleH) epCheckNow(ep *epHost) { sName = fmt.Sprintf("[%s]:%d", ep.hostName, ep.opts.probePort) } + if !ep.opts.probeActivated { + ep.inactive = false + ep.inActTries = 0 + return + } + if ep.opts.probeType == HostProbeConnectTcp || ep.opts.probeType == HostProbeConnectUdp || ep.opts.probeType == HostProbeConnectSctp { @@ -1739,7 +1758,7 @@ func epTicker(R *RuleH, helper int) { if idx > 0 { idx = 0 // We restart the sweep from beginning while taking a short break - // Due to how goLang range, works we would be sweeping eps mostly randomly + // Due to how goLang range works, we would be sweeping eps mostly randomly R.epMx.Unlock() break } diff --git a/options/options.go b/options/options.go index e2cb7eaa9..9e8be5503 100644 --- a/options/options.go +++ b/options/options.go @@ -22,4 +22,5 @@ var Opts struct { CPUProfile string `long:"cpuprofile" description:"Enable cpu profiling and specify file to use" default:"none" env:"CPUPROF"` NoPrometheus bool `short:"p" long:"nopro" description:" Do not run prometheus thread"` CSumDisable bool `long:"disable-csum" description:"Disable checksum update(experimental)"` + PassiveEPProbe bool `long:"passive-probe" description:"Enable passive liveness probes(experimental)"` }