-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change in findingsAPI call to accommodate backend findings enhancement #859
change in findingsAPI call to accommodate backend findings enhancement #859
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #859 +/- ##
==========================================
- Coverage 31.03% 30.96% -0.07%
==========================================
Files 151 151
Lines 5111 5119 +8
Branches 948 896 -52
==========================================
- Hits 1586 1585 -1
- Misses 3335 3344 +9
Partials 190 190 ☔ View full report in Codecov by Sentry. |
detector: detector, | ||
}); | ||
}); | ||
const detectorFindingsPromises = findingRes.response.findings.map(async (finding) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be async
? On line 161, we await
the response of the getFindings
API call, so I don't believe we'll be dealing with promises here (correct me if I'm missing something though).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes right, it does not necessarily need to be async because we're working with the result of an already awaited API call (findingsService.getFindings()).
detectorName: detectorInfo ? detectorInfo.name : 'Unknown', | ||
logType: detectorInfo ? detectorInfo.logType : 'Unknown', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Would it make sense to use the DEFAULT_EMPTY_DATA
constant (link) here instead of Unknown
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do you happen to know if there are instances when we'd expect the logType
or detectorName
to be undefined for a finding? If not, I'm wondering if it would be worthwhile to add a log of some kind here as that seems like it might be an odd anomaly.
} | ||
}); | ||
|
||
const detectorFindings = await Promise.all(detectorFindingsPromises); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the question I had on line 180, are we sure these are promises? I believe we're already await
ing the response from the API calls on lines 161 and 168, but I may have missed something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the await keyword is required in this context. The Promise.all function returns a single promise that resolves to an array of the fulfilled values of the input promises (or rejects with the reason of the first promise that rejects, if any). In order to wait for all the promises inside detectorFindingsPromises to resolve before moving on to the next line of code, we are using await with Promise.all.
@@ -252,7 +264,7 @@ class Findings extends Component<FindingsProps, FindingsState> { | |||
generateVisualizationSpec() { | |||
const visData: FindingVisualizationData[] = []; | |||
|
|||
this.state.filteredFindings.forEach((finding: FindingItemType) => { | |||
this.state.filteredFindings.forEach((finding: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the FindingItemType
no longer align with the schema for the findings that are returned? If so, would it be possible to update the FindingItemType
to accommodate the new structure, or perhaps make a new type? Using type any
can make understanding the code a little harder.
public/services/FindingsService.ts
Outdated
): Promise<ServerResponse<GetFindingsResponse>> => { | ||
const { detectorType, detectorId } = detectorParams; | ||
const { detectorType, detectorId } = detectorParams || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Rather than declaring detectorParams
as a nullable parameter, I believe you could just refactor line 19 to detectorParams: GetFindingsParams = {}
to provide a default value when the parameter is null. This would then eliminate the need for the || {}
at the end of line 21.
Signed-off-by: Riya Saxena <[email protected]>
ee40f67
to
265c6fe
Compare
@riysaxen-amzn I don't see any change that increases the count of findings being fetched to 100000. Also, isn't there a new |
detector: detector, | ||
}); | ||
}); | ||
const detectorFindingsPromises = findingRes.response.findings.map((finding) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not returning promises in the map function, so we don't need to use Promises.all below
findings = findings.concat(detectorFindings.filter(Boolean)); | ||
// Set the state after all asynchronous operations are completed | ||
await this.getRules(Array.from(ruleIds)); | ||
this.setState({ findings }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were setting detector's state as well previously, I think we missed it here
detectorInfoMap.set(detector._id, { | ||
logType: detector._source.detector_type, | ||
name: detector._source.name, | ||
detector: detector, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified to just detector
// Use detectorInfoMap to get detector information | ||
const detectorInfo = detectorInfoMap.get(finding.detectorId); | ||
finding.queries.forEach((rule) => ruleIds.add(rule.id)); | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's simplify this to set the detector related info before the return so we have a single check for detectorInfo
const detectorData = detectorInfo ? {
detectorName: detectorInfo.name
...
} : {
detectorName: DEFAULT....
}
Description
Issues Resolved
opensearch-project/security-analytics#795
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.