From 6427fb9e610c9c3d402f92f69b969b6fe4f70b2e Mon Sep 17 00:00:00 2001 From: ntkathole Date: Wed, 28 May 2025 15:30:46 +0530 Subject: [PATCH] feat: Support dual-mode REST and gRPC for Feast Registry Server Signed-off-by: ntkathole --- .../feature-servers/registry-server.md | 17 +++- .../api/registry/rest/rest_registry_server.py | 8 +- sdk/python/feast/cli/serve.py | 78 ++++++++++++++++++- sdk/python/feast/constants.py | 5 +- 4 files changed, 100 insertions(+), 8 deletions(-) diff --git a/docs/reference/feature-servers/registry-server.md b/docs/reference/feature-servers/registry-server.md index 98c152fbeed..55a2ac4bf07 100644 --- a/docs/reference/feature-servers/registry-server.md +++ b/docs/reference/feature-servers/registry-server.md @@ -4,6 +4,15 @@ The Registry server supports both gRPC and REST interfaces for interacting with feature metadata. While gRPC remains the default protocol—enabling clients in any language with gRPC support—the REST API allows users to interact with the registry over standard HTTP using any REST-capable tool or language. +Feast supports running the Registry Server in three distinct modes: + +| Mode | Command Example | Description | +| ----------- | ------------------------------------------- | -------------------------------------- | +| gRPC only | `feast serve_registry` | Default behavior for SDK and clients | +| REST + gRPC | `feast serve_registry --rest-api` | Enables both interfaces | +| REST only | `feast serve_registry --rest-api --no-grpc` | Used for REST-only clients like the UI | + + ## How to configure the server ## CLI @@ -12,10 +21,16 @@ There is a CLI command that starts the Registry server: `feast serve_registry`. To start the Registry Server in TLS mode, you need to provide the private and public keys using the `--key` and `--cert` arguments. More info about TLS mode can be found in [feast-client-connecting-to-remote-registry-sever-started-in-tls-mode](../../how-to-guides/starting-feast-servers-tls-mode.md#starting-feast-registry-server-in-tls-mode) -To enable REST API support, start the registry server with REST mode enabled : +To enable REST API support along with gRPC, start the registry server with REST mode enabled : `feast serve_registry --rest-api` +This launches both the gRPC and REST servers concurrently. The REST server listens on port 6572 by default. + +To run a REST-only server (no gRPC): + +`feast serve_registry --rest-api --no-grpc` + ## How to configure the client diff --git a/sdk/python/feast/api/registry/rest/rest_registry_server.py b/sdk/python/feast/api/registry/rest/rest_registry_server.py index b77580fcab6..dc71523b1c8 100644 --- a/sdk/python/feast/api/registry/rest/rest_registry_server.py +++ b/sdk/python/feast/api/registry/rest/rest_registry_server.py @@ -15,6 +15,7 @@ from feast.registry_server import RegistryServer logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) class RestRegistryServer: @@ -28,6 +29,7 @@ def __init__(self, store: FeatureStore): dependencies=[Depends(inject_user_details)], version="1.0.0", openapi_url="/openapi.json", + root_path="/api/v1", docs_url="/", redoc_url="/docs", default_status_code=status.HTTP_200_OK, @@ -86,7 +88,7 @@ def start_server( if tls_key_path and tls_cert_path: logger.info("Starting REST registry server in TLS(SSL) mode") - print(f"REST registry server listening on https://localhost:{port}") + logger.info(f"REST registry server listening on https://localhost:{port}") uvicorn.run( self.app, host="0.0.0.0", @@ -95,8 +97,8 @@ def start_server( ssl_certfile=tls_cert_path, ) else: - print("Starting REST registry server in non-TLS(SSL) mode") - print(f"REST registry server listening on http://localhost:{port}") + logger.info("Starting REST registry server in non-TLS(SSL) mode") + logger.info(f"REST registry server listening on http://localhost:{port}") uvicorn.run( self.app, host="0.0.0.0", diff --git a/sdk/python/feast/cli/serve.py b/sdk/python/feast/cli/serve.py index 53499506762..049eb232165 100644 --- a/sdk/python/feast/cli/serve.py +++ b/sdk/python/feast/cli/serve.py @@ -1,12 +1,18 @@ +import logging +import multiprocessing + import click from feast.constants import ( DEFAULT_FEATURE_TRANSFORMATION_SERVER_PORT, DEFAULT_OFFLINE_SERVER_PORT, + DEFAULT_REGISTRY_REST_SERVER_PORT, DEFAULT_REGISTRY_SERVER_PORT, ) from feast.repo_operations import create_feature_store +logging.basicConfig(level=logging.INFO) + @click.command("serve") @click.option( @@ -147,6 +153,13 @@ def serve_transformations_command(ctx: click.Context, port: int): default=DEFAULT_REGISTRY_SERVER_PORT, help="Specify a port for the server", ) +@click.option( + "--rest-port", + type=click.INT, + default=DEFAULT_REGISTRY_REST_SERVER_PORT, + show_default=True, + help="Specify a port for the REST API server (if enabled).", +) @click.option( "--key", "-k", @@ -165,12 +178,20 @@ def serve_transformations_command(ctx: click.Context, port: int): show_default=False, help="path to TLS certificate public key. You need to pass --key as well to start server in TLS mode", ) +@click.option( + "--grpc/--no-grpc", + is_flag=True, + default=True, + show_default=True, + help="Start a gRPC Registry Server. Enabled by default.", +) @click.option( "--rest-api", "-r", is_flag=True, + default=False, show_default=True, - help="Start a REST API Server", + help="Start a REST API Registry Server", ) @click.pass_context def serve_registry_command( @@ -178,16 +199,67 @@ def serve_registry_command( port: int, tls_key_path: str, tls_cert_path: str, + grpc: bool, rest_api: bool, + rest_port: int, ): - """Start a gRPC or REST api registry server locally on a given port (gRPC by default).""" + """Start Feast Registry server (gRPC by default, REST opt-in).""" if (tls_key_path and not tls_cert_path) or (not tls_key_path and tls_cert_path): raise click.BadParameter( "Please pass --cert and --key args to start the registry server in TLS mode." ) store = create_feature_store(ctx) - store.serve_registry(port, tls_key_path, tls_cert_path, rest_api) + if grpc and rest_api: + repo_path = store.repo_path + multiprocessing.set_start_method("spawn", force=True) + servers = [ + multiprocessing.Process( + target=_serve_grpc_registry, + args=(repo_path, port, tls_key_path, tls_cert_path), + name="grpc_registry_server", + ), + multiprocessing.Process( + target=_serve_rest_registry, + args=(repo_path, rest_port, tls_key_path, tls_cert_path), + name="rest_registry_server", + ), + ] + logging.info("Starting Feast Registry servers (gRPC + REST)...") + for p in servers: + logging.info(f"Starting {p.name}") + p.start() + for p in servers: + p.join() + else: + store.serve_registry(port, tls_key_path, tls_cert_path, rest_api) + + +def _serve_grpc_registry( + repo_path: str, port: int, tls_key_path: str, tls_cert_path: str +): + from feast import FeatureStore + + store = FeatureStore(repo_path=repo_path) + store.serve_registry( + port=port, + tls_key_path=tls_key_path, + tls_cert_path=tls_cert_path, + ) + + +def _serve_rest_registry( + repo_path: str, port: int, tls_key_path: str, tls_cert_path: str +): + from feast import FeatureStore + + store = FeatureStore(repo_path=repo_path) + store.serve_registry( + port=port, + tls_key_path=tls_key_path, + tls_cert_path=tls_cert_path, + rest_api=True, + ) @click.command("serve_offline") diff --git a/sdk/python/feast/constants.py b/sdk/python/feast/constants.py index 7dd39458211..240dda3311b 100644 --- a/sdk/python/feast/constants.py +++ b/sdk/python/feast/constants.py @@ -35,9 +35,12 @@ # Default FTS port DEFAULT_FEATURE_TRANSFORMATION_SERVER_PORT = 6569 -# Default registry server port +# Default registry server grpc port DEFAULT_REGISTRY_SERVER_PORT = 6570 +# Default registry server REST port +DEFAULT_REGISTRY_REST_SERVER_PORT = 6572 + # Default offline server port DEFAULT_OFFLINE_SERVER_PORT = 8815