Преглед изворни кода

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 пре 1 дан
родитељ
комит
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,
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()


+ 2
- 9
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)
}


Loading…
Откажи
Сачувај