-
Notifications
You must be signed in to change notification settings - Fork 0
TIMX 611 - AOSS support #383
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7ac20f1
Update dependencies
ghukill 3a56631
Support serverless Opensearch (AOSS) operations
ghukill 7ab6773
Prevent sentry init leak
ghukill 1aed60c
Add and fix tests for AOSS support
ghukill f240a35
Raise exception for invalid opensearch auth type
ghukill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| # ruff: noqa: TRY003, EM101 | ||
| import json | ||
| import logging | ||
| from datetime import timedelta | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -47,7 +47,21 @@ def configure_opensearch_client(url: str) -> OpenSearch: | |
|
|
||
| credentials = boto3.Session().get_credentials() | ||
| region = os.getenv("AWS_REGION", "us-east-1") | ||
| auth = AWSV4SignerAuth(credentials, region) | ||
|
|
||
| auth_service_type = os.getenv("AUTH_SERVICE_TYPE", "es") | ||
| valid_auth_service_types = {"aoss", "es"} | ||
|
|
||
| if auth_service_type not in valid_auth_service_types: | ||
| raise ValueError( | ||
| f"AUTH_SERVICE_TYPE must be one of {sorted(valid_auth_service_types)}, " | ||
| f"got {auth_service_type!r}" | ||
| ) | ||
|
|
||
| auth = AWSV4SignerAuth( | ||
| credentials, | ||
| region, | ||
| service=auth_service_type, | ||
| ) | ||
| return OpenSearch( | ||
| hosts=[{"host": url, "port": "443"}], | ||
| http_auth=auth, | ||
|
|
@@ -123,8 +137,6 @@ def get_formatted_indexes(client: OpenSearch) -> str: | |
| f" Primary store size: {info['pri.store.size']}\n" | ||
| f" Total store size: {info['store.size']}\n" | ||
| f" UUID: {info['uuid']}\n" | ||
| f" Primary Shards: {int(info['pri']):,}\n" | ||
| f" Replica Shards: {int(info['rep']):,}\n" | ||
| ) | ||
| return output | ||
| return output + " No indexes present in OpenSearch cluster." | ||
|
|
@@ -328,6 +340,9 @@ def bulk_delete( | |
| responses = streaming_bulk( | ||
| client, | ||
| actions, | ||
| chunk_size=REQUEST_CONFIG["OPENSEARCH_BULK_CHUNK_SIZE"], | ||
| max_retries=REQUEST_CONFIG["OPENSEARCH_BULK_MAX_RETRIES"], | ||
| initial_backoff=3, | ||
| max_chunk_bytes=REQUEST_CONFIG["OPENSEARCH_BULK_MAX_CHUNK_BYTES"], | ||
| raise_on_error=False, | ||
| ) | ||
|
|
@@ -351,11 +366,6 @@ def bulk_delete( | |
| result["total"] += 1 | ||
| if result["total"] % int(os.getenv("STATUS_UPDATE_INTERVAL", "1000")) == 0: | ||
| logger.info("Status update: %s records deleted so far!", result["total"]) | ||
| logger.info("Refreshing index.") | ||
| response = client.indices.refresh( | ||
| index=index, | ||
| ) | ||
| logger.debug(response) | ||
|
Comment on lines
-354
to
-358
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commenting here, but true on all bulk operations... We no longer have to "refresh" indexes. In fact, you can't anymore! It was not strictly required before, as indexes are refreshed organically by Opensearch. So we're still fine until the full switchover to AOSS. |
||
| return result | ||
|
|
||
|
|
||
|
|
@@ -382,6 +392,8 @@ def bulk_index(client: OpenSearch, index: str, records: Iterator[dict]) -> dict[ | |
| responses = streaming_bulk( | ||
| client, | ||
| actions, | ||
| chunk_size=REQUEST_CONFIG["OPENSEARCH_BULK_CHUNK_SIZE"], | ||
| max_retries=REQUEST_CONFIG["OPENSEARCH_BULK_MAX_RETRIES"], | ||
| max_chunk_bytes=REQUEST_CONFIG["OPENSEARCH_BULK_MAX_CHUNK_BYTES"], | ||
| raise_on_error=False, | ||
| ) | ||
|
|
@@ -411,11 +423,6 @@ def bulk_index(client: OpenSearch, index: str, records: Iterator[dict]) -> dict[ | |
| result["total"] += 1 | ||
| if result["total"] % int(os.getenv("STATUS_UPDATE_INTERVAL", "1000")) == 0: | ||
| logger.info("Status update: %s records indexed so far!", result["total"]) | ||
| logger.info("Refreshing index.") | ||
| response = client.indices.refresh( | ||
| index=index, | ||
| ) | ||
| logger.debug(response) | ||
| return result | ||
|
|
||
|
|
||
|
|
@@ -437,6 +444,8 @@ def bulk_update( | |
| responses = streaming_bulk( | ||
| client, | ||
| actions, | ||
| chunk_size=REQUEST_CONFIG["OPENSEARCH_BULK_CHUNK_SIZE"], | ||
| max_retries=REQUEST_CONFIG["OPENSEARCH_BULK_MAX_RETRIES"], | ||
| max_chunk_bytes=REQUEST_CONFIG["OPENSEARCH_BULK_MAX_CHUNK_BYTES"], | ||
| raise_on_error=False, | ||
| ) | ||
|
|
@@ -475,9 +484,4 @@ def bulk_update( | |
| result["total"] += 1 | ||
| if result["total"] % int(os.getenv("STATUS_UPDATE_INTERVAL", "1000")) == 0: | ||
| logger.info("Status update: %s records updated so far!", result["total"]) | ||
| logger.info("Refreshing index.") | ||
| response = client.indices.refresh( | ||
| index=index, | ||
| ) | ||
| logger.debug(response) | ||
| return result | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this what you were referring to last week re: logging?
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.
Nice catch! Interestingly, yes, but kind of indirectly...
Because we were technically leaving a Sentry initialization present -- which this change fixes -- it was the duplicating logging handlers that eventually revealed this issue during test suite. The Sentry bug was likely present before, but the logging handler duplication finally bubbled it up to the point where it was intermittently failing tests.
So, this change fixes the Sentry bug, and therefore the duplicating logging handlers don't cause test failiures. But it does not address the underlying logging handler duplication for test suites.