Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opensearch #79

Merged
merged 10 commits into from
Sep 18, 2023
Merged

Opensearch #79

merged 10 commits into from
Sep 18, 2023

Conversation

chaen
Copy link
Contributor

@chaen chaen commented Sep 8, 2023

Example usage

# DIRACX_OS_DB_JOBPARAMETERSDB='{"hosts": "https://admin:admin@opensearch-cluster-master:9200", "use_ssl": true, "verify_certs": false}' HOME=/tmp/home ipython
import asyncio
import json
import os

from diracx.db.jobs.job_parameters import JobParametersDB


db = JobParametersDB(json.loads(os.environ["DIRACX_OS_DB_JOBPARAMETERSDB"]))

async with db.client_context():
    print(await db.search(None, None, None))
    job_id = 798811211
    doc = {
        'CEQueue': 'nordugrid-Condor-grid',
        'HostName': 'lapp-wn301.in2p3.fr',
        # 'JobID': job_id,
        "asad": "12345678"
    }
    await db.upsert(job_id, doc)
    await asyncio.sleep(2)
    print(await db.search(None, None, None))

TODOs:

  • Properly implement the search method
  • Add integration tests (once we have diracx integration tests, requires Add demo ci diracx-charts#34)
  • Restructure diracx.db to be split into diracx.db.os and diracx.db.sql?
  • Figure out how best to manage indicies and implement python -m diracx.db init-os
  • Create a BaseDB class with the commonalities between BaseSQLDB and BaseOSDB?
  • Rename client_context/engine_context to lifetime_function? Probably not

from .auth.db import AuthDB
from .jobs.db import JobDB, JobLoggingDB
from .sandbox_metadata.db import SandboxMetadataDB
from .sql.auth.db import AuthDB
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that stay here, or do we want to expose to the routers the sql or os ?
Since we started making the distinction, it's probably worth pursuing so a router would do from diracx.db.sql import AuthDB

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree, especially as the behavour and API is different in each case.

Copy link
Contributor

@fstagni fstagni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the cost of being a bit more verbose, I would expand everywhere "os" -> "opensearch", for clarity.
Also, as of now you added directories tests/db/opensearch and src/diracx/db/os, I would reconcile everything to opensearch.

from diracx.db.os.utils import BaseOSDB

for db_name, db_url in BaseOSDB.available_urls().items():
logger.info("Initialising %s", db_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info("Initialising %s", db_name)
logger.info(f"Initialising {db_name}")

"HostName": {"type": "keyword"},
"GridCE": {"type": "keyword"},
"ModelName": {"type": "keyword"},
"Status": {"type": "keyword"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Status should be removed: DIRACGrid/DIRAC#7191
And a few of these should be moved to ElasticPilotParameters: DIRACGrid/DIRAC#7164

Do you want to create this implementation anyway now for testing? In this case put some ToDO notes (the links above would suffice).

for entry_point in select_from_extension(group="diracx.db.os", name=db_name)
]
if not db_classes:
raise NotImplementedError(f"Could not find any matches for {db_name=}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise NotImplementedError(f"Could not find any matches for {db_name=}")
raise NotImplementedError(f"Could not find any matches for {db_name}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the intended behavior

In [1]: a=3

In [2]: f"{a=}"
Out[2]: 'a=3'

try:
conn_kwargs[db_name] = json.loads(os.environ[var_name])
except Exception:
logger.error("Error loading connection parameters for %s", db_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.error("Error loading connection parameters for %s", db_name)
logger.error(f"Error loading connection parameters for {db_name}")```


async def __aenter__(self):
"""This is entered on every request. It does nothing"""
assert self._client is None, "client_context hasn't been entered"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert self._client is None, "client_context hasn't been entered"
assert self._client is None, "client_context has not been entered"

when it is about printing something, I would avoid any possibly-interpreted-as-special characters.

@@ -107,7 +109,7 @@ def available_urls(cls) -> dict[str, str]:
else:
db_urls[db_name] = parse_obj_as(SqlalchemyDsn, db_url)
except Exception:
logger.error("Error loading URL %s for %s", db_name, db_url)
logger.error("Error loading URL for %s", db_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.error("Error loading URL for %s", db_name)
logger.error(f"Error loading URL for {db_name}")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional, see #35 (comment)

@chaen chaen merged commit 70ebe49 into DIRACGrid:main Sep 18, 2023
12 checks passed
@fstagni
Copy link
Contributor

fstagni commented Sep 18, 2023

My review was completely ignored?

@chaen
Copy link
Contributor Author

chaen commented Sep 18, 2023

Sorry, I did not see it, we were discussing it on a shared screen and I did not refresh the page.
I agree with some of the comments, but I wouldn't replace OS to OpenSearch, it's just too long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants