Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bird output for gateway metrics #512

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/frontend/internal/frontend/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ var regex = regexp.MustCompile(`(?m) Routes:.*`)
func ParseShowProtocolsAll(output string) []*BirdStats {
res := []*BirdStats{}

// BIRD 2.0.10 ready.
// Name Proto Table State Since Info
// these 2 first lines must be removed.
outputSplitted := strings.Split(output, "\n")
if len(outputSplitted) > 2 && outputSplitted[0][:4] == "BIRD" && outputSplitted[1][:4] == "Name" {
output = strings.Join(outputSplitted[2:], "\n")
}

protocols := strings.Split(output, "\n\n")

for _, protocol := range protocols {
Expand Down
106 changes: 104 additions & 2 deletions cmd/frontend/internal/frontend/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestParseShowProtocolsAll(t *testing.T) {
},
want: []*BirdStats{
{
gatewayName: "BIRD",
gatewayName: "device1",
routesImported: 0,
routesExported: 0,
routesPreferred: 0,
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestParseShowProtocolsAll(t *testing.T) {
},
want: []*BirdStats{
{
gatewayName: "BIRD",
gatewayName: "device1",
routesImported: 0,
routesExported: 0,
routesPreferred: 0,
Expand Down Expand Up @@ -178,6 +178,32 @@ func TestParseShowProtocolsAll(t *testing.T) {
},
},
},
{
name: "t3",
args: args{
output: t3,
},
want: []*BirdStats{
{
gatewayName: "NBR-gateway-v4-a-1",
routesImported: 1,
routesExported: 1,
routesPreferred: 1,
},
{
gatewayName: "NBR-gateway-v6-a-1",
routesImported: 1,
routesExported: 1,
routesPreferred: 1,
},
{
gatewayName: "NBR-BFD",
routesImported: 0,
routesExported: 0,
routesPreferred: 0,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -497,3 +523,79 @@ NBR-gateway-v6-a-1 BGP --- start 10:39:56.122 Active Sock
Output filter: cluster_access

NBR-BFD BFD --- up 09:19:34.280`

var t3 = `BIRD 2.0.10 ready.
Name Proto Table State Since Info
NBR-gateway-v4-a-1 BGP --- up 13:49:37.427 Established
BGP state: Established
Neighbor address: 169.254.100.150%ext-vlan0
Neighbor AS: 4248829953
Local AS: 8103
Neighbor ID: 169.254.100.150
Local capabilities
Multiprotocol
AF announced: ipv4
Route refresh
4-octet AS numbers
Enhanced refresh
Neighbor capabilities
Multiprotocol
AF announced: ipv4 ipv6
Route refresh
4-octet AS numbers
Enhanced refresh
Session: external AS4
Source address: 169.254.100.1
Hold timer: 2.107/3
Keepalive timer: 0.268/1
Channel ipv4
State: UP
Table: master4
Preference: 100
Input filter: cluster_breakout
Output filter: cluster_access
Routes: 1 imported, 1 exported, 1 preferred
Route change stats: received rejected filtered ignored accepted
Import updates: 1 0 0 0 1
Import withdraws: 0 0 --- 0 0
Export updates: 2 1 0 --- 1
Export withdraws: 0 --- --- --- 0
BGP Next hop: 169.254.100.1

NBR-gateway-v6-a-1 BGP --- up 13:49:37.047 Established
BGP state: Established
Neighbor address: 100:100::150%ext-vlan0
Neighbor AS: 4248829953
Local AS: 8103
Neighbor ID: 169.254.100.150
Local capabilities
Multiprotocol
AF announced: ipv6
Route refresh
4-octet AS numbers
Enhanced refresh
Neighbor capabilities
Multiprotocol
AF announced: ipv4 ipv6
Route refresh
4-octet AS numbers
Enhanced refresh
Session: external AS4
Source address: 100:100::1
Hold timer: 2.193/3
Keepalive timer: 0.055/1
Channel ipv6
State: UP
Table: master6
Preference: 100
Input filter: cluster_breakout
Output filter: cluster_access
Routes: 1 imported, 1 exported, 1 preferred
Route change stats: received rejected filtered ignored accepted
Import updates: 1 0 0 0 1
Import withdraws: 0 0 --- 0 0
Export updates: 2 1 0 --- 1
Export withdraws: 0 --- --- --- 0
BGP Next hop: 100:100::1 fe80::fe:a6ff:fea1:960a

NBR-BFD BFD --- up 13:49:34.392 `