@@ -1291,10 +1291,7 @@ func (c *ChaosExperimentHandler) GetDBExperiment(query bson.D) (dbChaosExperimen
12911291
12921292func (c * ChaosExperimentHandler ) GetProbesInExperimentRun (ctx context.Context , projectID string , experimentRunID string , faultName string ) ([]* model.GetProbesInExperimentRunResponse , error ) {
12931293 var (
1294- probeDetails []* model.GetProbesInExperimentRunResponse
1295- probeStatusMap = make (map [string ]model.ProbeVerdict )
1296- probeDescriptionMap = make (map [string ]* string )
1297- probeModeMap = make (map [string ]model.Mode )
1294+ probeDetails []* model.GetProbesInExperimentRunResponse
12981295 )
12991296
13001297 wfRun , err := c .chaosExperimentRunOperator .GetExperimentRun (bson.D {
@@ -1310,10 +1307,16 @@ func (c *ChaosExperimentHandler) GetProbesInExperimentRun(ctx context.Context, p
13101307 if _probe .FaultName == faultName {
13111308 for _ , probeName := range _probe .ProbeNames {
13121309 var executionData types.ExecutionData
1313- probeStatusMap [probeName ] = model .ProbeVerdictNa
1314- probeModeMap [probeName ] = model .ModeSot
13151310 description := "Either probe is not executed or not evaluated"
1316- probeDescriptionMap [probeName ] = & description
1311+
1312+ probeVal := model.GetProbesInExperimentRunResponse {
1313+ Probe : & model.Probe {
1314+ Name : probeName ,
1315+ },
1316+ Status : & model.Status {
1317+ Description : & description ,
1318+ },
1319+ }
13171320
13181321 if err = json .Unmarshal ([]byte (wfRun .ExecutionData ), & executionData ); err != nil {
13191322 return nil , errors .New ("failed to unmarshal workflow manifest" )
@@ -1323,65 +1326,59 @@ func (c *ChaosExperimentHandler) GetProbesInExperimentRun(ctx context.Context, p
13231326 for _ , nodeData := range executionData .Nodes {
13241327 if nodeData .Name == faultName {
13251328 if nodeData .Type == "ChaosEngine" && nodeData .ChaosExp == nil {
1326- probeStatusMap [ probeName ] = model .ProbeVerdictNa
1329+ probeVal . Status . Verdict = model .ProbeVerdictNa
13271330 } else if nodeData .Type == "ChaosEngine" && nodeData .ChaosExp != nil {
1328- probeStatusMap [ probeName ] = model .ProbeVerdictNa
1331+ probeVal . Status . Verdict = model .ProbeVerdictNa
13291332 if nodeData .ChaosExp .ChaosResult != nil {
1330- probeStatusMap [ probeName ] = model .ProbeVerdictAwaited
1333+ probeVal . Status . Verdict = model .ProbeVerdictAwaited
13311334 probeStatuses := nodeData .ChaosExp .ChaosResult .Status .ProbeStatuses
13321335
13331336 for _ , probeStatus := range probeStatuses {
13341337 if probeStatus .Name == probeName {
1335- probeModeMap [probeName ] = model .Mode (probeStatus .Mode )
1336-
1337- description := probeStatus .Status .Description
1338- probeDescriptionMap [probeStatus .Name ] = & description
1339-
1340- switch probeStatus .Status .Verdict {
1341- case chaosTypes .ProbeVerdictPassed :
1342- probeStatusMap [probeName ] = model .ProbeVerdictPassed
1343- break
1344- case chaosTypes .ProbeVerdictFailed :
1345- probeStatusMap [probeName ] = model .ProbeVerdictFailed
1346- break
1347- case chaosTypes .ProbeVerdictAwaited :
1348- probeStatusMap [probeName ] = model .ProbeVerdictAwaited
1349- break
1350- default :
1351- probeStatusMap [probeName ] = model .ProbeVerdictNa
1352- break
1353- }
1338+ probeVal .Mode = model .Mode (probeStatus .Mode )
1339+
1340+ description = probeStatus .Status .Description
1341+ probeVal .Status .Description = & description
1342+ probeVal .Status .Verdict = convertProbeVerdict (probeStatus .Status .Verdict )
13541343 }
13551344 }
13561345 }
13571346 }
13581347 }
13591348 }
13601349 }
1350+ probeDetails = append (probeDetails , & probeVal )
13611351 }
1352+ }
1353+ }
13621354
1363- for _ , probeName := range _probe .ProbeNames {
1364- singleProbe , err := dbSchemaProbe .NewChaosProbeOperator (c .mongodbOperator ).GetProbeByName (ctx , probeName , projectID )
1365- if err != nil {
1366- return nil , err
1367- }
1368-
1369- probeDetails = append (probeDetails , & model.GetProbesInExperimentRunResponse {
1370- Probe : singleProbe .GetOutputProbe (),
1371- Mode : probeModeMap [probeName ],
1372- Status : & model.Status {
1373- Verdict : probeStatusMap [probeName ],
1374- Description : probeDescriptionMap [probeName ],
1375- },
1376- })
1377- }
1378-
1355+ for i , probeData := range probeDetails {
1356+ value := probeData
1357+ singleProbe , err := dbSchemaProbe .NewChaosProbeOperator (c .mongodbOperator ).GetProbeByName (ctx , value .Probe .Name , projectID )
1358+ if err != nil {
1359+ return nil , err
13791360 }
1361+
1362+ probeDetails [i ].Probe = singleProbe .GetOutputProbe ()
13801363 }
13811364
13821365 return probeDetails , nil
13831366}
13841367
1368+ // convertProbeVerdict maps chaosTypes verdicts to GraphQL model verdicts
1369+ func convertProbeVerdict (verdict chaosTypes.ProbeVerdict ) model.ProbeVerdict {
1370+ switch verdict {
1371+ case chaosTypes .ProbeVerdictPassed :
1372+ return model .ProbeVerdictPassed
1373+ case chaosTypes .ProbeVerdictFailed :
1374+ return model .ProbeVerdictFailed
1375+ case chaosTypes .ProbeVerdictAwaited :
1376+ return model .ProbeVerdictAwaited
1377+ default :
1378+ return model .ProbeVerdictNa
1379+ }
1380+ }
1381+
13851382// validateDuplicateExperimentName validates if the name of experiment is duplicate
13861383func (c * ChaosExperimentHandler ) validateDuplicateExperimentName (ctx context.Context , projectID , name string ) error {
13871384 filterQuery := bson.D {
0 commit comments