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:
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"evobgp/internal/birdfmt"
|
||||
"evobgp/internal/bundle"
|
||||
"evobgp/internal/jobs"
|
||||
"evobgp/internal/observability"
|
||||
@@ -58,6 +59,7 @@ func (s *Server) registerV1(m *http.ServeMux) {
|
||||
m.HandleFunc("POST /apply", s.handleApply)
|
||||
m.HandleFunc("POST /speakers/{id}/apply", s.handleSpeakerApply)
|
||||
m.HandleFunc("POST /bird/reload", s.handleBirdReload)
|
||||
m.HandleFunc("GET /bird/status", s.handleBirdStatus)
|
||||
m.HandleFunc("GET /jobs", s.handleListJobs)
|
||||
m.HandleFunc("GET /jobs/{job_id}", s.handleGetJob)
|
||||
m.HandleFunc("POST /jobs/{job_id}/cancel", s.handleCancelJob)
|
||||
@@ -555,6 +557,21 @@ func (s *Server) handleBirdReload(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusAccepted, map[string]any{"job_id": j.ID, "status": "queued"})
|
||||
}
|
||||
|
||||
func (s *Server) handleBirdStatus(w http.ResponseWriter, r *http.Request) {
|
||||
a, ok := authFromContext(r.Context())
|
||||
if !ok {
|
||||
writeProblem(w, http.StatusUnauthorized, "Unauthorized", "missing auth")
|
||||
return
|
||||
}
|
||||
if !s.requireAtLeast(w, a, "viewer") {
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 12*time.Second)
|
||||
defer cancel()
|
||||
st := birdfmt.InspectLocalBird(ctx)
|
||||
writeJSON(w, http.StatusOK, st)
|
||||
}
|
||||
|
||||
func (s *Server) handleListJobs(w http.ResponseWriter, r *http.Request) {
|
||||
a, ok := authFromContext(r.Context())
|
||||
if !ok {
|
||||
|
||||
@@ -14,6 +14,28 @@ import (
|
||||
"evobgp/internal/store"
|
||||
)
|
||||
|
||||
// mergeBirdPostApplyMeta attaches a birdc snapshot after deploy/reload (best-effort).
|
||||
func mergeBirdPostApplyMeta(j *Job) {
|
||||
if strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_SOCKET")) == "" {
|
||||
j.mergeMeta(map[string]any{"bird_post_apply_check": "skipped_no_birdc_socket"})
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
|
||||
defer cancel()
|
||||
st := birdfmt.InspectLocalBird(ctx)
|
||||
inner := map[string]any{
|
||||
"bgp_established": st.BGPEstablished,
|
||||
"bgp_sessions_total": st.BGPSessionsTotal,
|
||||
}
|
||||
if st.Error != "" {
|
||||
inner["ok"] = false
|
||||
inner["error"] = st.Error
|
||||
} else {
|
||||
inner["ok"] = true
|
||||
}
|
||||
j.mergeMeta(map[string]any{"bird_post_apply": inner})
|
||||
}
|
||||
|
||||
const (
|
||||
KindModuleRefresh = "module_refresh"
|
||||
KindDeployApply = "deploy_apply"
|
||||
@@ -85,6 +107,7 @@ func (w *Worker) Process(j *Job) {
|
||||
j.Fail(err.Error())
|
||||
return
|
||||
}
|
||||
mergeBirdPostApplyMeta(j)
|
||||
j.Succeed()
|
||||
default:
|
||||
j.Fail("unknown job kind")
|
||||
@@ -137,6 +160,7 @@ func (w *Worker) runDeployApply(j *Job) {
|
||||
j.Fail(err.Error())
|
||||
return
|
||||
}
|
||||
mergeBirdPostApplyMeta(j)
|
||||
j.Succeed()
|
||||
return
|
||||
}
|
||||
@@ -146,6 +170,7 @@ func (w *Worker) runDeployApply(j *Job) {
|
||||
return
|
||||
}
|
||||
}
|
||||
mergeBirdPostApplyMeta(j)
|
||||
j.Succeed()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user