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

[Refactor] Extract GrpcRunner from GRPCIndexBase class #395

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

jhamon
Copy link
Collaborator

@jhamon jhamon commented Oct 15, 2024

Problem

This is another extractive refactoring in preparation for grpc with asyncio.

Solution

The generated stub class, VectorServiceStub, is what knows how to call the Pinecone grpc service, but our wrapper code needs to do some work to make sure we have a consistent approach to "metadata" (grpc-speak for request headers) and handling other request params like timeout. Previously this work was accomplished in a private method of the GRPCIndexBase base class called _wrap_grpc_call().

Since we will need to perform almost identical marshaling of metadata for requests with asyncio, I pulled this logic out into a separate class GrpcRunner and renamed _wrap_grpc_call to run. You can see there is also a parallel method implementation called run_asyncio; currently this is unused and untested, but kind of illustrates why this refactor is useful.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: Mechanical refactor, should have no net impact to functionality.

Test Plan

Tests should still be green


return wrapped()

async def run_asyncio(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not using or testing run_asyncio anywhere yet, but I will. It's the same as run but with the addition of the async/await bits.

@jhamon jhamon changed the title [Refactor] Extract GrpcRunner class [Refactor] Extract GrpcRunner class from GRPCIndexBase Oct 15, 2024
@jhamon jhamon changed the title [Refactor] Extract GrpcRunner class from GRPCIndexBase [Refactor] Extract GrpcRunner from GRPCIndexBase class Oct 15, 2024
@jhamon jhamon marked this pull request as ready for review October 15, 2024 15:51
Copy link
Contributor

@austin-denoble austin-denoble left a comment

Choose a reason for hiding this comment

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

LGTM, seems like a nice cleanup overall.

from pinecone.utils.constants import REQUEST_ID, CLIENT_VERSION
from pinecone.exceptions.exceptions import PineconeException

_logger = logging.getLogger(__name__)
Copy link
Contributor

Choose a reason for hiding this comment

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

This wasn't being used, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently unused. The _logger reference is now used in the GrpcChannelFactory which is logic I recently pulled out of this base class. Cleaning up this reference should have happened in that PR, but got overlooked.

from google.protobuf.message import Message


class GrpcRunner:
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea pulling all of this out into somewhere contained. 👍

Copy link
Contributor

@haruska haruska left a comment

Choose a reason for hiding this comment

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

👍

@jhamon jhamon merged commit 2831a5e into main Oct 15, 2024
86 checks passed
@jhamon jhamon deleted the jhamon/extract-grpc-runner branch October 15, 2024 18:16
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