Skip to content
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
21 changes: 21 additions & 0 deletions sdk/python/feast/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ def build_metrics_flags(metrics_config: Optional[object] = None) -> _MetricsFlag
"Number of entity rows per online feature request",
buckets=(1, 5, 10, 25, 50, 100, 250, 500, 1000),
)
online_features_status_total = Counter(
"feast_online_features_status_total",
"Count of individual feature values by retrieval status per feature view",
["feature_view", "status"],
)

# ---------------------------------------------------------------------------
# Push / write metrics
Expand Down Expand Up @@ -334,6 +339,22 @@ def track_online_store_read(duration_seconds: float):
online_store_read_duration_seconds.observe(duration_seconds)


def track_feature_statuses(
feature_view_name: str, present_count: int, not_found_count: int
):
"""Record the number of PRESENT vs NOT_FOUND feature values for a feature view."""
if not _config.online_features:
return
if present_count > 0:
online_features_status_total.labels(
feature_view=feature_view_name, status="present"
).inc(present_count)
if not_found_count > 0:
online_features_status_total.labels(
feature_view=feature_view_name, status="not_found"
).inc(not_found_count)


def track_transformation(odfv_name: str, mode: str, duration_seconds: float):
"""Record the duration of an on-demand feature view read-path transformation."""
if not _config.online_features:
Expand Down
9 changes: 9 additions & 0 deletions sdk/python/feast/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,15 @@ def _populate_response_from_feature_data(
feat_values[f_idx][out_idx] = feat_val
feat_statuses[f_idx][out_idx] = PRESENT

try:
from feast.metrics import track_feature_statuses

_present = sum(s == PRESENT for row in feat_statuses for s in row)
_not_found = (n_features * output_len) - _present
track_feature_statuses(table.name, _present, _not_found)
except Exception:
pass

for f_idx in range(n_features):
online_features_response.results.append(
GetOnlineFeaturesResponse.FeatureVector(
Expand Down
67 changes: 67 additions & 0 deletions sdk/python/tests/unit/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
materialization_result_total,
online_features_entity_count,
online_features_request_count,
online_features_status_total,
online_store_read_duration_seconds,
push_request_count,
request_count,
request_latency,
track_feature_statuses,
track_materialization,
track_online_features_entities,
track_online_store_read,
Expand Down Expand Up @@ -435,6 +437,71 @@ def test_records_entity_count(self):
assert online_features_entity_count._sum.get() >= before_count + 42


class TestTrackFeatureStatuses:
def test_increments_present_and_not_found(self):
before_present = online_features_status_total.labels(
feature_view="fv_status", status="present"
)._value.get()
before_not_found = online_features_status_total.labels(
feature_view="fv_status", status="not_found"
)._value.get()

track_feature_statuses("fv_status", present_count=3, not_found_count=2)

assert (
online_features_status_total.labels(
feature_view="fv_status", status="present"
)._value.get()
== before_present + 3
)
assert (
online_features_status_total.labels(
feature_view="fv_status", status="not_found"
)._value.get()
== before_not_found + 2
)

@patch("feast.metrics.track_feature_statuses")
def test_populate_response_passes_correct_counts(self, mock_track):
"""Integration: _populate_response_from_feature_data computes and
forwards the right present/not_found counts.

3 entities, 2 features each:
Entity 0 — both present (2 PRESENT)
Entity 1 — missing (2 NOT_FOUND)
Entity 2 — partial (1 PRESENT, 1 NOT_FOUND)
"""
from feast.protos.feast.serving.ServingService_pb2 import (
GetOnlineFeaturesResponse,
)
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
from feast.utils import _populate_response_from_feature_data

now = datetime.now(tz=timezone.utc)
val = ValueProto(int64_val=1)
table = MagicMock()
table.name = "driver_fv"
table.projection.name_to_use.return_value = "driver_fv"
table.projection.name_alias = None
table.projection.name = "driver_fv"

_populate_response_from_feature_data(
requested_features=["feat_a", "feat_b"],
read_rows=[
(now, {"feat_a": val, "feat_b": val}),
(None, None),
(now, {"feat_a": val}),
],
indexes=([0], [1], [2]),
online_features_response=GetOnlineFeaturesResponse(),
full_feature_names=False,
table=table,
output_len=3,
)

mock_track.assert_called_once_with("driver_fv", 3, 3)


class TestTrackPush:
def test_increments_push_counter(self):
before = push_request_count.labels(
Expand Down
Loading