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

Feast endpoint #1927

Merged
merged 6 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions sdk/python/feast/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import click
import pkg_resources
import yaml
from colorama import Fore, Style

from feast import flags, flags_helper, utils
from feast.errors import FeastObjectNotFoundException, FeastProviderLoginError
Expand Down Expand Up @@ -93,6 +94,24 @@ def version():
print(f'Feast SDK Version: "{pkg_resources.get_distribution("feast")}"')


@cli.command()
@click.pass_context
def endpoint(ctx: click.Context):
"""
Display feature server endpoints.
"""
repo = ctx.obj["CHDIR"]
cli_check_repo(repo)
store = FeatureStore(repo_path=str(repo))
endpoint = store.get_feature_server_endpoint()
if endpoint is not None:
_logger.info(
f"Feature server endpoint: {Style.BRIGHT + Fore.GREEN}{endpoint}{Style.RESET_ALL}"
)
else:
_logger.info("There is no active feature server.")


@cli.group(name="entities")
def entities_cmd():
"""
Expand Down
5 changes: 5 additions & 0 deletions sdk/python/feast/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,11 @@ def serve(self, port: int) -> None:

feature_server.start_server(self, port)

@log_exceptions_and_usage
def get_feature_server_endpoint(self) -> Optional[str]:
"""Returns endpoint for the feature server, if it exists."""
return self._provider.get_feature_server_endpoint()


def _entity_row_to_key(row: GetOnlineFeaturesRequestV2.EntityRow) -> EntityKeyProto:
names, values = zip(*row.fields.items())
Expand Down
28 changes: 25 additions & 3 deletions sdk/python/feast/infra/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import datetime
from pathlib import Path
from tempfile import TemporaryFile
from typing import Sequence, Union
from typing import Optional, Sequence, Union
from urllib.parse import urlparse

from colorama import Fore, Style
Expand Down Expand Up @@ -174,6 +174,20 @@ def teardown_infra(
_logger.info(" Tearing down AWS API Gateway...")
aws_utils.delete_api_gateway(api_gateway_client, api["ApiId"])

def get_feature_server_endpoint(self) -> Optional[str]:
project = self.repo_config.project
resource_name = self._get_lambda_name(project)
api_gateway_client = boto3.client("apigatewayv2")
api = aws_utils.get_first_api_gateway(api_gateway_client, resource_name)

if not api:
return None

api_id = api["ApiId"]
lambda_client = boto3.client("lambda")
region = lambda_client.meta.region_name
return f"https://{api_id}.execute-api.{region}.amazonaws.com"

def _upload_docker_image(self, project: str) -> str:
"""
Pulls the AWS Lambda docker image from Dockerhub and uploads it to AWS ECR.
Expand Down Expand Up @@ -213,7 +227,7 @@ def _upload_docker_image(self, project: str) -> str:
)
docker_client.images.pull(AWS_LAMBDA_FEATURE_SERVER_IMAGE)

version = get_version()
version = self._get_version_for_aws()
repository_name = f"feast-python-server-{project}-{version}"
ecr_client = boto3.client("ecr")
try:
Expand Down Expand Up @@ -246,7 +260,15 @@ def _upload_docker_image(self, project: str) -> str:
return image_remote_name

def _get_lambda_name(self, project: str):
return f"feast-python-server-{project}-{get_version()}"
return f"feast-python-server-{project}-{self._get_version_for_aws()}"

@staticmethod
def _get_version_for_aws():
"""Returns Feast version with certain characters replaced.

This allows the version to be included in names for AWS resources.
"""
return get_version().replace(".", "_").replace("+", "_")


class S3RegistryStore(RegistryStore):
Expand Down
3 changes: 2 additions & 1 deletion sdk/python/feast/infra/feature_servers/aws_lambda/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
from mangum import Mangum

from feast import FeatureStore
from feast.constants import FEATURE_STORE_YAML_ENV_NAME
from feast.feature_server import get_app

# Load RepoConfig
config_base64 = os.environ["FEAST_CONFIG_BASE64"]
config_base64 = os.environ[FEATURE_STORE_YAML_ENV_NAME]
config_bytes = base64.b64decode(config_base64)

# Create a new unique directory for writing feature_store.yaml
Expand Down
4 changes: 4 additions & 0 deletions sdk/python/feast/infra/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ def online_read(
"""
...

def get_feature_server_endpoint(self) -> Optional[str]:
"""Returns endpoint for the feature server, if it exists."""
return None


def get_provider(config: RepoConfig, repo_path: Path) -> Provider:
if "." not in config.provider:
Expand Down