Skip to content

Commit

Permalink
Merge pull request #471 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR - Fetch immediate LB stats on-demand
  • Loading branch information
UltraInstinct14 authored Dec 26, 2023
2 parents 15eed72 + 0748b76 commit 6bb845b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
1 change: 1 addition & 0 deletions loxinet/dpbroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const (
DpStatsGet
DpStatsClr
DpMapGet
DpStatsGetImm
)

// DpStatusT - status of a dp work
Expand Down
7 changes: 5 additions & 2 deletions loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,6 @@ func (e *DpEbpfH) DpStat(w *StatDpWorkQ) int {
switch {
case w.Name == MapNameNat4:
tbl = append(tbl, int(C.LL_DP_NAT_STATS_MAP))
sync = 1
case w.Name == MapNameBD:
tbl = append(tbl, int(C.LL_DP_BD_STATS_MAP), int(C.LL_DP_TX_BD_STATS_MAP))
case w.Name == MapNameRxBD:
Expand All @@ -1032,14 +1031,18 @@ func (e *DpEbpfH) DpStat(w *StatDpWorkQ) int {
return EbpfErrWqUnk
}

if w.Work == DpStatsGet {
if w.Work == DpStatsGet || w.Work == DpStatsGetImm {
var b C.longlong
var p C.longlong

packets = 0
bytes = 0
dropPackets = 0

if w.Work == DpStatsGetImm {
sync = 1
}

for _, t := range tbl {

ret := C.llb_fetch_map_stats_cached(C.int(t), C.uint(w.Mark), C.int(sync),
Expand Down
29 changes: 8 additions & 21 deletions loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ func (R *RuleH) GetNatLbRule() ([]cmn.LbRuleMod, error) {
ret.SecIPs = append(ret.SecIPs, cmn.LbSecIPArg{SecIP: sip.sIP.String()})
}

data.DP(DpStatsGetImm)

// Make Endpoints
tmpEp := data.act.action.(*ruleNatActs).endPoints
for _, ep := range tmpEp {
Expand Down Expand Up @@ -1999,25 +2001,6 @@ func (R *RuleH) RulesSync() {
rule.DP(DpCreate)
}

bytes := uint64(0)
packets := uint64(0)
switch at := rule.act.action.(type) {
case *ruleNatActs:
for _, natActs := range at.endPoints {
bytes += natActs.stat.bytes
packets += natActs.stat.packets
}
}

rule.stat.bytes = bytes
rule.stat.packets = packets

tk.LogIt(-1, "%d:%s,%s pc %v bc %v \n",
rule.ruleNum, ruleKeys, ruleActs,
rule.stat.packets, rule.stat.bytes)

rule.DP(DpStatsGet)

if !rule.hChk.actChk {
continue
}
Expand Down Expand Up @@ -2328,7 +2311,7 @@ func (r *ruleEnt) DP(work DpWorkT) int {
return 0
}

if work == DpStatsGet {
if work == DpStatsGet || work == DpStatsGetImm {
if isNat {
switch at := r.act.action.(type) {
case *ruleNatActs:
Expand All @@ -2340,7 +2323,11 @@ func (r *ruleEnt) DP(work DpWorkT) int {
nStat.Name = MapNameNat4
nStat.Bytes = &nEP.stat.bytes
nStat.Packets = &nEP.stat.packets
mh.dp.ToDpCh <- nStat
if work == DpStatsGetImm {
DpWorkSingle(mh.dp, nStat)
} else {
mh.dp.ToDpCh <- nStat
}
}
}
} else {
Expand Down

0 comments on commit 6bb845b

Please sign in to comment.