Skip to content

Commit

Permalink
[core] Expose DCS last known detector state matrix to GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
teo committed Nov 10, 2023
1 parent fd7d48e commit 3e8163f
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions core/integration/dcs/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type Plugin struct {

dcsClient *RpcClient
pendingEORs map[string] /*envId*/ int64

detectorMatrix []*dcspb.DetectorInfo
}

type DCSDetectors []dcspb.Detector
Expand All @@ -77,10 +79,11 @@ func NewPlugin(endpoint string) integration.Plugin {
portNumber, _ := strconv.Atoi(u.Port())

return &Plugin{
dcsHost: u.Hostname(),
dcsPort: portNumber,
dcsClient: nil,
pendingEORs: make(map[string]int64),
dcsHost: u.Hostname(),
dcsPort: portNumber,
dcsClient: nil,
pendingEORs: make(map[string]int64),
detectorMatrix: make([]*dcspb.DetectorInfo, 0),
}
}

Expand Down Expand Up @@ -113,6 +116,8 @@ func (p *Plugin) GetData(_ []any) string {
outMap := make(map[string]interface{})
outMap["partitions"] = p.partitionStatesForEnvs(environmentIds)

outMap["detectors"] = p.detectorMatrix

out, err := json.Marshal(outMap)
if err != nil {
return ""
Expand Down Expand Up @@ -176,7 +181,25 @@ func (p *Plugin) Init(instanceId string) error {
time.Sleep(3 * time.Second)
break
}
log.WithField("event", ev.String()).Debug("received DCS event")

if ev != nil && ev.Eventtype == dcspb.EventType_HEARTBEAT {
log.Trace("received DCS heartbeat event")
if dm := ev.GetDetectorMatrix(); len(dm) > 0 {
p.detectorMatrix = dm
}
continue
}

if ev != nil && ev.Eventtype == dcspb.EventType_STATE_CHANGE_EVENT {
log.Trace("received DCS state change event")
if dm := ev.GetDetectorMatrix(); len(dm) > 0 {
p.detectorMatrix = dm
}
continue
}

log.WithField("event", ev.String()).
Debug("received DCS event")
}

log.WithField("endpoint", viper.GetString("dcsServiceEndpoint")).
Expand Down

0 comments on commit 3e8163f

Please sign in to comment.