-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
print errors on console for execute-test
Signed-off-by: Chinmay Gadgil <[email protected]> added erros file for common opensearch errors during execute-test Signed-off-by: Chinmay Gadgil <[email protected]> make errors less verbose Signed-off-by: Chinmay Gadgil <[email protected]>
- Loading branch information
Showing
2 changed files
with
73 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import re | ||
|
||
def parse_error(error_metadata): | ||
error = error_metadata['error'] | ||
status_code = None | ||
description = "error occured, check logs for details" | ||
|
||
if 'status' in error_metadata: | ||
status_code = error_metadata["status"] | ||
|
||
if 'reason' in error: | ||
description = error['reason'] | ||
matches = re.findall(r'\[([^]]*)\]', description) | ||
for match in matches: | ||
if match == "indices:admin/create": | ||
return IndexOperationError(description, "index-create", status_code) | ||
elif match == "indices:admin/delete": | ||
return IndexOperationError(description, "index-delete", status_code) | ||
elif match == "indices:data/write/bulk": | ||
return IndexOperationError(description, "index-append", status_code) | ||
elif match == "indices:admin/refresh": | ||
return IndexOperationError(description, "refresh-after-index", status_code) | ||
elif match == "indices:admin/forcemerge": | ||
return IndexOperationError(description, "force-merge", status_code) | ||
elif match == "indices:data/read/search": | ||
return SearchOperationError(description, "search", status_code) | ||
|
||
return UnknownOperationError(description, None) | ||
|
||
|
||
class OpenSearchOperationError(): | ||
def __init__(self, description, operation=None, status_code=None): | ||
self.description = description | ||
self.operation = operation | ||
self.status_code = status_code | ||
|
||
class UnknownOperationError(OpenSearchOperationError): | ||
def get_error_message(self): | ||
return self.description | ||
|
||
|
||
class IndexOperationError(OpenSearchOperationError): | ||
def get_error_message(self): | ||
if self.status_code == 403: | ||
return f"permission denied for {self.operation}. check logs for details" | ||
elif self.status_code == 500: | ||
return f"internal server error for {self.operation}. check logs for details" | ||
else: | ||
return self.description | ||
|
||
class SearchOperationError(OpenSearchOperationError): | ||
def get_error_message(self): | ||
if self.status_code == 403: | ||
return f"permission denied for {self.operation}. check logs for details" | ||
elif self.status_code == 500: | ||
return f"internal server error for {self.operation} index. check logs for details" | ||
else: | ||
return self.description |
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