浏览代码

fix: remove decoder active beacons, as there are none, remove active beacons from base health and add lookup beacons to the bridge beacons

master
Blaz Smehov 15 小时前
父节点
当前提交
12225497f0
共有 2 个文件被更改,包括 20 次插入15 次删除
  1. +18
    -6
      internal/pkg/common/appcontext/context.go
  2. +2
    -9
      internal/pkg/common/appcontext/health.go

+ 18
- 6
internal/pkg/common/appcontext/context.go 查看文件

@@ -59,15 +59,14 @@ func NewAppState() *AppState {
Uptime: 0, Uptime: 0,
ActiveReaders: []string{}, ActiveReaders: []string{},
ActiveWriters: []string{}, ActiveWriters: []string{},
ActiveBeacons: []string{},
}, },
ActiveBeacons: []string{},
}, },
Decoder: DecoderHealth{ Decoder: DecoderHealth{
BaseHealth: BaseHealth{ BaseHealth: BaseHealth{
Uptime: 0, Uptime: 0,
ActiveReaders: []string{}, ActiveReaders: []string{},
ActiveWriters: []string{}, ActiveWriters: []string{},
ActiveBeacons: []string{},
}, },
}, },
Bridge: BridgeHealth{ Bridge: BridgeHealth{
@@ -75,8 +74,8 @@ func NewAppState() *AppState {
Uptime: 0, Uptime: 0,
ActiveReaders: []string{}, ActiveReaders: []string{},
ActiveWriters: []string{}, ActiveWriters: []string{},
ActiveBeacons: []string{},
}, },
ActiveBeacons: []string{},
}, },
Kafka: ServiceStatus{Status: "unknown"}, Kafka: ServiceStatus{Status: "unknown"},
Database: 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) { 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.GetUptime(m.startTime)
m.health.Location.GetActiveReaders(k) m.health.Location.GetActiveReaders(k)
m.health.Location.GetActiveWriters(k) m.health.Location.GetActiveWriters(k)
m.health.Location.GetActiveBeacons(m)
return m.health.Location.Marshal() 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.GetUptime(m.startTime)
m.health.Decoder.GetActiveReaders(k) m.health.Decoder.GetActiveReaders(k)
m.health.Decoder.GetActiveWriters(k) m.health.Decoder.GetActiveWriters(k)
m.health.Decoder.GetActiveBeacons(m)
return m.health.Decoder.Marshal() return m.health.Decoder.Marshal()
} }


func (m *AppState) GetBridgeHealth(k *kafkaclient.KafkaManager) ([]byte, error) { 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.GetUptime(m.startTime)
m.health.Bridge.GetActiveReaders(k) m.health.Bridge.GetActiveReaders(k)
m.health.Bridge.GetActiveWriters(k) m.health.Bridge.GetActiveWriters(k)
m.health.Bridge.GetActiveBeacons(m)
return m.health.Bridge.Marshal() return m.health.Bridge.Marshal()
} }


@@ -179,6 +185,12 @@ func (m *AppState) CleanLookup() {
m.beaconsLookup.Lock.Unlock() 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 // BeaconExists checks if a beacon exists in the lookup
func (m *AppState) BeaconExists(id string) (string, bool) { func (m *AppState) BeaconExists(id string) (string, bool) {
m.beaconsLookup.Lock.RLock() m.beaconsLookup.Lock.RLock()


+ 2
- 9
internal/pkg/common/appcontext/health.go 查看文件

@@ -17,7 +17,6 @@ type BaseHealth struct {
Uptime time.Duration `json:"uptime"` Uptime time.Duration `json:"uptime"`
ActiveReaders []string `json:"activeReaders" gorm:"type:jsonb"` ActiveReaders []string `json:"activeReaders" gorm:"type:jsonb"`
ActiveWriters []string `json:"activeWriters" gorm:"type:jsonb"` ActiveWriters []string `json:"activeWriters" gorm:"type:jsonb"`
ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"`
} }


type DecoderHealth struct { type DecoderHealth struct {
@@ -27,11 +26,13 @@ type DecoderHealth struct {


type LocationHealth struct { type LocationHealth struct {
BaseHealth BaseHealth
ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"`
ActiveSettings []Settings `json:"activeSettings" gorm:"type:jsonb"` ActiveSettings []Settings `json:"activeSettings" gorm:"type:jsonb"`
} }


type BridgeHealth struct { type BridgeHealth struct {
BaseHealth BaseHealth
ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"`
} }


type Health struct { type Health struct {
@@ -54,14 +55,6 @@ func (b *BaseHealth) GetActiveWriters(m *kafkaclient.KafkaManager) {
b.ActiveWriters = m.GetWriters() 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) { func (d *DecoderHealth) Marshal() ([]byte, error) {
return json.Marshal(d) return json.Marshal(d)
} }


正在加载...
取消
保存