fix(api): add bulk_upsert method and unit tests for opensearch BaseOSDB class - #990
fix(api): add bulk_upsert method and unit tests for opensearch BaseOSDB class#990vkuznet wants to merge 14 commits into
Conversation
Documentation build overview
17 files changed ·
|
@fstagni regarding issue #401. I checked the main repository code and what is described in this issue is not there the issue is based on commit outside of any branch, most likely in fork outside of the repository diracx/diracx-routers/src/diracx/routers/jobs/status.py Lines 174 to 180 in 7c260cc |
|
Hi, since #410 was created, the mentioned code has been moved and refactored, and can now be found in https://github.com/DIRACGrid/diracx/blob/main/diracx-logic/src/diracx/logic/jobs/status.py#L643. The issue anyway still holds, can you have a look? |
for more information, see https://pre-commit.ci
…mentation for MockOSDBMixin class
| response, | ||
| ) | ||
|
|
||
| async def bulk_upsert( |
There was a problem hiding this comment.
bulk_upsert would need to overridden within job_parameters_db because we are inserting a JobID and a timestamp:
diracx/diracx-db/src/diracx/db/os/job_parameters.py
Lines 37 to 43 in 202f84c
Here it would not work I think (and it looks like it's not spotted within the tests).
I actually wonder whether upsert is useful now that we have bulk_upsert.
I would suggest we just drop upsert and replace it everywhere with bulk_upsert, what do you think?
| if new_application: | ||
| job_data["ApplicationStatus"] = new_application | ||
|
|
||
| await job_parameters_db.upsert(res["VO"], job_id, {"Status": new_status}) |
There was a problem hiding this comment.
bulk_upsert could (should) be used here too I think
| self.client, | ||
| actions, | ||
| raise_on_error=False, | ||
| raise_on_exception=False, |
There was a problem hiding this comment.
I'm just wondering what happens if there is a connection issue with the DB and no exception is raised.
I guess you would get 0 success, N errors but would get any information to know that there is an issue with the DB itself?
There was a problem hiding this comment.
Also I am wondering whether it would make sense to use max_retries and initial_backoff:
https://github.com/opensearch-project/opensearch-py/blob/213b7d6b2890c19bc83ebce0a9886d7571760240/opensearchpy/_async/helpers/actions.py#L188-L192
| if errors: | ||
| for error in errors: | ||
| logger.error("bulk insert error %s", error) | ||
| raise DocumentUpsertError("Failed to perform bulk insert operation") |
There was a problem hiding this comment.
I assume this piece of code is generic because will be reused every time there is an error.
Wouldn't it make sense to raise the DocumentUpsertError from diracx-db itself? So that this part of the code only lives in db/os/utils and is automatically reused by the callers
| class DummyOSDB(BaseOSDB): | ||
| fields = { | ||
| "job_id": {"type": "long"}, | ||
| "status": {"type": "keyword"}, | ||
| "timestamp": {"type": "date"}, | ||
| "vo": {"type": "keyword"}, | ||
| } | ||
| index_prefix = "dummy" | ||
|
|
||
| def index_name(self, vo: str, doc_id: int) -> str: | ||
| return f"{self.index_prefix}-{vo}-{doc_id % 10}" |
There was a problem hiding this comment.
Any reason for not reusing diracx-testing DummyOSDB? https://github.com/DIRACGrid/diracx/blob/d72016500fb6cfd73350aa7b2582c5dd2cdcf2d2/diracx-testing/src/diracx/testing/dummy_osdb.py
Like in
There was a problem hiding this comment.
Isn't there some duplication with https://github.com/DIRACGrid/diracx/blob/d72016500fb6cfd73350aa7b2582c5dd2cdcf2d2/diracx-db/tests/opensearch/test_search.py?
There was a problem hiding this comment.
I think you can remove this conftest.py file and add your mock_osdb fixture within os_db.py, which is already including in pyproject.toml of the diracx-* packages. See in
diracx/diracx-logic/pyproject.toml
Line 59 in d720165
Though it looks like this is not documented...
This PR fixes issue #401 by introducing the
bulk_upsertAPI to BaseOSDB class. It is also complement by full set of unit tests for BaseOSDB class which were missing. The unit test introduces mock client and different classes for different use cases.Depends on #1007
Please note: it is my first PR and I'm happy to adjust it according to requirements/guidelines of DiracX community.