mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-08 00:26:37 +08:00
[优化] 修复
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"openflare/model"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// RelayHeartbeatPayload is the payload sent by OpenFlareRelay in each heartbeat.
|
||||
@@ -23,6 +25,8 @@ type RelayHeartbeatPayload struct {
|
||||
HealthEvents []AgentNodeHealthEvent `json:"health_events,omitempty"`
|
||||
}
|
||||
|
||||
const relayFrpsUnhealthyEventType = "frps_unhealthy"
|
||||
|
||||
// RelayConfig is the frps configuration sent to the Relay.
|
||||
type RelayConfig struct {
|
||||
BindPort int `json:"bind_port"`
|
||||
@@ -98,6 +102,9 @@ func HeartbeatRelay(node *model.Node, payload RelayHeartbeatPayload) (*RelayHear
|
||||
return nil, fmt.Errorf("update relay heartbeat: %w", err)
|
||||
}
|
||||
}
|
||||
if err := reconcileRelayHealthEvents(node.NodeID, payload.RelayStatus, now); err != nil {
|
||||
return nil, fmt.Errorf("reconcile relay health events: %w", err)
|
||||
}
|
||||
refreshAccessTokenCache(node)
|
||||
persistRelayHeartbeatObservability(node.NodeID, payload, node.LastSeenAt)
|
||||
|
||||
@@ -142,6 +149,30 @@ func buildRelaySettings() *RelaySettings {
|
||||
}
|
||||
}
|
||||
|
||||
func reconcileRelayHealthEvents(nodeID string, relayStatus string, reportedAt time.Time) error {
|
||||
if relayStatus == "unknown" {
|
||||
return nil
|
||||
}
|
||||
managedTypes := map[string]struct{}{
|
||||
relayFrpsUnhealthyEventType: {},
|
||||
}
|
||||
events := []AgentNodeHealthEvent{}
|
||||
if relayStatus == "unhealthy" {
|
||||
events = append(events, AgentNodeHealthEvent{
|
||||
EventType: relayFrpsUnhealthyEventType,
|
||||
Severity: NodeHealthSeverityCritical,
|
||||
Message: "frps runtime is not healthy",
|
||||
TriggeredAtUnix: reportedAt.Unix(),
|
||||
Metadata: map[string]string{
|
||||
"relay_status": relayStatus,
|
||||
},
|
||||
})
|
||||
}
|
||||
return model.DB.Transaction(func(tx *gorm.DB) error {
|
||||
return reconcileScopedNodeHealthEvents(tx, nodeID, events, reportedAt, managedTypes)
|
||||
})
|
||||
}
|
||||
|
||||
func normalizeRelayStatus(status string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(status)) {
|
||||
case "healthy":
|
||||
|
||||
Reference in New Issue
Block a user