sacred
sacred copied to clipboard
Store url and database as part of MongoObserver
I am trying to implement some code that creates the appropriate ExperimentLoader
from incense
given a particular observer. Unfortunately it seems that it is not possible to access the url and database name provided to MongoObserver
, as they are not stored in the object itself. Would it be possible to keep that information around?
Hey @vnmabus , are you still looking for this to be added?
At some point, you must be giving the URL to the MongoObserver
. You would be free to add the URL there if that works for you.
url = "mongodb://sample:password@localhost:27017/?authMechanism=SCRAM-SHA-1"
ex = Experiment("add_url")
mongo_obs = MongoObserver.create(url=url, db_name="db")
mongo_obs.url = url
ex.observers.append(mongo_obs)
If that doesn't work for your use case, I'd be happy to put a PR up that stores the pymongo client as an instance attribute.
Unfortunately the part of the code responsible from creating the observer is not under my control, so that is not possible.
Interesting. I put up a PR to allow you to get the MongoClient
with mongo_obs._client
.
How is the observer getting created? Are you using another library to handle that part?
No, my code IS a library. Given an observer and some ids, it needs to recover the results.
Just to let you know, my actual, totally a hack solution to this problem is here:
elif isinstance(storage, MongoObserver):
database = storage.runs.database
client = database.client
url, port = list(
client.topology_description.server_descriptions().keys(),
)[0]
return ExperimentLoader(
mongo_uri=f"mongodb://{url}:{port}/",
db_name=database.name,
unpickle=False,
)
I would rather write:
elif isinstance(storage, MongoObserver):
return ExperimentLoader(
mongo_uri=f"mongodb://{storage.url}:{storage.port}/",
db_name=database.name,
unpickle=False,
)