Skip to content

Commit

Permalink
Vijay feedback & reordered conditionals
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Roblin <[email protected]>
  • Loading branch information
finnroblin committed Jun 27, 2024
1 parent a78351e commit 95d445e
Showing 1 changed file with 44 additions and 19 deletions.
63 changes: 44 additions & 19 deletions osbenchmark/worker_coordinator/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
Expand Down Expand Up @@ -659,46 +659,71 @@ class DeleteKnnModel(Runner):
"""

NAME = "delete-knn-model"
MODEL_DOES_NOT_EXIST_STATUS_CODE = 404

async def __call__(self, opensearch, params):
model_id = parse_string_parameter("model_id", params)
should_ignore_if_model_DNE = params.get("ignore-if-model-does-not-exist", False)
ignore_if_model_does_not_exist = params.get(
"ignore-if-model-does-not-exist", False
)

method = "DELETE"
model_uri = f"/_plugins/_knn/models/{model_id}"

request_context_holder.on_client_request_start()

# 404 indicates the model has not been created.
# 404 indicates the model has not been created. The runner's response depends on ignore_if_model_does_not_exist.
response = await opensearch.transport.perform_request(
method, model_uri, params={"ignore": [404]}
method,
model_uri,
params={"ignore": [self.MODEL_DOES_NOT_EXIST_STATUS_CODE]},
)

request_context_holder.on_client_request_end()

if (
"error" in response.keys()
and response["status"] == 404
and not should_ignore_if_model_DNE
):
self.logger.error(
"Request to delete model [%s] failed because the model does not exist "\
"and ignore-if-model-does-not-exist was set to True. Response: [%s]",
# success condition.
if "result" in response.keys() and response["result"] == "deleted":
self.logger.debug("Model [%s] deleted successfully.", model_id)
return {"weight": 1, "unit": "ops", "success": True}

if "error" not in response.keys():
self.logger.warning(
"Request to delete model [%s] failed but no error, response: [%s]",
model_id,
response,
)
return {"success": False}
return {"weight": 1, "unit": "ops", "success": False}

if "error" in response.keys() and response["status"] != 404:
self.logger.error(
"Request to delete model [%s] failed with error: with error response: [%s]",
if response["status"] != self.MODEL_DOES_NOT_EXIST_STATUS_CODE:
self.logger.warning(
"Request to delete model [%s] failed with status [%s] and response: [%s]",
model_id,
response["status"],
response,
)
return {"success": False}
return {"weight": 1, "unit": "ops", "success": False}

if ignore_if_model_does_not_exist:
self.logger.debug(
(
"Model [%s] does not exist so it could not be deleted, "
"however ignore-if-model-does-not-exist is True so the "
"DeleteKnnModel operation succeeded."
),
model_id,
)

self.logger.debug("Model [%s] deleted successfully.", model_id)
return {"success": True}
return {"weight": 1, "unit": "ops", "success": True}

self.logger.warning(
(
"Request to delete model [%s] failed because the model does not exist "
"and ignore-if-model-does-not-exist was set to False. Response: [%s]"
),
model_id,
response,
)
return {"weight": 1, "unit": "ops", "success": False}

def __repr__(self, *args, **kwargs):
return self.NAME
Expand Down

0 comments on commit 95d445e

Please sign in to comment.