Skip to content

Commit cc4ab8d

Browse files
authored
[TRTLLM-8825][feat] Support Pytest Perf Results uploading to Database (#8653)
Signed-off-by: Chenfei Zhang <[email protected]>
1 parent 2ff772e commit cc4ab8d

File tree

10 files changed

+708
-41
lines changed

10 files changed

+708
-41
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ common-files: &common_files |
901901
tests/integration/defs/perf/diff_tools.py |
902902
tests/integration/defs/perf/gpu_clock_lock.py |
903903
tests/integration/defs/perf/misc.py |
904+
tests/integration/defs/perf/open_search_db_utils.py |
904905
tests/integration/defs/perf/pytorch_model_config.py |
905906
tests/integration/defs/perf/sample_options_config.py |
906907
tests/integration/defs/perf/sampler_options_config.py |

jenkins/scripts/open_search_db.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,15 @@ def typeCheckForOpenSearchDB(json_data) -> bool:
9696
OpenSearchDB.typeCheckForOpenSearchDB(item)
9797
for item in json_data)
9898
if not isinstance(json_data, dict):
99-
OpenSearchDB.logger.error(
99+
OpenSearchDB.logger.info(
100100
f"OpenSearchDB type check failed! Expected dict, got {type(json_data).__name__}"
101101
)
102102
return False
103103

104-
allowed_keys = {"_id", "_project", "_shard", "_version"}
104+
allowed_keys = {
105+
"@timestamp", "_id", "_index", "_score", "_type", "_project",
106+
"_shard", "_version"
107+
}
105108
type_map = {
106109
"l_": int,
107110
"d_": float,
@@ -117,15 +120,15 @@ def typeCheckForOpenSearchDB(json_data) -> bool:
117120
for prefix, expected_type in type_map.items():
118121
if key.startswith(prefix):
119122
if not isinstance(value, expected_type):
120-
OpenSearchDB.logger.error(
123+
OpenSearchDB.logger.info(
121124
f"OpenSearchDB type check failed! key:{key}, value:{value} value_type:{type(value)}"
122125
)
123126
return False
124127
matched = True
125128
break
126129
if not matched:
127130
if key not in allowed_keys:
128-
OpenSearchDB.logger.error(
131+
OpenSearchDB.logger.info(
129132
f"Unknown key type! key:{key}, value_type:{type(value)}"
130133
)
131134
return False
@@ -168,24 +171,25 @@ def postToOpenSearchDB(json_data, project) -> bool:
168171
:param project: Name of the project.
169172
:return: bool, True if post successful, False otherwise.
170173
"""
174+
use_poc_db = "sandbox" in project
171175
if not OPEN_SEARCH_DB_BASE_URL:
172-
OpenSearchDB.logger.error("OPEN_SEARCH_DB_BASE_URL is not set")
176+
OpenSearchDB.logger.info("OPEN_SEARCH_DB_BASE_URL is not set")
173177
return False
174-
if not OPEN_SEARCH_DB_USERNAME or not OPEN_SEARCH_DB_PASSWORD:
175-
OpenSearchDB.logger.error(
178+
if not use_poc_db and (not OPEN_SEARCH_DB_USERNAME
179+
or not OPEN_SEARCH_DB_PASSWORD):
180+
OpenSearchDB.logger.info(
176181
"OPEN_SEARCH_DB_USERNAME or OPEN_SEARCH_DB_PASSWORD is not set")
177182
return False
178-
if project not in WRITE_ACCESS_PROJECT_NAME:
179-
OpenSearchDB.logger.error(
183+
if not use_poc_db and project not in WRITE_ACCESS_PROJECT_NAME:
184+
OpenSearchDB.logger.info(
180185
f"project {project} is not in write access project list: {json.dumps(WRITE_ACCESS_PROJECT_NAME)}"
181186
)
182187
return False
183188
if not OpenSearchDB.typeCheckForOpenSearchDB(json_data):
184-
OpenSearchDB.logger.error(
189+
OpenSearchDB.logger.info(
185190
f"OpenSearchDB type check failed! json_data:{json_data}")
186191
return False
187192

188-
OpenSearchDB.add_id_of_json(json_data)
189193
json_data_dump = json.dumps(json_data)
190194

191195
if DISABLE_OPEN_SEARCH_DB_FOR_LOCAL_TEST:
@@ -202,14 +206,16 @@ def postToOpenSearchDB(json_data, project) -> bool:
202206

203207
for attempt in range(DEFAULT_RETRY_COUNT):
204208
try:
205-
res = requests.post(
206-
url,
207-
data=json_data_dump,
208-
headers=headers,
209-
auth=HTTPProxyAuth(OPEN_SEARCH_DB_USERNAME,
210-
OPEN_SEARCH_DB_PASSWORD),
211-
timeout=POST_TIMEOUT_SECONDS,
212-
)
209+
args = {
210+
"url": url,
211+
"data": json_data_dump,
212+
"headers": headers,
213+
"timeout": POST_TIMEOUT_SECONDS,
214+
}
215+
if not use_poc_db:
216+
args["auth"] = HTTPProxyAuth(OPEN_SEARCH_DB_USERNAME,
217+
OPEN_SEARCH_DB_PASSWORD)
218+
res = requests.post(**args)
213219
if res.status_code in (200, 201, 202):
214220
if res.status_code != 200 and project == JOB_PROJECT_NAME:
215221
OpenSearchDB.logger.info(
@@ -224,7 +230,7 @@ def postToOpenSearchDB(json_data, project) -> bool:
224230
OpenSearchDB.logger.info(
225231
f"OpenSearchDB post exception, attempt {attempt + 1} error: {e}"
226232
)
227-
OpenSearchDB.logger.error(
233+
OpenSearchDB.logger.info(
228234
f"Fail to postToOpenSearchDB after {DEFAULT_RETRY_COUNT} tries: {url}, json: {json_data_dump}, last error: {getattr(res, 'text', 'N/A') if 'res' in locals() else ''}"
229235
)
230236
return False
@@ -238,14 +244,15 @@ def queryFromOpenSearchDB(json_data, project) -> dict:
238244
:param project: Name of the project.
239245
:return: dict, query result.
240246
"""
247+
use_poc_db = "sandbox" in project
241248
if not OPEN_SEARCH_DB_BASE_URL:
242-
OpenSearchDB.logger.error("OPEN_SEARCH_DB_BASE_URL is not set")
243-
return {}
244-
if project not in READ_ACCESS_PROJECT_NAME:
245-
OpenSearchDB.logger.error(
249+
OpenSearchDB.logger.info("OPEN_SEARCH_DB_BASE_URL is not set")
250+
return None
251+
if not use_poc_db and project not in READ_ACCESS_PROJECT_NAME:
252+
OpenSearchDB.logger.info(
246253
f"project {project} is not in read access project list: {json.dumps(READ_ACCESS_PROJECT_NAME)}"
247254
)
248-
return {}
255+
return None
249256
if not isinstance(json_data, str):
250257
json_data_dump = json.dumps(json_data)
251258
else:
@@ -262,15 +269,15 @@ def queryFromOpenSearchDB(json_data, project) -> dict:
262269
headers=headers,
263270
timeout=QUERY_TIMEOUT_SECONDS)
264271
if res.status_code in [200, 201, 202]:
265-
return res.json()
272+
return res
266273
OpenSearchDB.logger.info(
267274
f"OpenSearchDB query failed, will retry, error:{res.status_code} {res.text}"
268275
)
269276
retry_time -= 1
270-
OpenSearchDB.logger.error(
277+
OpenSearchDB.logger.info(
271278
f"Fail to queryFromOpenSearchDB after {retry_time} retry: {url}, json: {json_data_dump}, error: {res.text}"
272279
)
273-
return {}
280+
return None
274281

275282
@staticmethod
276283
def queryBuildIdFromOpenSearchDB(job_name, last_days=DEFAULT_LOOKBACK_DAYS):
@@ -293,6 +300,9 @@ def queryBuildIdFromOpenSearchDB(job_name, last_days=DEFAULT_LOOKBACK_DAYS):
293300
try:
294301
query_res = OpenSearchDB.queryFromOpenSearchDB(
295302
json_data, JOB_PROJECT_NAME)
303+
if query_res is None:
304+
return []
305+
query_res = query_res.json()
296306
for job in query_res["hits"]["hits"]:
297307
job_info = job.get("_source", {})
298308
if job_name == job_info.get("s_job_name"):
@@ -346,6 +356,9 @@ def queryPRIdsFromOpenSearchDB(repo_name, last_days=DEFAULT_LOOKBACK_DAYS):
346356
try:
347357
query_res = OpenSearchDB.queryFromOpenSearchDB(
348358
json_data, PR_PROJECT_NAME)
359+
if query_res is None:
360+
return []
361+
query_res = query_res.json()
349362
for pr in query_res["hits"]["hits"]:
350363
pr_info = pr.get("_source", {})
351364
if repo_name == pr_info.get("s_repo_name"):

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ exclude = [
941941
"tests/integration/defs/perf/diff_tools.py",
942942
"tests/integration/defs/perf/gpu_clock_lock.py",
943943
"tests/integration/defs/perf/misc.py",
944+
"tests/integration/defs/perf/open_search_db_utils.py",
944945
"tests/integration/defs/perf/pytorch_model_config.py",
945946
"tests/integration/defs/perf/sample_options_config.py",
946947
"tests/integration/defs/perf/sampler_options_config.py",

0 commit comments

Comments
 (0)