hub 0.164.0 (unreleased): host_swap_short / host_swap_ok operator alarm from the agent's host and guest swap numbers (R-1192 follow-up); wire gate allowlists guests.spec.swap_bytes
gates / gates (push) Failing after 14m53s

This commit is contained in:
admin committed 2026-10-21 21:55:15 +02:00
1 parent dbfe5dac06
commit 3c620f8d2e
8 files changed
+169

No files matched your search

+22
View File
@@ -2736,6 +2736,28 @@ func (s *Store) LatestHostLivenessEvent(customerID, hostID string) (*Event, erro
return &e, nil
}
// LatestHostSwapEvent returns the newest host_swap_short / host_swap_ok event for hostID, or nil (R-1192 follow-up).
// The host is read from the event's details (host_id), so a customer with two hosts keeps two states.
func (s *Store) LatestHostSwapEvent(customerID, hostID string) (*Event, error) {
var e Event
var createdAt string
err := s.db.QueryRow(`
SELECT id, customer_id, event_type, severity, message, details_json, source, created_at
FROM events
WHERE customer_id = ? AND event_type IN ('host_swap_short', 'host_swap_ok') AND json_extract(details_json, '$.host_id') = ?
ORDER BY created_at DESC, id DESC
LIMIT 1`, customerID, hostID,
).Scan(&e.ID, &e.CustomerID, &e.EventType, &e.Severity, &e.Message, &e.DetailsJSON, &e.Source, &createdAt)
if err == sql.ErrNoRows {
return nil, nil
}
if err != nil {
return nil, err
}
e.CreatedAt = parseSQLiteTime(createdAt)
return &e, nil
}
// GetAllRecentEvents returns the most recent events across all customers.
func (s *Store) GetAllRecentEvents(limit int) ([]Event, error) {
rows, err := s.db.Query(`