feat(api): add live status tracking for speakers and BGP sessions
CI / changes (push) Successful in 9s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 24s
CI / web (push) Successful in 29s
CI / go (push) Successful in 43s
CI / bird2 (push) Successful in 15s
CI / release (push) Successful in 3m29s
CI / changes (push) Successful in 9s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 24s
CI / web (push) Successful in 29s
CI / go (push) Successful in 43s
CI / bird2 (push) Successful in 15s
CI / release (push) Successful in 3m29s
- Introduced new schemas for `SpeakerLiveStatus`, `BgpSessionLive`, and `LiveSpeakerPoll` in OpenAPI documentation to support live status queries. - Enhanced the `/v1/speakers` endpoint to include a `live` query parameter, allowing retrieval of real-time speaker and BGP status. - Updated the HTTP API to collect and return live status data for speakers, improving monitoring capabilities. - Modified frontend components to display live status information, enhancing user visibility into speaker health and BGP session states. - Added a new endpoint `/v1/bird/status` for retrieving the local BIRD status, further enriching the network monitoring features.
This commit is contained in:
@@ -156,33 +156,14 @@ func WakeReplicas(ctx context.Context, st store.Backend, tenantID, revisionID st
|
||||
return out
|
||||
}
|
||||
|
||||
// CheckHealth GETs /v1/agent/health for UI Connected/Offline status.
|
||||
// CheckHealth is deprecated; use FetchAgentHealth.
|
||||
func CheckHealth(ctx context.Context, sp *store.Speaker, opts Options) (ok bool, detail string) {
|
||||
if sp == nil {
|
||||
return false, "nil speaker"
|
||||
}
|
||||
meta := store.ParseSpeakerMeta(sp.MetaJSON)
|
||||
url := store.AgentHealthURL(meta)
|
||||
if url == "" {
|
||||
return false, "agent_domain not configured"
|
||||
}
|
||||
secret := strings.TrimSpace(meta.AgentSecret)
|
||||
if secret == "" {
|
||||
return false, "agent_secret missing"
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return false, err.Error()
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+secret)
|
||||
resp, err := opts.client().Do(req)
|
||||
if err != nil {
|
||||
return false, err.Error()
|
||||
}
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
res := FetchAgentHealth(ctx, sp, opts)
|
||||
if res.OK {
|
||||
return true, "connected"
|
||||
}
|
||||
b, _ := io.ReadAll(resp.Body)
|
||||
return false, fmt.Sprintf("HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(b)))
|
||||
if res.Error != "" {
|
||||
return false, res.Error
|
||||
}
|
||||
return false, "agent unhealthy"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package nodedispatch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"evobgp/internal/store"
|
||||
)
|
||||
|
||||
// AgentHealthResult is the parsed outcome of GET /v1/agent/health on a replica.
|
||||
type AgentHealthResult struct {
|
||||
OK bool
|
||||
Error string
|
||||
LastAppliedRevisionID string
|
||||
LastSyncAt string
|
||||
}
|
||||
|
||||
// FetchAgentHealth GETs /v1/agent/health for UI Connected/Offline status.
|
||||
func FetchAgentHealth(ctx context.Context, sp *store.Speaker, opts Options) AgentHealthResult {
|
||||
if sp == nil {
|
||||
return AgentHealthResult{Error: "nil speaker"}
|
||||
}
|
||||
meta := store.ParseSpeakerMeta(sp.MetaJSON)
|
||||
url := store.AgentHealthURL(meta)
|
||||
if url == "" {
|
||||
return AgentHealthResult{Error: "agent_domain not configured"}
|
||||
}
|
||||
secret := strings.TrimSpace(meta.AgentSecret)
|
||||
if secret == "" {
|
||||
return AgentHealthResult{Error: "agent_secret missing"}
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return AgentHealthResult{Error: err.Error()}
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+secret)
|
||||
resp, err := opts.client().Do(req)
|
||||
if err != nil {
|
||||
return AgentHealthResult{Error: err.Error()}
|
||||
}
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
b, _ := io.ReadAll(resp.Body)
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
return AgentHealthResult{
|
||||
Error: fmt.Sprintf("HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(b))),
|
||||
}
|
||||
}
|
||||
var out struct {
|
||||
OK bool `json:"ok"`
|
||||
LastAppliedRevisionID string `json:"last_applied_revision_id"`
|
||||
LastSyncAt string `json:"last_sync_at"`
|
||||
}
|
||||
if err := json.Unmarshal(b, &out); err != nil {
|
||||
return AgentHealthResult{Error: err.Error()}
|
||||
}
|
||||
res := AgentHealthResult{
|
||||
OK: out.OK,
|
||||
LastAppliedRevisionID: strings.TrimSpace(out.LastAppliedRevisionID),
|
||||
LastSyncAt: strings.TrimSpace(out.LastSyncAt),
|
||||
}
|
||||
if !res.OK {
|
||||
res.Error = "agent reported ok=false"
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user