Skip to content

Add object store #299

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

balvisio
Copy link
Contributor

Description

This PR addresses https://jirasw.nvidia.com/browse/AIQ-846

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Signed-off-by: Bruno Alvisio <[email protected]>
Copy link

copy-pr-bot bot commented May 19, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@mdemoret-nv mdemoret-nv added feature request New feature or request non-breaking Non-breaking change labels Jun 10, 2025
Copy link
Collaborator

@mdemoret-nv mdemoret-nv left a comment

Choose a reason for hiding this comment

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

This is a really good start. I have a few general suggestions:

  1. One goal of this was to allow accessing these objects from the fastapi server. I think we need to update the server configuration options to support something like this:
        # Upload static files to the object store
        async def static_files(file: UploadFile):

            object_store_client = builder.get_object_store_client(self.front_end_config.object_store)

            file_data = await file.read()

            await object_store_client.put_object(file.filename, ObjectStoreItem(data=file_data, content_type=file.content_type))

            return {"filename": file.filename}

        app.add_api_route(
            path="/static",
            endpoint=static_files,
            methods=["POST"],
        )

        # Get static files from the object store
        async def get_static_files(file_name: str):

            object_store_client = builder.get_object_store_client(self.front_end_config.object_store)

            file_data = await object_store_client.get_object(file_name)

            return FileResponse(file_data.data, media_type=file_data.content_type)

        app.add_api_route(
            path="/static/{file_name}",
            endpoint=get_static_files,
            methods=["GET"],
        )
  1. The functions in the user_report example should be generalizable and could be included in the main library since they will work with any data store.
  2. Are there other more complex data store types that we should consider to ensure the interface works. Redis? MySQL?
  3. Will need to update documentation

Comment on lines +27 to +31
bucket_name: str,
access_key: str | None,
secret_key: str | None,
region: str | None,
endpoint_url: str | None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you just accept the config object directly, this simplifies the signature

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

endpoint_url: str | None):
self.bucket_name = bucket_name
self.session = aioboto3.Session()
access_key = access_key or os.environ.get("OBJECT_STORE_ACCESS_KEY")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefix all env variables with AIQ_

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

pass

@abstractmethod
async def get_object(self, key: str) -> ObjectStoreItem | str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

How can this return a string if you cant set a string?

"""

@abstractmethod
async def put_object(self, key: str, data: ObjectStoreItem) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to address duplicate entries. Do we add an upsert method?

pass

@abstractmethod
async def delete_object(self, key: str) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about checking if a key exists?

key: str,
data: ObjectStoreItem,
) -> None:
self._store[key] = data
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should throw an error if the key exists already

return

async def get_object(self, key: str) -> ObjectStoreItem | str:
return self._store.get(key, f"No object found with key: {key}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should throw an exception if the key does not exist

return self._store.get(key, f"No object found with key: {key}")

async def delete_object(self, key: str) -> None:
self._store.pop(key, None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Exception if the key does not exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants