feat: Add OnlineStore for MongoDB - #6025
Conversation
5a815be to
6581159
Compare
|
@caseyclements please check the errors in the tests :) |
6aa5578 to
91dc75c
Compare
|
@shuchu Would you please help me investigate the CI timeout? I can run the universal tests for mongodb locally, like so: |
|
@caseyclements Please rebase with master, it would solve the CI issue |
91dc75c to
bcaa548
Compare
|
Thanks @ntkathole , @shuchu . Would you please approve further workflows if applicable. |
|
Hi @shuchu, @ntkathole, @oavdeev, @ankurs. All checks are now passing on approved workflows. Would you please kick off the others? Of course, your personal feedback would be great as well. In the meantime, I am working on an offline store. |
|
Hi @shuchu, @ntkathole, @oavdeev, @ankurs. I made a small change in |
Need to add mongodb in operator as well |
@ntkathole Thanks. The go files weren't on my radar. It looks like we're almost there. I updated a few small pieces based on feedback from our product team. Would you please kick off the workflows? |
|
@caseyclements seems linting issue with operator code, you can run make lint in feast-operator dir to fix |
I believe this might be fixed by updating the GOLANGCI_LINT version. This fixes the issue which I could reproduce locally. No actual changes were needed though. It was a tooling issue. |
|
@ntkathole Can I get a rerun of the workflows please? Is there someone on the west coast that can do another run? |
| We remove any feature views named in tables_to_delete. | ||
| The Entities are serialized in the _id. No schema needs be adjusted. | ||
| """ | ||
| if config.online_store.type != "mongodb": |
There was a problem hiding this comment.
| if config.online_store.type != "mongodb": | |
| if not isinstance(config.online_store, MongoDBOnlineStoreConfig): |
Good to be consistent across
| _client_async: Optional[AsyncMongoClient] = None | ||
| _collection_async: Optional[AsyncCollection] = None | ||
|
|
||
| def online_write_batch( |
There was a problem hiding this comment.
online_write_batch and online_write_batch_async has duplicated logic written in two different styles, we can extract the shared logic into a static helper that both paths call
|
HI @ntkathole I'll make the suggested changes. Is the one failing test a red-herring? It appears to be an unrelated timeout. |
yes, unrelated |
|
Please rebase with master, seems there are some conflicts |
Can I merge, or is only rebase permitted? |
| async def close(self) -> None: | ||
| """Close the async MongoDB client and release its resources.""" | ||
| if self._client_async is not None: | ||
| await self._client_async.close() | ||
| self._client_async = None | ||
| self._collection_async = None |
There was a problem hiding this comment.
🟡 Resource leak: teardown() never closes async client, close() never closes sync client
The MongoDBOnlineStore maintains two independent clients: _client (sync MongoClient) and _client_async (async AsyncMongoClient). The teardown() method (line 273-276) only closes the sync _client and leaves _client_async open. Conversely, the close() method (line 280-283) only closes _client_async and leaves the sync _client open. If both clients are created during the lifetime of a store instance (e.g., sync writes via online_write_batch followed by async reads via online_read_async, or vice versa), the other client's connection pool will leak when cleanup runs through either path.
| async def close(self) -> None: | |
| """Close the async MongoDB client and release its resources.""" | |
| if self._client_async is not None: | |
| await self._client_async.close() | |
| self._client_async = None | |
| self._collection_async = None | |
| async def close(self) -> None: | |
| """Close both async and sync MongoDB clients and release their resources.""" | |
| if self._client_async is not None: | |
| await self._client_async.close() | |
| self._client_async = None | |
| self._collection_async = None | |
| if self._client is not None: | |
| self._client.close() | |
| self._client = None | |
| self._collection = None |
Was this helpful? React with 👍 or 👎 to provide feedback.
…t.toml Any change to pyproject.toml invalidates the pixi.lock manifest hash, causing 'pixi install --locked' to fail in CI even when the changed section (mongodb optional extras) is not used by any pixi environment. Regenerated with: pixi install (v0.63.2) Signed-off-by: Casey Clements <casey.clements@mongodb.com>
Stores like mongodb, redis, and dynamodb raise FeastExtrasDependencyImportError at import time when their optional Python extras are not installed. test_all.py only caught ModuleNotFoundError, so any such import caused the entire test_docstrings() function to abort rather than gracefully skipping the module. Extend the except clause to also catch FeastExtrasDependencyImportError so the doctest run completes for all other modules when an optional extra is absent in the test environment. Signed-off-by: Casey Clements <casey.clements@mongodb.com>
Directory was renamed from tests/integration/feature_repos to tests/universal/feature_repos in upstream/master. Update the PYTEST_PLUGINS module path in test-python-universal-mongodb-online to match the new location. Signed-off-by: Casey Clements <casey.clements@mongodb.com>
…eError and other third-party import errors qdrant_client raises TypeError at import time when a gRPC EnumTypeWrapper is used with the | union operator on Python < 3.12. The previous fix only caught ModuleNotFoundError and FeastExtrasDependencyImportError, leaving the test runner vulnerable to any other exception raised by third-party libraries during pkgutil.walk_packages. Changes: - Catch bare Exception in the import try/except block so any import-time error from an optional dependency causes a graceful skip rather than an abort of the entire test run. - Initialize temp_module = None before the try block and add a continue guard so that a failed import never leaves a stale module reference to be used in the subsequent doctest execution block. Signed-off-by: Casey Clements <casey.clements@mongodb.com>
…r package import failures FeastExtrasDependencyImportError inherits from FeastError -> Exception, not from ImportError. pkgutil.walk_packages calls __import__ internally when recursing into sub-packages, and only silently swallows ImportError subclasses; any other exception is re-raised, crashing the entire test run. Passing onerror=lambda _: None tells walk_packages to skip any package that fails to import during the walk phase, regardless of the exception type. The inner importlib.import_module try/except already handles the same errors for the explicit import step used to collect doctests. Signed-off-by: Casey Clements <casey.clements@mongodb.com>
…iversal.feature_repos The upstream directory tests/integration/feature_repos was renamed to tests/universal/feature_repos. Three files still referenced the old path: - mongodb_repo_configuration.py: IntegrationTestRepoConfig and MongoDBOnlineStoreCreator imports - tests/.../online_store/mongodb.py: OnlineStoreCreator import - tests/unit/online_store/test_mongodb_online_retrieval.py: TAGS import Updating all three unblocks test collection and allows make test-python-universal-mongodb-online to run locally. Signed-off-by: Casey Clements <casey.clements@mongodb.com>
…-operator The Python ONLINE_STORE_CLASS_FOR_TYPE now includes 'mongodb', so the operator's parity check (test-datasources) fails unless the Go API also lists it. Add 'mongodb' to ValidOnlineStoreDBStorePersistenceTypes in both api/v1 and api/v1alpha1. Signed-off-by: Casey Clements <casey.clements@mongodb.com>
Add DriverInfo with the Feast name and version to both the sync MongoClient and async AsyncMongoClient so that MongoDB can identify traffic originating from a Feast AI integration. Signed-off-by: Casey Clements <casey.clements@mongodb.com>
Signed-off-by: Casey Clements <casey.clements@mongodb.com>
…rePersistence The +kubebuilder:validation:Enum annotation on the Type field of OnlineStoreDBStorePersistence was not updated when mongodb was added to ValidOnlineStoreDBStorePersistenceTypes. This annotation drives CRD OpenAPI schema validation at Kubernetes admission time, so any FeatureStore CR specifying type: mongodb would be rejected by the API server. Updated both api/v1 and api/v1alpha1. Signed-off-by: Casey Clements <casey.clements@mongodb.com>
Signed-off-by: Casey Clements <casey.clements@mongodb.com>
…onsistent with sync counterpart Signed-off-by: Casey Clements <casey.clements@mongodb.com>
Signed-off-by: ntkathole <nikhilkathole2683@gmail.com>
Signed-off-by: Casey Clements <casey.clements@mongodb.com>
…ially identical. Signed-off-by: Casey Clements <casey.clements@mongodb.com>
cb9e1d6 to
e761e10
Compare
@ntkathole I've rebased all my commits from the latest master, and run tests locally. Please approve workflows and have a look. |
What this PR does / why we need it:
Adds a first-class MongoDB online store integration at
feast.infra.online_stores.mongodb_online_store.Schema
Each entity is stored as a single MongoDB document keyed by its serialized entity key:
{ "_id": "<serialized_entity_key>", "features": { "<feature_view>": { "<feature>": <value> } }, "event_timestamps": { "<feature_view>": "<datetime>" }, "created_timestamp": "<datetime>" }Because MongoDB has a loose schema and supports upsert semantics natively,
update()requires nopre-creation — it only removes feature views named in
tables_to_deletevia$unset. Multiplefeature views for the same entity share one document.
Implementation highlights
online_write_batch,online_read,online_write_batch_async,online_read_async, andasync def close().async_supportedreturnsread=True, write=True.requested_featuresprojection — both read paths build a MongoDB field projection so onlythe requested feature columns are returned from the server.
_convert_raw_docs_to_prototransforms column-wise tominimise calls to
python_values_to_proto_values(one call per feature across all entities,rather than one call per entity × feature). Benchmarking confirmed this is ~3–4× faster than a
naïve row-wise approach across all scaling dimensions (entities, features, feature views).
serialize_entity_key, so compositekeys (e.g.
customer_id + driver_id) are handled without schema changes.Tests
test_mongodb_online_features) — spins up a real MongoDB containervia
testcontainers, writes to three feature views (single int key, single string key, compositekey), and asserts correct retrieval including type coercion and missing-entity handling.
test_convert_raw_docs_missing_entity— entity absent from query results →(None, None)test_convert_raw_docs_partial_doc— entity present but a feature key missing → emptyValueProto(schema-migration safety)test_convert_raw_docs_ordering— result order follows the requestedidslist regardlessof MongoDB cursor order
All tests pass. Code is clean under
mypy,ruff check, andruff format.