-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix push sources and add docs / tests pushing via the python fea…
…ture server (#2561) * bug: Fixing push API endpoint to include a way to specify whether the registry should be looked up from a cache. Adding docs for feature server usage Signed-off-by: Danny Chiao <danny@tecton.ai> * fix Signed-off-by: Danny Chiao <danny@tecton.ai> * prune out unneeded fields in push source Signed-off-by: Danny Chiao <danny@tecton.ai> * prune out unneeded fields in push source Signed-off-by: Danny Chiao <danny@tecton.ai> * prune out unneeded fields in push source Signed-off-by: Danny Chiao <danny@tecton.ai> * fix comment Signed-off-by: Danny Chiao <danny@tecton.ai> * fix comment Signed-off-by: Danny Chiao <danny@tecton.ai> * fix comment Signed-off-by: Danny Chiao <danny@tecton.ai> * fix comment Signed-off-by: Danny Chiao <danny@tecton.ai> * fix generator Signed-off-by: Danny Chiao <danny@tecton.ai> * add data source creator teardown Signed-off-by: Danny Chiao <danny@tecton.ai> * add data source creator teardown Signed-off-by: Danny Chiao <danny@tecton.ai> * update push source to alpha Signed-off-by: Danny Chiao <danny@tecton.ai> * lint Signed-off-by: Danny Chiao <danny@tecton.ai> * lint Signed-off-by: Danny Chiao <danny@tecton.ai> * lint Signed-off-by: Danny Chiao <danny@tecton.ai> * lint Signed-off-by: Danny Chiao <danny@tecton.ai> * lint Signed-off-by: Danny Chiao <danny@tecton.ai>
- v0.42.0
- v0.41.3
- v0.41.2
- v0.41.1
- v0.41.0
- v0.40.1
- v0.40.0
- v0.39.1
- v0.39.0
- v0.38.0
- v0.37.1
- v0.37.0
- v0.36.1
- v0.36.0
- v0.35.0
- v0.34.1
- v0.34.0
- v0.33.1
- v0.33.0
- v0.32.1
- v0.32.0
- v0.31.1
- v0.31.0
- v0.30.2
- v0.30.1
- v0.30.0
- v0.29.0
- v0.28.0
- v0.27.1
- v0.27.0
- v0.26.0
- v0.25.2
- v0.25.1
- v0.25.0
- v0.24.1
- v0.24.0
- v0.23.2
- v0.23.1
- v0.23.0
- v0.22.5
- v0.22.4
- v0.22.3
- v0.22.2
- v0.22.1
- v0.22.0
- v0.21.3
- v0.21.2
- v0.21.1
- v0.21.0
Showing
15 changed files
with
221 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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
121 changes: 121 additions & 0 deletions
121
sdk/python/tests/integration/e2e/test_python_feature_server.py
This file contains 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,121 @@ | ||
import contextlib | ||
import json | ||
from datetime import datetime | ||
from typing import List | ||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from feast.feast_object import FeastObject | ||
from feast.feature_server import get_app | ||
from tests.integration.feature_repos.integration_test_repo_config import ( | ||
IntegrationTestRepoConfig, | ||
) | ||
from tests.integration.feature_repos.repo_configuration import ( | ||
construct_test_environment, | ||
construct_universal_feature_views, | ||
construct_universal_test_data, | ||
) | ||
from tests.integration.feature_repos.universal.entities import ( | ||
customer, | ||
driver, | ||
location, | ||
) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.universal | ||
def test_get_online_features(): | ||
with setup_python_fs_client() as client: | ||
request_data_dict = { | ||
"features": [ | ||
"driver_stats:conv_rate", | ||
"driver_stats:acc_rate", | ||
"driver_stats:avg_daily_trips", | ||
], | ||
"entities": {"driver_id": [5001, 5002]}, | ||
} | ||
response = client.post( | ||
"/get-online-features", data=json.dumps(request_data_dict) | ||
) | ||
|
||
# Check entities and features are present | ||
parsed_response = json.loads(response.text) | ||
assert "metadata" in parsed_response | ||
metadata = parsed_response["metadata"] | ||
expected_features = ["driver_id", "conv_rate", "acc_rate", "avg_daily_trips"] | ||
response_feature_names = metadata["feature_names"] | ||
assert len(response_feature_names) == len(expected_features) | ||
for expected_feature in expected_features: | ||
assert expected_feature in response_feature_names | ||
assert "results" in parsed_response | ||
results = parsed_response["results"] | ||
for result in results: | ||
# Same order as in metadata | ||
assert len(result["statuses"]) == 2 # Requested two entities | ||
for status in result["statuses"]: | ||
assert status == "PRESENT" | ||
results_driver_id_index = response_feature_names.index("driver_id") | ||
assert ( | ||
results[results_driver_id_index]["values"] | ||
== request_data_dict["entities"]["driver_id"] | ||
) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.universal | ||
def test_push(): | ||
with setup_python_fs_client() as client: | ||
initial_temp = get_temperatures(client, location_ids=[1])[0] | ||
json_data = json.dumps( | ||
{ | ||
"push_source_name": "location_stats_push_source", | ||
"df": { | ||
"location_id": [1], | ||
"temperature": [initial_temp * 100], | ||
"event_timestamp": [str(datetime.utcnow())], | ||
"created": [str(datetime.utcnow())], | ||
}, | ||
} | ||
) | ||
response = client.post("/push", data=json_data,) | ||
|
||
# Check new pushed temperature is fetched | ||
assert response.status_code == 200 | ||
assert get_temperatures(client, location_ids=[1]) == [initial_temp * 100] | ||
|
||
|
||
def get_temperatures(client, location_ids: List[int]): | ||
get_request_data = { | ||
"features": ["pushable_location_stats:temperature"], | ||
"entities": {"location_id": location_ids}, | ||
} | ||
response = client.post("/get-online-features", data=json.dumps(get_request_data)) | ||
parsed_response = json.loads(response.text) | ||
assert "metadata" in parsed_response | ||
metadata = parsed_response["metadata"] | ||
response_feature_names = metadata["feature_names"] | ||
assert "results" in parsed_response | ||
results = parsed_response["results"] | ||
results_temperature_index = response_feature_names.index("temperature") | ||
return results[results_temperature_index]["values"] | ||
|
||
|
||
@contextlib.contextmanager | ||
def setup_python_fs_client(): | ||
config = IntegrationTestRepoConfig() | ||
environment = construct_test_environment(config) | ||
fs = environment.feature_store | ||
try: | ||
entities, datasets, data_sources = construct_universal_test_data(environment) | ||
feature_views = construct_universal_feature_views(data_sources) | ||
feast_objects: List[FeastObject] = [] | ||
feast_objects.extend(feature_views.values()) | ||
feast_objects.extend([driver(), customer(), location()]) | ||
fs.apply(feast_objects) | ||
fs.materialize(environment.start_date, environment.end_date) | ||
client = TestClient(get_app(fs)) | ||
yield client | ||
finally: | ||
fs.teardown() | ||
environment.data_source_creator.teardown() |
This file contains 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 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