feat: add BIRD status endpoint and integrate birdc checks into job processing. Enhance UI to display BIRD runtime status and job metadata, improving user feedback on BIRD operations.
CI / changes (push) Successful in 6s
CI / openapi (push) Has been skipped
CI / go (push) Successful in 25s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Successful in 1m7s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Successful in 1m5s
CI / docker-bird (push) Has been skipped
CI / bird2 (push) Successful in 16s
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Successful in 1m0s
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Successful in 1m25s
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Successful in 1m30s
CI / docker-go (evobgp-deploy, 0, deploy/docker/gobinary/Dockerfile, , evobgp-deploy) (push) Successful in 1m30s
CI / docker-go (evobgp-ingest, 0, deploy/docker/gobinary/Dockerfile, , evobgp-ingest) (push) Successful in 1m27s
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Successful in 1m13s
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Successful in 1m32s
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Successful in 1m23s
CI / changes (push) Successful in 6s
CI / openapi (push) Has been skipped
CI / go (push) Successful in 25s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Successful in 1m7s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Successful in 1m5s
CI / docker-bird (push) Has been skipped
CI / bird2 (push) Successful in 16s
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Successful in 1m0s
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Successful in 1m25s
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Successful in 1m30s
CI / docker-go (evobgp-deploy, 0, deploy/docker/gobinary/Dockerfile, , evobgp-deploy) (push) Successful in 1m30s
CI / docker-go (evobgp-ingest, 0, deploy/docker/gobinary/Dockerfile, , evobgp-ingest) (push) Successful in 1m27s
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Successful in 1m13s
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Successful in 1m32s
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Successful in 1m23s
This commit is contained in:
1 parent
e1aaa18377
commit
94a4c6acd4
8 files changed
+324
-8
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package birdfmt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// LocalBirdStatus is returned by GET /v1/bird/status (same host as birdc when socket is configured).
|
||||
type LocalBirdStatus struct {
|
||||
BirdcConfigured bool `json:"birdc_configured"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
ProtocolsExcerpt string `json:"protocols_excerpt,omitempty"`
|
||||
BGPSessionsTotal int `json:"bgp_sessions_total"`
|
||||
BGPEstablished int `json:"bgp_established"`
|
||||
// Healthy: null if birdc not configured; false if birdc failed or BGP sessions exist but none Established; true otherwise.
|
||||
Healthy *bool `json:"healthy"`
|
||||
}
|
||||
|
||||
// InspectLocalBird runs `birdc show protocols all` using EVOBGP_BIRDC_SOCKET / EVOBGP_BIRDC_BIN.
|
||||
func InspectLocalBird(ctx context.Context) LocalBirdStatus {
|
||||
sock := strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_SOCKET"))
|
||||
if sock == "" {
|
||||
return LocalBirdStatus{
|
||||
BirdcConfigured: false,
|
||||
Message: "EVOBGP_BIRDC_SOCKET не задан на этом процессе — статус BIRD недоступен (типично, если birdc только на ноде со спикером).",
|
||||
Healthy: nil,
|
||||
}
|
||||
}
|
||||
bin := strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_BIN"))
|
||||
out, err := ShowProtocols(ctx, sock, bin)
|
||||
if err != nil {
|
||||
f := false
|
||||
return LocalBirdStatus{
|
||||
BirdcConfigured: true,
|
||||
Error: err.Error(),
|
||||
Healthy: &f,
|
||||
}
|
||||
}
|
||||
sum := SummarizeProtocolsOutput(out)
|
||||
excerpt := out
|
||||
const maxExcerpt = 20000
|
||||
if len(excerpt) > maxExcerpt {
|
||||
excerpt = excerpt[:maxExcerpt] + "\n# … truncated …\n"
|
||||
}
|
||||
ok := sum.BGPSessionsTotal == 0 || sum.BGPEstablished > 0
|
||||
return LocalBirdStatus{
|
||||
BirdcConfigured: true,
|
||||
ProtocolsExcerpt: excerpt,
|
||||
BGPSessionsTotal: sum.BGPSessionsTotal,
|
||||
BGPEstablished: sum.BGPEstablished,
|
||||
Healthy: &ok,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package birdfmt
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ProtocolsSummary is a lightweight parse of `birdc show protocols all` (BIRD 2).
|
||||
type ProtocolsSummary struct {
|
||||
BGPSessionsTotal int
|
||||
BGPEstablished int
|
||||
RawLineCount int
|
||||
}
|
||||
|
||||
// SummarizeProtocolsOutput extracts BGP session heuristics from birdc output.
|
||||
func SummarizeProtocolsOutput(output string) ProtocolsSummary {
|
||||
var s ProtocolsSummary
|
||||
lines := strings.Split(output, "\n")
|
||||
s.RawLineCount = len(lines)
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
low := strings.ToLower(line)
|
||||
if strings.HasPrefix(low, "name") || strings.HasPrefix(low, "table") {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(low, "bgp") {
|
||||
s.BGPSessionsTotal++
|
||||
if strings.Contains(low, "established") {
|
||||
s.BGPEstablished++
|
||||
}
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package birdfmt
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSummarizeProtocolsOutput(t *testing.T) {
|
||||
sample := `name proto table state since info
|
||||
device1 Device --- up 10:00:00
|
||||
uplink BGP --- start 10:00:01 Established
|
||||
`
|
||||
s := SummarizeProtocolsOutput(sample)
|
||||
if s.BGPSessionsTotal != 1 || s.BGPEstablished != 1 {
|
||||
t.Fatalf("got %+v", s)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user