@@ -54,6 +54,7 @@ import (
5454const (
5555 DCS_DIAL_TIMEOUT = 2 * time .Hour
5656 DCS_GENERAL_OP_TIMEOUT = 45 * time .Second
57+ DCS_TIME_FORMAT = "2006-01-02 15:04:05.000"
5758)
5859
5960type Plugin struct {
@@ -73,6 +74,8 @@ type DCSDetectorOpAvailabilityMap map[dcspb.Detector]dcspb.DetectorState
7374
7475type DCSDetectorInfoMap map [dcspb.Detector ]* dcspb.DetectorInfo
7576
77+ type ECSDetectorInfoMap map [string ]ECSDetectorInfo
78+
7679func NewPlugin (endpoint string ) integration.Plugin {
7780 u , err := url .Parse (endpoint )
7881 if err != nil {
@@ -121,7 +124,7 @@ func (p *Plugin) GetData(_ []any) string {
121124 environmentIds := environment .ManagerInstance ().Ids ()
122125
123126 outMap := make (map [string ]interface {})
124- outMap ["partitions" ] = p .partitionStatesForEnvs (environmentIds )
127+ outMap ["partitions" ] = p .pendingEorsForEnvs (environmentIds )
125128
126129 p .detectorMapMu .RLock ()
127130 outMap ["detectors" ] = p .detectorMap .ToEcsDetectors ()
@@ -139,20 +142,50 @@ func (p *Plugin) GetEnvironmentsData(environmentIds []uid.ID) map[uid.ID]string
139142 return nil
140143 }
141144
142- out := p .partitionStatesForEnvs (environmentIds )
145+ envMan := environment .ManagerInstance ()
146+ pendingEors := p .pendingEorsForEnvs (environmentIds )
147+
148+ out := make (map [uid.ID ]string )
149+
150+ detectorMap := p .detectorMap .ToEcsDetectors ()
151+ for _ , envId := range environmentIds {
152+ env , err := envMan .Environment (envId )
153+ if err != nil {
154+ log .WithField ("partition" , envId ).
155+ WithError (err ).
156+ Error ("DCS client cannot acquire environment" )
157+ continue
158+ }
159+
160+ includedDetectors := env .GetActiveDetectors ().StringList ()
161+ includedDetectorsMap := detectorMap .Filtered (includedDetectors )
162+
163+ pi := PartitionInfo {
164+ Detectors : includedDetectorsMap ,
165+ }
166+ if pendingEorStatus , pendingEorExists := pendingEors [envId ]; pendingEorExists {
167+ pi .SorSuccessful = pendingEorStatus
168+ }
169+
170+ marshalled , err := json .Marshal (pi )
171+ if err != nil {
172+ continue
173+ }
174+ out [envId ] = string (marshalled [:])
175+ }
176+
143177 return out
144178}
145179
146180func (p * Plugin ) GetEnvironmentsShortData (environmentIds []uid.ID ) map [uid.ID ]string {
147- return p . GetEnvironmentsData ( environmentIds )
181+ return nil
148182}
149183
150- func (p * Plugin ) partitionStatesForEnvs (envIds []uid.ID ) map [uid.ID ]string {
151- out := make (map [uid.ID ]string )
184+ func (p * Plugin ) pendingEorsForEnvs (envIds []uid.ID ) map [uid.ID ]bool {
185+ out := make (map [uid.ID ]bool )
152186 for _ , envId := range envIds {
153- if _ , ok := p .pendingEORs [envId .String ()]; ok {
154- out [envId ] = "SOR SUCCESSFUL"
155- }
187+ _ , pendingEorExists := p .pendingEORs [envId .String ()]
188+ out [envId ] = pendingEorExists
156189 }
157190 return out
158191}
@@ -168,6 +201,10 @@ func (p *Plugin) updateLastKnownDetectorStates(detectorMatrix []*dcspb.DetectorI
168201 } else {
169202 if detInfo .State != dcspb .DetectorState_NULL_STATE {
170203 p .detectorMap [dcsDet ].State = detInfo .State
204+ timestamp , err := time .Parse (DCS_TIME_FORMAT , detInfo .Timestamp )
205+ if err == nil {
206+ p .detectorMap [dcsDet ].Timestamp = fmt .Sprintf ("%d" , timestamp .UnixMilli ())
207+ }
171208 }
172209 }
173210 }
@@ -184,6 +221,10 @@ func (p *Plugin) updateDetectorOpAvailabilities(detectorMatrix []*dcspb.Detector
184221 } else {
185222 p .detectorMap [dcsDet ].PfrAvailability = detInfo .PfrAvailability
186223 p .detectorMap [dcsDet ].SorAvailability = detInfo .SorAvailability
224+ timestamp , err := time .Parse (DCS_TIME_FORMAT , detInfo .Timestamp )
225+ if err == nil {
226+ p .detectorMap [dcsDet ].Timestamp = fmt .Sprintf ("%d" , timestamp .UnixMilli ())
227+ }
187228 }
188229 }
189230}
0 commit comments