Skip to content

Commit

Permalink
Fix logging and exception messages
Browse files Browse the repository at this point in the history
Signed-off-by: Megha Goyal <[email protected]>
  • Loading branch information
goyamegh committed Mar 8, 2024
1 parent 998c075 commit 87cf6ca
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.opensearch.securityanalytics.transport.TransportCorrelateFindingAction;
import org.opensearch.securityanalytics.util.CorrelationIndices;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -197,10 +198,8 @@ public void insertCorrelatedFindings(String detectorType, Finding finding, Strin

public void insertOrphanFindings(String detectorType, Finding finding, float timestampFeature, Map<String, CustomLogType> logTypes) {
if (logTypes.get(detectorType) == null ) {
log.debug("[PERF-DEBUG] insertOrphanFindings detector type {} {}", detectorType, finding.getId());
for (String key : logTypes.keySet()) {
log.debug("[PERF-DEBUG] keys {}", key);
}
log.debug("Missing detector type {} in the log types index for finding id {}. Keys in the index: {}",
detectorType, finding.getId(), Arrays.toString(logTypes.keySet().toArray()));
onFailure(new OpenSearchStatusException("insertOrphanFindings null log types for detector type: " + detectorType, RestStatus.INTERNAL_SERVER_ERROR));
}

Expand Down Expand Up @@ -260,7 +259,8 @@ public void insertOrphanFindings(String detectorType, Finding finding, float tim
onFailure(ex);
}
} else {
onFailure(new OpenSearchStatusException(indexResponse.toString(), RestStatus.INTERNAL_SERVER_ERROR));
onFailure(new OpenSearchStatusException("Indexing failed with response {} ",
indexResponse.status(), indexResponse.toString()));
}
}, this::onFailure));
} else {
Expand Down Expand Up @@ -306,7 +306,8 @@ public void insertOrphanFindings(String detectorType, Finding finding, float tim
onFailure(ex);
}
} else {
onFailure(new OpenSearchStatusException(indexResponse.toString(), RestStatus.INTERNAL_SERVER_ERROR));
onFailure(new OpenSearchStatusException("Indexing failed with response {} ",
indexResponse.status(), indexResponse.toString()));
}
}, this::onFailure));
} else {
Expand Down Expand Up @@ -418,7 +419,8 @@ public void insertOrphanFindings(String detectorType, Finding finding, float tim
onFailure(ex);
}
} else {
onFailure(new OpenSearchStatusException("Indexing failed", RestStatus.INTERNAL_SERVER_ERROR));
onFailure(new OpenSearchStatusException("Indexing failed with response {} ",
indexResponse.status(), indexResponse.toString()));
}
}, this::onFailure));
} catch (Exception ex) {
Expand All @@ -444,7 +446,7 @@ private void indexCorrelatedFindings(XContentBuilder builder) {
if (response.status().equals(RestStatus.CREATED)) {
correlateFindingAction.onOperation();
} else {
onFailure(new OpenSearchStatusException(response.toString(), RestStatus.INTERNAL_SERVER_ERROR));
onFailure(new OpenSearchStatusException("Indexing failed with response {} ", response.status(), response.toString()));
}
}, this::onFailure));
}
Expand Down

0 comments on commit 87cf6ca

Please sign in to comment.