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

Kafka producer should raise an exception when it fails to connect to broker #636

Merged
merged 4 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions sdk/python/feast/loaders/abstract_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ def flush(self, timeout: Optional[int]):
Returns:
int: Number of messages still in queue.
"""
return self.producer.flush(timeout=timeout)
messages = self.producer.flush(timeout=timeout)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to fail fast using produce() callbacks rather than wait for the timeout/queue to clear.

if self.error_count:
raise Exception(self.last_exception)
if messages:
raise Exception("Not all Kafka messages are successfully delivered.")
return messages

def _delivery_callback(self, err: str, msg) -> None:
"""
Expand Down Expand Up @@ -200,7 +205,12 @@ def flush(self, timeout: Optional[int]):
KafkaTimeoutError: failure to flush buffered records within the
provided timeout
"""
return self.producer.flush(timeout=timeout)
messages = self.producer.flush(timeout=timeout)
if self.error_count:
raise Exception(self.last_exception)
if messages:
raise Exception("Not all Kafka messages are successfully delivered.")
return messages


def get_producer(
Expand Down
32 changes: 32 additions & 0 deletions sdk/python/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,38 @@ def test_feature_set_ingest_success(self, dataframe, test_client, mocker):
# Ingest data into Feast
test_client.ingest("driver-feature-set", dataframe)

@pytest.mark.parametrize(
"dataframe,test_client,exception",
[(dataframes.GOOD, pytest.lazy_fixture("client"), Exception)],
)
def test_feature_set_ingest_throws_exception_if_kafka_down(
self, dataframe, test_client, exception, mocker
):

test_client.set_project("project1")
driver_fs = FeatureSet(
"driver-feature-set",
source=KafkaSource(brokers="localhost:4412", topic="test"),
)
driver_fs.add(Feature(name="feature_1", dtype=ValueType.FLOAT))
driver_fs.add(Feature(name="feature_2", dtype=ValueType.STRING))
driver_fs.add(Feature(name="feature_3", dtype=ValueType.INT64))
driver_fs.add(Entity(name="entity_id", dtype=ValueType.INT64))

# Register with Feast core
test_client.apply(driver_fs)
driver_fs = driver_fs.to_proto()
driver_fs.meta.status = FeatureSetStatusProto.STATUS_READY

mocker.patch.object(
test_client._core_service_stub,
"GetFeatureSet",
return_value=GetFeatureSetResponse(feature_set=driver_fs),
)

with pytest.raises(exception):
test_client.ingest("driver-feature-set", dataframe)

@pytest.mark.parametrize(
"dataframe,exception,test_client",
[
Expand Down