Skip to content

Commit e94c697

Browse files
authored
Merge pull request #50 from blink1073/INTPYTHON-309
INTPYTHON-309 & INTPYTHON-417 Use new cluster and schedule on interval
2 parents 57d9909 + c4ad06e commit e94c697

File tree

23 files changed

+412
-124
lines changed

23 files changed

+412
-124
lines changed

.evergreen/config.yml

Lines changed: 101 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ functions:
2828
params:
2929
directory: "src"
3030

31+
"fetch secrets":
32+
- command: subprocess.exec
33+
type: setup
34+
params:
35+
working_dir: "src"
36+
binary: bash
37+
args: [.evergreen/fetch-secrets.sh]
38+
3139
"fetch repo":
3240
- command: shell.exec
3341
type: setup
@@ -54,58 +62,116 @@ functions:
5462
add_expansions_to_env: true
5563
working_dir: "src/${DIR}/${REPO_NAME}"
5664
binary: bash
57-
env:
58-
atlas: ${workdir}/src/atlas/bin/atlas
5965
args:
6066
- ../run.sh
6167

62-
"setup atlas cli":
68+
"setup local atlas":
6369
- command: subprocess.exec
6470
type: setup
6571
retry_on_failure: true
6672
params:
6773
add_expansions_to_env: true
6874
working_dir: "src"
6975
binary: bash
70-
env:
71-
atlas: ${workdir}/src/atlas/bin/atlas
7276
args:
7377
- .evergreen/provision-atlas.sh
7478

79+
"setup remote atlas":
80+
- command: subprocess.exec
81+
type: setup
82+
params:
83+
add_expansions_to_env: true
84+
working_dir: "src"
85+
binary: bash
86+
args: [.evergreen/setup-remote.sh]
87+
7588
pre_error_fails_task: true
7689
pre:
7790
- func: "fetch source"
78-
- func: "setup atlas cli"
91+
- func: "fetch secrets"
7992

8093
tasks:
81-
- name: test-semantic-kernel-python
94+
- name: test-semantic-kernel-python-local
95+
tags: [local]
96+
commands:
97+
- func: "fetch repo"
98+
- func: "setup local atlas"
99+
- func: "execute tests"
100+
101+
- name: test-semantic-kernel-python-remote
102+
tags: [remote]
103+
commands:
104+
- func: "fetch repo"
105+
- func: "setup remote atlas"
106+
- func: "execute tests"
107+
108+
- name: test-semantic-kernel-csharp-local
109+
tags: [local]
110+
commands:
111+
- func: "fetch repo"
112+
- func: "setup local atlas"
113+
- func: "execute tests"
114+
115+
- name: test-semantic-kernel-csharp-remote
116+
tags: [remote]
117+
commands:
118+
- func: "fetch repo"
119+
- func: "setup remote atlas"
120+
- func: "execute tests"
121+
122+
- name: test-langchain-python-local
123+
tags: [local]
82124
commands:
83125
- func: "fetch repo"
126+
- func: "setup local atlas"
84127
- func: "execute tests"
85128

86-
- name: test-semantic-kernel-csharp
129+
- name: test-langchain-python-remote
130+
tags: [remote]
87131
commands:
88132
- func: "fetch repo"
133+
- func: "setup remote atlas"
89134
- func: "execute tests"
90135

91-
- name: test-langchain-python
136+
- name: test-chatgpt-retrieval-plugin-local
137+
tags: [local]
92138
commands:
93139
- func: "fetch repo"
140+
- func: "setup local atlas"
94141
- func: "execute tests"
95142

96-
- name: test-chatgpt-retrieval-plugin
143+
- name: test-chatgpt-retrieval-plugin-remote
144+
tags: [remote]
97145
commands:
98146
- func: "fetch repo"
147+
- func: "setup remote atlas"
99148
- func: "execute tests"
100149

101-
- name: test-llama-index
150+
- name: test-llama-index-local
151+
tags: [local]
102152
commands:
103153
- func: "fetch repo"
154+
- func: "setup local atlas"
104155
- func: "execute tests"
105156

106-
- name: test-docarray
157+
- name: test-llama-index-remote
107158
commands:
108159
- func: "fetch repo"
160+
- func: "setup remote atlas"
161+
- func: "execute tests"
162+
163+
- name: test-docarray-local
164+
tags: [local]
165+
commands:
166+
- func: "fetch repo"
167+
- func: "setup local atlas"
168+
- func: "execute tests"
169+
170+
- name: test-docarray-remote
171+
tags: [remote]
172+
commands:
173+
- func: "fetch repo"
174+
- func: "setup remote atlas"
109175
- func: "execute tests"
110176

111177
buildvariants:
@@ -121,7 +187,10 @@ buildvariants:
121187
run_on:
122188
- rhel87-small
123189
tasks:
124-
- name: test-llama-index
190+
- name: test-llama-index-local
191+
- name: test-llama-index-remote
192+
batchtime: 10080 # 1 week
193+
125194
- name: test-semantic-kernel-python-rhel
126195
display_name: Semantic-Kernel RHEL Python
127196
expansions:
@@ -132,7 +201,10 @@ buildvariants:
132201
run_on:
133202
- rhel87-small
134203
tasks:
135-
- name: test-semantic-kernel-python
204+
- name: test-semantic-kernel-python-local
205+
# TODO: INTPYTHON-430
206+
# - name: test-semantic-kernel-python-remote
207+
# batchtime: 10080 # 1 week
136208

137209
- name: test-semantic-kernel-csharp-rhel
138210
display_name: Semantic-Kernel RHEL CSharp
@@ -144,7 +216,9 @@ buildvariants:
144216
run_on:
145217
- rhel87-small
146218
tasks:
147-
- name: test-semantic-kernel-csharp
219+
- name: test-semantic-kernel-csharp-local
220+
- name: test-semantic-kernel-csharp-remote
221+
batchtime: 10080 # 1 week
148222

149223
- name: test-langchain-python-rhel
150224
display_name: Langchain RHEL Python
@@ -156,7 +230,9 @@ buildvariants:
156230
run_on:
157231
- rhel87-small
158232
tasks:
159-
- name: test-langchain-python
233+
- name: test-langchain-python-local
234+
- name: test-langchain-python-remote
235+
batchtime: 10080 # 1 week
160236

161237
- name: test-chatgpt-retrieval-plugin-rhel
162238
display_name: ChatGPT Retrieval Plugin
@@ -168,7 +244,9 @@ buildvariants:
168244
run_on:
169245
- rhel87-small
170246
tasks:
171-
- name: test-chatgpt-retrieval-plugin
247+
- name: test-chatgpt-retrieval-plugin-local
248+
- name: test-chatgpt-retrieval-plugin-remote
249+
batchtime: 10080 # 1 week
172250

173251
- name: test-llama-index-vectorstore-rhel
174252
display_name: LlamaIndex RHEL Vector Store
@@ -180,7 +258,10 @@ buildvariants:
180258
run_on:
181259
- rhel87-small
182260
tasks:
183-
- name: test-llama-index
261+
- name: test-llama-index-local
262+
# TODO: INTPYTHON-440
263+
# - name: test-llama-index-remote
264+
# batchtime: 10080 # 1 week
184265

185266
- name: test-docarray-rhel
186267
display_name: DocArray RHEL
@@ -192,4 +273,5 @@ buildvariants:
192273
run_on:
193274
- rhel87-small
194275
tasks:
195-
- name: test-docarray
276+
- name: test-docarray-local
277+
- name: test-docarray-remote

.evergreen/fetch-secrets.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
# Clone drivers-evergeen-tools.
6+
git clone https://github.com/mongodb-labs/drivers-evergreen-tools
7+
8+
# Get the secrets for drivers/ai-ml-pipeline-testing.
9+
. drivers-evergreen-tools/.evergreen/secrets_handling/setup-secrets.sh drivers/ai-ml-pipeline-testing

.evergreen/provision-atlas.sh

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
11
#!/bin/bash
2+
set -eu
23

34
. .evergreen/utils.sh
45

5-
PYTHON_BINARY=$(find_python3)
6-
7-
# Should be called from src
8-
EVERGREEN_PATH=$(pwd)/.evergreen
9-
TARGET_DIR=$(pwd)/$DIR
10-
SCAFFOLD_SCRIPT=$EVERGREEN_PATH/scaffold_atlas.py
11-
12-
set -ex
13-
mkdir atlas
14-
156
setup_local_atlas
7+
scaffold_atlas
168

17-
cd atlas
18-
19-
$PYTHON_BINARY -m venv .
20-
source ./bin/activate
21-
22-
# Test server is up
23-
$PYTHON_BINARY -m pip install pymongo
24-
CONN_STRING=$CONN_STRING \
25-
$PYTHON_BINARY -c "from pymongo import MongoClient; import os; MongoClient(os.environ['CONN_STRING']).db.command('ping')"
9+
# Get the secrets.
10+
source secrets-export.sh
2611

27-
# Add database and index configurations
28-
DATABASE=$DATABASE \
29-
CONN_STRING=$CONN_STRING \
30-
REPO_NAME=$REPO_NAME \
31-
DIR=$DIR \
32-
TARGET_DIR=$TARGET_DIR \
33-
$PYTHON_BINARY $SCAFFOLD_SCRIPT
12+
# Create the env file
13+
echo "export OPENAI_API_KEY=$OPENAI_API_KEY" >> env.sh
14+
echo "export MONGODB_URI=$CONN_STRING" >> env.sh

.evergreen/scaffold_atlas.py

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import logging
55
import os
66
from pathlib import Path
7-
from typing import Any, Union
7+
from time import sleep, monotonic
8+
from typing import Any, Callable, Union
89

910
from pymongo import MongoClient
1011
from pymongo.database import Database
@@ -13,7 +14,7 @@
1314

1415
logging.basicConfig()
1516
logger = logging.getLogger(__file__)
16-
logger.setLevel(logging.DEBUG if os.environ.get("DEBUG") else logging.INFO)
17+
logger.setLevel(logging.DEBUG)
1718

1819
DATABASE_NAME = os.environ.get("DATABASE")
1920
CONN_STRING = os.environ.get("CONN_STRING")
@@ -41,12 +42,17 @@ def upload_data(db: Database, filename: Path) -> None:
4142
db.name,
4243
collection_name,
4344
)
45+
collections = [c["name"] for c in db.list_collections()]
46+
if collection_name in collections:
47+
logger.debug("Clearing existing collection", collection_name)
48+
db[collection_name].delete_many({})
49+
4450
if not isinstance(loaded_collection, list):
4551
loaded_collection = [loaded_collection]
4652
if loaded_collection:
4753
result: InsertManyResult = db[collection_name].insert_many(loaded_collection)
4854
logger.debug("Uploaded results for %s: %s", filename.name, result.inserted_ids)
49-
else:
55+
elif collection_name not in collections:
5056
logger.debug("Empty collection named %s created", collection_name)
5157
db.create_collection(collection_name)
5258

@@ -66,12 +72,87 @@ def create_index(client: MongoClient, filename: Path) -> None:
6672
index_name = loaded_index_configuration.pop("name")
6773
index_type = loaded_index_configuration.pop("type", None)
6874

75+
logger.debug(
76+
"creating search index: %s on %s.%s...",
77+
index_name,
78+
database_name,
79+
collection_name,
80+
)
81+
6982
collection = client[database_name][collection_name]
7083

7184
search_index = SearchIndexModel(
7285
loaded_index_configuration, name=index_name, type=index_type
7386
)
74-
collection.create_search_index(search_index)
87+
indexes = [index["name"] for index in collection.list_search_indexes()]
88+
if index_name not in indexes:
89+
collection.create_search_index(search_index)
90+
91+
else:
92+
logger.debug(
93+
"search index already exists, updating: %s on %s.%s",
94+
index_name,
95+
database_name,
96+
collection_name,
97+
)
98+
collection.update_search_index(index_name, loaded_index_configuration)
99+
100+
logger.debug("waiting for search index to be ready...")
101+
wait_until_complete = 120
102+
_wait_for_predicate(
103+
predicate=lambda: _is_index_ready(collection, index_name),
104+
err=f"Index {index_name} update did not complete in {wait_until_complete}!",
105+
timeout=wait_until_complete,
106+
)
107+
logger.debug("waiting for search index to be ready... done.")
108+
109+
logger.debug(
110+
"creating search index: %s on %s.%s... done",
111+
index_name,
112+
database_name,
113+
collection_name,
114+
)
115+
116+
117+
def _is_index_ready(collection: Any, index_name: str) -> bool:
118+
"""Check for the index name in the list of available search indexes.
119+
120+
This confirms that the specified index is of status READY.
121+
122+
Args:
123+
collection (Collection): MongoDB Collection to for the search indexes
124+
index_name (str): Vector Search Index name
125+
126+
Returns:
127+
bool : True if the index is present and READY false otherwise
128+
"""
129+
search_indexes = collection.list_search_indexes(index_name)
130+
131+
for index in search_indexes:
132+
if index["status"] == "READY":
133+
return True
134+
return False
135+
136+
137+
def _wait_for_predicate(
138+
predicate: Callable, err: str, timeout: float = 120, interval: float = 0.5
139+
) -> None:
140+
"""Generic to block until the predicate returns true.
141+
142+
Args:
143+
predicate (Callable[, bool]): A function that returns a boolean value
144+
err (str): Error message to raise if nothing occurs
145+
timeout (float, optional): Wait time for predicate. Defaults to TIMEOUT.
146+
interval (float, optional): Interval to check predicate. Defaults to DELAY.
147+
148+
Raises:
149+
TimeoutError: _description_
150+
"""
151+
start = monotonic()
152+
while not predicate():
153+
if monotonic() - start > timeout:
154+
raise TimeoutError(err)
155+
sleep(interval)
75156

76157

77158
def walk_directory(filepath) -> list[str]:

0 commit comments

Comments
 (0)