create sap error history index#859
create sap error history index#859riysaxen-amzn wants to merge 1 commit intoopensearch-project:mainfrom
Conversation
a2a430b to
fcc53be
Compare
| } | ||
| } | ||
|
|
||
| private void createSAPHistoryIndex(IndexDetectorRequest request, String exception) throws IOException { |
There was a problem hiding this comment.
plz move this logic to separate class. you can chekc rule indices handling for reference
| try { | ||
| createSAPHistoryIndex(request, t.toString()); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); |
There was a problem hiding this comment.
- plz dont ever throw runtime exceptions.
- no need to throw exception at all here imo since this is not a customer facing feature.
- plz add error log for failure and continue execution
| builder.field("user", user); | ||
| builder.endObject(); | ||
| log.info("Index name is: {}", indexName); | ||
| IndexRequest indexRequest = new IndexRequest(indexName) |
There was a problem hiding this comment.
this method is not even creating an index. plz rename method correcty.
eirsep
left a comment
There was a problem hiding this comment.
- plz add mapping for system index.
- maintain separate class for system index management. use the right index settings at creation time by referring other system indices' behaviour
So, the idea was to create this index whenever we encounter any failure and then upserting it with failure docs. Since this will be an Ops feature, i don't see the utility of creating this index at the beginning. But I see the point since this is a system index it not intended for direct access or modification. So, having a proper system index management for this make sense. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #859 +/- ##
============================================
- Coverage 24.83% 24.75% -0.08%
Complexity 1030 1030
============================================
Files 277 277
Lines 12713 12754 +41
Branches 1401 1404 +3
============================================
Hits 3157 3157
- Misses 9292 9333 +41
Partials 264 264 ☔ View full report in Codecov by Sentry. |
45e8bd4 to
d0c9e3d
Compare
Signed-off-by: Riya Saxena <riysaxen@amazon.com>
d0c9e3d to
844c2f9
Compare
…-project#859) Signed-off-by: Ashish Agrawal <ashisagr@amazon.com> (cherry picked from commit fcdcdcbf13a6df32693fb7b063c2819c6a80f85e) Co-authored-by: Ashish Agrawal <ashisagr@amazon.com>
| import org.opensearch.securityanalytics.util.RuleTopicIndices; | ||
| import org.opensearch.securityanalytics.util.SecurityAnalyticsException; | ||
| import org.opensearch.securityanalytics.util.WorkflowService; | ||
| import org.opensearch.securityanalytics.util.*; |
There was a problem hiding this comment.
Nit: we should avoid wildcard imports
| } | ||
|
|
||
| private void onFailures(Exception t) { | ||
| log.info("Exception failures while creating detector: {}", t.toString()); |
There was a problem hiding this comment.
Let's log this as error level. Same comment for 1529. We can then avoid the t.toString() with just
log.error("Exception failures while creating detector", t);
|
|
||
| private void initErrorHistoryIndexAndAddErrors(IndexDetectorRequest request, String exceptionMessage) throws IOException { | ||
|
|
||
| if (!errorHistoryIndex.errorHistoryIndexExists()) { |
There was a problem hiding this comment.
Take it or leave it - negating conditions is a bit harder to read than testing for the non-negated condition first. In a case like this where the method is an 'either or', I find it's easiest to read as
private void method() {
if (condition) {
// logic
return;
}
// logic for !condition
}
| } | ||
| @Override | ||
| public void onFailure(Exception ex) { | ||
| log.debug("Exception while creating error history index: {}", ex); |
| } | ||
| @Override | ||
| public void onFailure(Exception ex) { | ||
| log.info("Exception while inserting a document in error history index: {}", ex); |
| } | ||
| @Override | ||
| public void onFailure(Exception e) { | ||
| log.debug("Exception while creating error history index: {}", e); |
| @Override | ||
| public void onResponse(CreateIndexResponse response) { | ||
| errorHistoryIndex.onCreateMappingsResponse(response); | ||
| try { |
There was a problem hiding this comment.
Style nit: the pattern of nesting these action listeners is tough to read imo. This is far from the most flagrant use of it in the codebase but I would still advocate for a private method to handle the try/catch and inner logic. In this case it would also reduce duplication with the else condition below
| builder.field("user", user); | ||
| builder.endObject(); | ||
| IndexRequest indexRequest = new IndexRequest(indexName) | ||
| .id(UUIDs.base64UUID()) |
There was a problem hiding this comment.
Can we let OpenSearch generate the ID rather than creating a UUID?
Description
.opensearch-sap-error-historyIssues Resolved
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.