This repository has been archived by the owner on Nov 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup indexes in case of failure (#232)
* Cleanup indexes in case of failure * Remove shell bash * Move to script * Fix * Fix env * Poetry run * Fix * Try fix * Try * Fix * Update secrets * Test * Fix * Fail system test * Improve logging * Fix lint
- Loading branch information
Showing
6 changed files
with
98 additions
and
23 deletions.
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
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
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,23 @@ | ||
import logging | ||
import sys | ||
from tests.util import cleanup_indexes | ||
|
||
|
||
def main(): | ||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
if len(sys.argv) != 2: | ||
logger.info("Usage: python scripts/cleanup_indexes.py <testrun_uid>") | ||
sys.exit(1) | ||
|
||
testrun_uid = sys.argv[1] | ||
if testrun_uid: | ||
logger.info(f"Cleaning up indexes for testrun_uid '{testrun_uid}'") | ||
cleanup_indexes(testrun_uid) | ||
else: | ||
logger.info("testrun_uid is not passed, index cleanup will not be run.") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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
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
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,35 @@ | ||
import logging | ||
from datetime import datetime | ||
|
||
import pinecone | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def create_index_name(testrun_uid: str, prefix: str) -> str: | ||
today = datetime.today().strftime("%Y-%m-%d") | ||
return f"{prefix}-{testrun_uid[-6:]}-{today}" | ||
|
||
|
||
def create_system_tests_index_name(testrun_uid: str) -> str: | ||
return create_index_name(testrun_uid, "test-kb") | ||
|
||
|
||
def create_e2e_tests_index_name(testrun_uid: str) -> str: | ||
return create_index_name(testrun_uid, "test-app") | ||
|
||
|
||
def cleanup_indexes(testrun_uid: str): | ||
pinecone.init() | ||
e2e_index_name = create_e2e_tests_index_name(testrun_uid) | ||
system_index_name = create_system_tests_index_name(testrun_uid) | ||
index_names = (system_index_name, e2e_index_name) | ||
logger.info(f"Preparing to cleanup indexes: {index_names}") | ||
current_indexes = pinecone.list_indexes() | ||
for index_name in index_names: | ||
if index_name in current_indexes: | ||
logger.info(f"Deleting index '{index_name}'...") | ||
pinecone.delete_index(index_name) | ||
logger.info(f"Index '{index_name}' deleted.") | ||
else: | ||
logger.info(f"Index '{index_name}' does not exist.") |