Skip to content

Commit 95fdb19

Browse files
authored
feat: Add possibility to define feature_store.yaml path with env variable (#3231)
* Add possibility to define feature_store.yaml path with environment variable Signed-off-by: arcabucero <arcabucero@gmail.com> * Add possibility to define feature_store.yaml path with environment variable for aws and lambda_engine Signed-off-by: arcabucero <arcabucero@gmail.com> * Add test for overriding feature_store.yaml path with environment variable Signed-off-by: arcabucero <arcabucero@gmail.com> Signed-off-by: arcabucero <arcabucero@gmail.com>
1 parent d7d33c9 commit 95fdb19

File tree

7 files changed

+40
-4
lines changed

7 files changed

+40
-4
lines changed

sdk/python/feast/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def cli(
9999
ctx.obj["FS_YAML_FILE"] = (
100100
Path(feature_store_yaml).absolute()
101101
if feature_store_yaml
102-
else ctx.obj["CHDIR"] / "feature_store.yaml"
102+
else utils.get_default_yaml_file_path(ctx.obj["CHDIR"])
103103
)
104104
try:
105105
level = getattr(logging, log_level.upper())

sdk/python/feast/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
# feature_store.yaml environment variable name for remote feature server
2424
FEATURE_STORE_YAML_ENV_NAME: str = "FEATURE_STORE_YAML_BASE64"
2525

26+
# feature_store.yaml path environment variable name
27+
FEAST_FS_YAML_FILE_PATH_ENV_NAME: str = "FEAST_FS_YAML_FILE_PATH"
28+
2629
# Environment variable for registry
2730
REGISTRY_ENV_NAME: str = "REGISTRY_BASE64"
2831

sdk/python/feast/feature_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def __init__(
160160
self.config = load_repo_config(self.repo_path, fs_yaml_file)
161161
else:
162162
self.config = load_repo_config(
163-
self.repo_path, Path(self.repo_path) / "feature_store.yaml"
163+
self.repo_path, utils.get_default_yaml_file_path(self.repo_path)
164164
)
165165

166166
registry_config = self.config.get_registry_config()

sdk/python/feast/infra/aws.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from colorama import Fore, Style
1010

11+
from feast import utils
1112
from feast.constants import (
1213
AWS_LAMBDA_FEATURE_SERVER_IMAGE,
1314
AWS_LAMBDA_FEATURE_SERVER_REPOSITORY,
@@ -113,7 +114,10 @@ def _deploy_feature_server(self, project: str, image_uri: str):
113114

114115
if not self.repo_config.repo_path:
115116
raise RepoConfigPathDoesNotExist()
116-
with open(self.repo_config.repo_path / "feature_store.yaml", "rb") as f:
117+
118+
with open(
119+
utils.get_default_yaml_file_path(self.repo_config.repo_path), "rb"
120+
) as f:
117121
config_bytes = f.read()
118122
config_base64 = base64.b64encode(config_bytes).decode()
119123

sdk/python/feast/infra/materialization/aws_lambda/lambda_engine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pydantic import StrictStr
1111
from tqdm import tqdm
1212

13+
from feast import utils
1314
from feast.batch_feature_view import BatchFeatureView
1415
from feast.constants import FEATURE_STORE_YAML_ENV_NAME
1516
from feast.entity import Entity
@@ -137,7 +138,7 @@ def __init__(
137138
)
138139
repo_path = self.repo_config.repo_path
139140
assert repo_path
140-
feature_store_path = repo_path / "feature_store.yaml"
141+
feature_store_path = utils.get_default_yaml_file_path(repo_path)
141142
self.feature_store_base64 = str(
142143
base64.b64encode(bytes(feature_store_path.read_text(), "UTF-8")), "UTF-8"
143144
)

sdk/python/feast/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import os
12
import typing
23
from collections import defaultdict
34
from datetime import datetime
5+
from pathlib import Path
46
from typing import Dict, List, Optional, Tuple, Union
57

68
import pandas as pd
@@ -9,6 +11,7 @@
911
from dateutil.tz import tzlocal
1012
from pytz import utc
1113

14+
from feast.constants import FEAST_FS_YAML_FILE_PATH_ENV_NAME
1215
from feast.entity import Entity
1316
from feast.protos.feast.types.EntityKey_pb2 import EntityKey as EntityKeyProto
1417
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
@@ -51,6 +54,14 @@ def maybe_local_tz(t: datetime) -> datetime:
5154
return t
5255

5356

57+
def get_default_yaml_file_path(repo_path: Path) -> Path:
58+
if FEAST_FS_YAML_FILE_PATH_ENV_NAME in os.environ:
59+
yaml_path = os.environ[FEAST_FS_YAML_FILE_PATH_ENV_NAME]
60+
return Path(yaml_path)
61+
else:
62+
return repo_path / "feature_store.yaml"
63+
64+
5465
def _get_requested_feature_views_to_features_dict(
5566
feature_refs: List[str],
5667
feature_views: List["FeatureView"],

sdk/python/tests/unit/cli/test_cli.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import os
12
import tempfile
23
from contextlib import contextmanager
34
from pathlib import Path
45
from textwrap import dedent
6+
from unittest import mock
57

68
from assertpy import assertpy
79

@@ -85,6 +87,21 @@ def test_3rd_party_registry_store_with_fs_yaml_override() -> None:
8587
assertpy.assert_that(return_code).is_equal_to(0)
8688

8789

90+
def test_3rd_party_registry_store_with_fs_yaml_override_by_env_var() -> None:
91+
runner = CliRunner()
92+
93+
fs_yaml_file = "test_fs.yaml"
94+
with setup_third_party_registry_store_repo(
95+
"foo.registry_store.FooRegistryStore", fs_yaml_file_name=fs_yaml_file
96+
) as repo_path:
97+
custom_yaml_path = os.path.join(repo_path, fs_yaml_file)
98+
with mock.patch.dict(
99+
"os.environ", {"FEAST_FS_YAML_FILE_PATH": custom_yaml_path}, clear=True
100+
):
101+
return_code, output = runner.run_with_output(["apply"], cwd=repo_path)
102+
assertpy.assert_that(return_code).is_equal_to(0)
103+
104+
88105
@contextmanager
89106
def setup_third_party_provider_repo(provider_name: str):
90107
with tempfile.TemporaryDirectory() as repo_dir_name:

0 commit comments

Comments
 (0)