From 12225497f0010f33c3af07beba77a62f301800e2 Mon Sep 17 00:00:00 2001 From: blazSmehov Date: Thu, 7 May 2026 11:01:04 +0200 Subject: [PATCH] fix: remove decoder active beacons, as there are none, remove active beacons from base health and add lookup beacons to the bridge beacons --- internal/pkg/common/appcontext/context.go | 24 +++++++++++++++++------ internal/pkg/common/appcontext/health.go | 11 ++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/internal/pkg/common/appcontext/context.go b/internal/pkg/common/appcontext/context.go index 2a9237a..be14349 100644 --- a/internal/pkg/common/appcontext/context.go +++ b/internal/pkg/common/appcontext/context.go @@ -59,15 +59,14 @@ func NewAppState() *AppState { Uptime: 0, ActiveReaders: []string{}, ActiveWriters: []string{}, - ActiveBeacons: []string{}, }, + ActiveBeacons: []string{}, }, Decoder: DecoderHealth{ BaseHealth: BaseHealth{ Uptime: 0, ActiveReaders: []string{}, ActiveWriters: []string{}, - ActiveBeacons: []string{}, }, }, Bridge: BridgeHealth{ @@ -75,8 +74,8 @@ func NewAppState() *AppState { Uptime: 0, ActiveReaders: []string{}, ActiveWriters: []string{}, - ActiveBeacons: []string{}, }, + ActiveBeacons: []string{}, }, Kafka: ServiceStatus{Status: "unknown"}, Database: ServiceStatus{Status: "unknown"}, @@ -117,10 +116,14 @@ func (m *AppState) UpdateServerHealth(kafka, database ServiceStatus) { } func (m *AppState) GetLocationHealth(k *kafkaclient.KafkaManager) ([]byte, error) { + beacons := m.GetAllBeacons() + m.health.Location.ActiveBeacons = make([]string, 0, len(beacons)) + for beacon := range beacons { + m.health.Location.ActiveBeacons = append(m.health.Location.ActiveBeacons, beacon) + } m.health.Location.GetUptime(m.startTime) m.health.Location.GetActiveReaders(k) m.health.Location.GetActiveWriters(k) - m.health.Location.GetActiveBeacons(m) return m.health.Location.Marshal() } @@ -128,15 +131,18 @@ func (m *AppState) GetDecoderHealth(k *kafkaclient.KafkaManager) ([]byte, error) m.health.Decoder.GetUptime(m.startTime) m.health.Decoder.GetActiveReaders(k) m.health.Decoder.GetActiveWriters(k) - m.health.Decoder.GetActiveBeacons(m) return m.health.Decoder.Marshal() } func (m *AppState) GetBridgeHealth(k *kafkaclient.KafkaManager) ([]byte, error) { + beacons := m.GetBeaconLookup() + m.health.Bridge.ActiveBeacons = make([]string, 0, len(beacons)) + for beacon := range beacons { + m.health.Bridge.ActiveBeacons = append(m.health.Bridge.ActiveBeacons, beacon) + } m.health.Bridge.GetUptime(m.startTime) m.health.Bridge.GetActiveReaders(k) m.health.Bridge.GetActiveWriters(k) - m.health.Bridge.GetActiveBeacons(m) return m.health.Bridge.Marshal() } @@ -179,6 +185,12 @@ func (m *AppState) CleanLookup() { m.beaconsLookup.Lock.Unlock() } +func (m *AppState) GetBeaconLookup() map[string]string { + m.beaconsLookup.Lock.RLock() + defer m.beaconsLookup.Lock.RUnlock() + return m.beaconsLookup.Lookup +} + // BeaconExists checks if a beacon exists in the lookup func (m *AppState) BeaconExists(id string) (string, bool) { m.beaconsLookup.Lock.RLock() diff --git a/internal/pkg/common/appcontext/health.go b/internal/pkg/common/appcontext/health.go index b9cda36..fadd5df 100644 --- a/internal/pkg/common/appcontext/health.go +++ b/internal/pkg/common/appcontext/health.go @@ -17,7 +17,6 @@ type BaseHealth struct { Uptime time.Duration `json:"uptime"` ActiveReaders []string `json:"activeReaders" gorm:"type:jsonb"` ActiveWriters []string `json:"activeWriters" gorm:"type:jsonb"` - ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"` } type DecoderHealth struct { @@ -27,11 +26,13 @@ type DecoderHealth struct { type LocationHealth struct { BaseHealth + ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"` ActiveSettings []Settings `json:"activeSettings" gorm:"type:jsonb"` } type BridgeHealth struct { BaseHealth + ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"` } type Health struct { @@ -54,14 +55,6 @@ func (b *BaseHealth) GetActiveWriters(m *kafkaclient.KafkaManager) { b.ActiveWriters = m.GetWriters() } -func (b *BaseHealth) GetActiveBeacons(m *AppState) { - beacons := m.GetAllBeacons() - b.ActiveBeacons = []string{} - for beacon := range beacons { - b.ActiveBeacons = append(b.ActiveBeacons, beacon) - } -} - func (d *DecoderHealth) Marshal() ([]byte, error) { return json.Marshal(d) }