-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Implement gRPC server to ingest streaming features #3687
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b235d1a
Implemented gRPC server for ingesting streaming features.
1b4bf8d
[lint-python]
809b9eb
Fix unmatched gRPC field issue.
5ea58d1
Make max_workers parameter configurable.
9766c53
[lint-python]
b92b838
Refactor gRPC server to have similar logic with HTTP server
caed020
Refactor CLI.
cd537d9
Type parameter.
d73c3d7
Upgrade 3.8 requirements.
a5000d8
Configure health check service and update CI dependencies
be0010d
Downgrade flake8 version to prevent E721 checks.
5f73e77
lint
adchia 392768a
fix grpcio pin
adchia 0c75491
fix lint
adchia 068de80
Fix linter
adchia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| message PushRequest { | ||
| map<string, string> features = 1; | ||
| string stream_feature_view = 2; | ||
| bool allow_registry_cache = 3; | ||
| string to = 4; | ||
| } | ||
|
|
||
| message PushResponse { | ||
| bool status = 1; | ||
| } | ||
|
|
||
| message WriteToOnlineStoreRequest { | ||
| map<string, string> features = 1; | ||
| string feature_view_name = 2; | ||
| bool allow_registry_cache = 3; | ||
| } | ||
|
|
||
| message WriteToOnlineStoreResponse { | ||
| bool status = 1; | ||
| } | ||
|
|
||
| service GrpcFeatureServer { | ||
| rpc Push (PushRequest) returns (PushResponse) {}; | ||
| rpc WriteToOnlineStore (WriteToOnlineStoreRequest) returns (WriteToOnlineStoreResponse); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import logging | ||
| from concurrent import futures | ||
|
|
||
| import grpc | ||
| import pandas as pd | ||
| from grpc_health.v1 import health, health_pb2_grpc | ||
|
|
||
| from feast.data_source import PushMode | ||
| from feast.errors import PushSourceNotFoundException | ||
| from feast.feature_store import FeatureStore | ||
| from feast.protos.feast.serving.GrpcServer_pb2 import ( | ||
| PushResponse, | ||
| WriteToOnlineStoreResponse, | ||
| ) | ||
| from feast.protos.feast.serving.GrpcServer_pb2_grpc import ( | ||
| GrpcFeatureServerServicer, | ||
| add_GrpcFeatureServerServicer_to_server, | ||
| ) | ||
|
|
||
|
|
||
| def parse(features): | ||
| df = {} | ||
| for i in features.keys(): | ||
| df[i] = [features.get(i)] | ||
| return pd.DataFrame.from_dict(df) | ||
|
|
||
|
|
||
| class GrpcFeatureServer(GrpcFeatureServerServicer): | ||
| fs: FeatureStore | ||
|
|
||
| def __init__(self, fs: FeatureStore): | ||
| self.fs = fs | ||
| super().__init__() | ||
|
|
||
| def Push(self, request, context): | ||
| try: | ||
| df = parse(request.features) | ||
| if request.to == "offline": | ||
| to = PushMode.OFFLINE | ||
| elif request.to == "online": | ||
| to = PushMode.ONLINE | ||
| elif request.to == "online_and_offline": | ||
| to = PushMode.ONLINE_AND_OFFLINE | ||
| else: | ||
| raise ValueError( | ||
| f"{request.to} is not a supported push format. Please specify one of these ['online', 'offline', " | ||
| f"'online_and_offline']." | ||
| ) | ||
| self.fs.push( | ||
| push_source_name=request.push_source_name, | ||
| df=df, | ||
| allow_registry_cache=request.allow_registry_cache, | ||
| to=to, | ||
| ) | ||
| except PushSourceNotFoundException as e: | ||
| logging.exception(str(e)) | ||
| context.set_code(grpc.StatusCode.INVALID_ARGUMENT) | ||
| context.set_details(str(e)) | ||
| return PushResponse(status=False) | ||
| except Exception as e: | ||
| logging.exception(str(e)) | ||
| context.set_code(grpc.StatusCode.INTERNAL) | ||
| context.set_details(str(e)) | ||
| return PushResponse(status=False) | ||
| return PushResponse(status=True) | ||
|
|
||
| def WriteToOnlineStore(self, request, context): | ||
| logging.warning( | ||
| "write_to_online_store is deprecated. Please consider using Push instead" | ||
| ) | ||
| try: | ||
| df = parse(request.features) | ||
| self.fs.write_to_online_store( | ||
| feature_view_name=request.feature_view_name, | ||
| df=df, | ||
| allow_registry_cache=request.allow_registry_cache, | ||
| ) | ||
| except Exception as e: | ||
| logging.exception(str(e)) | ||
| context.set_code(grpc.StatusCode.INTERNAL) | ||
| context.set_details(str(e)) | ||
| return PushResponse(status=False) | ||
| return WriteToOnlineStoreResponse(status=True) | ||
|
|
||
|
|
||
| def get_grpc_server(address: str, fs: FeatureStore, max_workers: int): | ||
| server = grpc.server(futures.ThreadPoolExecutor(max_workers=max_workers)) | ||
| add_GrpcFeatureServerServicer_to_server(GrpcFeatureServer(fs), server) | ||
| health_servicer = health.HealthServicer( | ||
| experimental_non_blocking=True, | ||
| experimental_thread_pool=futures.ThreadPoolExecutor(max_workers=max_workers), | ||
| ) | ||
| health_pb2_grpc.add_HealthServicer_to_server(health_servicer, server) | ||
| server.add_insecure_port(address) | ||
| return server | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.