feat: improve BGP protocol summary handling by introducing isBGPProtocolSummaryRow function. Update SummarizeProtocolsOutput and related tests to ensure evobgp_* static names are not counted as BGP sessions, enhancing accuracy in protocol summaries.
CI / changes (push) Successful in 5s
CI / openapi (push) Has been skipped
CI / go (push) Successful in 23s
CI / bird2 (push) Has been cancelled
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Has been cancelled
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Has been cancelled
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Has been cancelled
CI / docker-go (evobgp-deploy, 0, deploy/docker/gobinary/Dockerfile, , evobgp-deploy) (push) Has been cancelled
CI / docker-go (evobgp-ingest, 0, deploy/docker/gobinary/Dockerfile, , evobgp-ingest) (push) Has been cancelled
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Has been cancelled
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Has been cancelled
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Has been cancelled
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Has started running
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Has been cancelled
CI / docker-bird (push) Has been cancelled
CI / changes (push) Successful in 5s
CI / openapi (push) Has been skipped
CI / go (push) Successful in 23s
CI / bird2 (push) Has been cancelled
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Has been cancelled
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Has been cancelled
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Has been cancelled
CI / docker-go (evobgp-deploy, 0, deploy/docker/gobinary/Dockerfile, , evobgp-deploy) (push) Has been cancelled
CI / docker-go (evobgp-ingest, 0, deploy/docker/gobinary/Dockerfile, , evobgp-ingest) (push) Has been cancelled
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Has been cancelled
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Has been cancelled
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Has been cancelled
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Has started running
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Has been cancelled
CI / docker-bird (push) Has been cancelled
This commit is contained in:
@@ -11,6 +11,24 @@ type ProtocolsSummary struct {
|
||||
RawLineCount int
|
||||
}
|
||||
|
||||
// isBGPProtocolSummaryRow is true for BIRD "show protocols" summary rows where the
|
||||
// second column (Proto) is BGP. Substring checks are unsafe: names like evobgp_* contain "bgp".
|
||||
func isBGPProtocolSummaryRow(line string) bool {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
return false
|
||||
}
|
||||
low := strings.ToLower(line)
|
||||
if strings.HasPrefix(low, "name") || strings.HasPrefix(low, "table") {
|
||||
return false
|
||||
}
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) < 2 {
|
||||
return false
|
||||
}
|
||||
return strings.EqualFold(fields[1], "BGP")
|
||||
}
|
||||
|
||||
// SummarizeProtocolsOutput extracts BGP session heuristics from birdc output.
|
||||
func SummarizeProtocolsOutput(output string) ProtocolsSummary {
|
||||
var s ProtocolsSummary
|
||||
@@ -22,14 +40,12 @@ func SummarizeProtocolsOutput(output string) ProtocolsSummary {
|
||||
continue
|
||||
}
|
||||
low := strings.ToLower(line)
|
||||
if strings.HasPrefix(low, "name") || strings.HasPrefix(low, "table") {
|
||||
if !isBGPProtocolSummaryRow(line) {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(low, "bgp") {
|
||||
s.BGPSessionsTotal++
|
||||
if strings.Contains(low, "established") {
|
||||
s.BGPEstablished++
|
||||
}
|
||||
s.BGPSessionsTotal++
|
||||
if strings.Contains(low, "established") {
|
||||
s.BGPEstablished++
|
||||
}
|
||||
}
|
||||
return s
|
||||
|
||||
@@ -12,3 +12,14 @@ uplink BGP --- start 10:00:01 Established
|
||||
t.Fatalf("got %+v", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummarizeProtocolsOutput_evoBGPNameNotCountedAsBGP(t *testing.T) {
|
||||
sample := `Name Proto Table State Since Info
|
||||
evobgp_prefixes_v4 Static master4 up 17:32:14.631
|
||||
evobgp_prefixes_v6 Static master6 up 17:32:14.631
|
||||
`
|
||||
s := SummarizeProtocolsOutput(sample)
|
||||
if s.BGPSessionsTotal != 0 || s.BGPEstablished != 0 {
|
||||
t.Fatalf("evobgp_* static names must not match substring bgp: got %+v", s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func CountEstablishedBGPSessions(showProtocolsOutput string) int {
|
||||
if line == "" || strings.HasPrefix(line, "name") || strings.HasPrefix(strings.ToLower(line), "table") {
|
||||
continue
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(line), "bgp") {
|
||||
if !isBGPProtocolSummaryRow(line) {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(strings.ToLower(line), "established") {
|
||||
|
||||
Reference in New Issue
Block a user