-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG] Finding's fly-out has no correlations if open from alerts (#558)
* [BUG] Finding's fly-out has no correlations if open from alerts #557 Signed-off-by: Jovan Cvetkovic <[email protected]> * code review from #558 (comment) Signed-off-by: Jovan Cvetkovic <[email protected]> * cypress tests wait interval updated to 400 Signed-off-by: Jovan Cvetkovic <[email protected]> * cypress tests wait interval updated to 400 Signed-off-by: Jovan Cvetkovic <[email protected]> --------- Signed-off-by: Jovan Cvetkovic <[email protected]>
- Loading branch information
1 parent
3d95270
commit 28edd8e
Showing
13 changed files
with
156 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { DetectorsService, FindingsService } from '../services'; | ||
import { NotificationsStart } from 'opensearch-dashboards/public'; | ||
import { RouteComponentProps } from 'react-router-dom'; | ||
import { errorNotificationToast } from '../utils/helpers'; | ||
import { FindingItemType } from '../pages/Findings/containers/Findings/Findings'; | ||
|
||
export interface IFindingsStore { | ||
readonly service: FindingsService; | ||
|
||
readonly detectorsService: DetectorsService; | ||
|
||
readonly notifications: NotificationsStart; | ||
|
||
getFindingsPerDetector: (detectorId: string) => Promise<FindingItemType[]>; | ||
|
||
getAllFindings: () => Promise<FindingItemType[]>; | ||
} | ||
|
||
export interface IFindingsCache {} | ||
|
||
/** | ||
* Findings store | ||
* | ||
* @class FindingsStore | ||
* @implements IDetectorsStore | ||
* @param {BrowserServices} services Uses services to make API requests | ||
*/ | ||
export class FindingsStore implements IFindingsStore { | ||
/** | ||
* Findings service instance | ||
* | ||
* @property {FindingsService} service | ||
* @readonly | ||
*/ | ||
readonly service: FindingsService; | ||
|
||
/** | ||
* Detectors service instance | ||
* | ||
* @property {DetectorsService} detectorsService | ||
* @readonly | ||
*/ | ||
readonly detectorsService: DetectorsService; | ||
|
||
/** | ||
* Notifications | ||
* @property {NotificationsStart} | ||
* @readonly | ||
*/ | ||
readonly notifications: NotificationsStart; | ||
|
||
/** | ||
* Router history | ||
* @property {RouteComponentProps['history']} | ||
* @readonly | ||
*/ | ||
history: RouteComponentProps['history'] | undefined = undefined; | ||
|
||
constructor( | ||
service: FindingsService, | ||
detectorsService: DetectorsService, | ||
notifications: NotificationsStart | ||
) { | ||
this.service = service; | ||
this.detectorsService = detectorsService; | ||
this.notifications = notifications; | ||
} | ||
|
||
public getFindingsPerDetector = async (detectorId: string): Promise<FindingItemType[]> => { | ||
let allFindings: FindingItemType[] = []; | ||
const findingRes = await this.service.getFindings({ detectorId }); | ||
if (findingRes.ok) { | ||
allFindings = findingRes.response.findings as FindingItemType[]; | ||
} else { | ||
errorNotificationToast(this.notifications, 'retrieve', 'findings', findingRes.error); | ||
} | ||
|
||
return allFindings; | ||
}; | ||
|
||
public getAllFindings = async (): Promise<FindingItemType[]> => { | ||
let allFindings: FindingItemType[] = []; | ||
const detectorsRes = await this.detectorsService.getDetectors(); | ||
if (detectorsRes.ok) { | ||
const detectors = detectorsRes.response.hits.hits; | ||
|
||
for (let detector of detectors) { | ||
const findings = await this.getFindingsPerDetector(detector._id); | ||
const findingsPerDetector: FindingItemType[] = findings.map((finding) => { | ||
return { | ||
...finding, | ||
detectorName: detector._source.name, | ||
logType: detector._source.detector_type, | ||
detector: detector, | ||
}; | ||
}); | ||
allFindings = allFindings.concat(findingsPerDetector); | ||
} | ||
} | ||
|
||
return allFindings; | ||
}; | ||
} |