Repository navigation
feat: Report the materialization window in write-time metrics - #388
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| def _to_utc(ts: Optional[datetime]) -> Optional[datetime]: | ||
| """Return ``ts`` as a tz-aware UTC datetime; naive values are taken as UTC.""" | ||
| if ts is None: | ||
| return None | ||
| if ts.tzinfo is None: | ||
| return ts.replace(tzinfo=timezone.utc) | ||
| return ts.astimezone(timezone.utc) |
There was a problem hiding this comment.
nit: _to_utc re-implements feast.utils.make_tzaware (naive → UTC) and adds an .astimezone(). feature_store.materialize already calls make_tzaware on these same values, so we'd now have two helpers encoding the same rule that could drift apart. Suggest:
return None if ts is None else make_tzaware(ts).astimezone(timezone.utc)There was a problem hiding this comment.
Good call. _to_utc is now your one-liner, so there's only one naive-is-UTC rule. I kept the .astimezone() because make_tzaware leaves aware non-UTC values as they are, and the UTC-8 tests fail without it.
In 9edeb9c.
| """Return ``ts`` as a tz-aware UTC datetime; naive values are taken as UTC.""" | ||
| if ts is None: | ||
| return None | ||
| if ts.tzinfo is None: |
There was a problem hiding this comment.
_to_utc treats naive datetimes as UTC, which mislabels the window on the /materialize path with disable_event_timestamp=True. feature_server.py:440 builds end_date = datetime.now() (naive local time) and start_date = datetime(1970,1,1). On a UTC-8 host the metrics row reports an end_date 8h earlier than the real run end, labelled as UTC. The start_date of 1970 is also misleading, because that path loads all data regardless of window. Should that path use datetime.now(timezone.utc), or leave the window as None when event timestamps are disabled?
There was a problem hiding this comment.
Good catch, but the mislabel happens before _to_utc. FeatureStore.materialize already runs make_tzaware on that naive datetime.now(), so the query end and the registry interval were off by the host offset too. I switched this endpoint and the matching CLI path to utils._utc_now(), the same fix upstream Feast already made, and kept the 1970 start because no engine in our fork reads disable_event_timestamp, so [1970, now) really is the window that gets queried.
In 9edeb9c.
| self.start_date = _to_utc(start_date) | ||
| self.end_date = _to_utc(end_date) |
There was a problem hiding this comment.
start_date/end_date are now tz-aware UTC, but max_event_timestamp is stored raw (naive for e.g. a parquet source with a naive timestamp column). A consumer computing lag as end_date - max_event_timestamp will hit "can't subtract offset-naive and offset-aware datetimes". Suggest normalizing max_event_timestamp with the same _to_utc in observe_event_timestamp so all timestamps in the payload follow one convention.
There was a problem hiding this comment.
Agreed. observe_event_timestamp now goes through the same _to_utc, so max_event_timestamp is tz-aware UTC like the window, whether it comes from a batch or from merged partition stats. This was a real case, because Spark hands us naive values. FSM already treated naive as UTC, so the recorded value and lag stay the same.
In 9edeb9c.
| "start_date": self.start_date, | ||
| "end_date": self.end_date, |
There was a problem hiding this comment.
to_dict() now emits two new keys (start_date, end_date) in every run result. Is the feature-store-materialization consumer / metrics table ready for these? If it builds rows with a fixed schema (Row(**stats), a typed DataFrame, an explicit INSERT), the flush will either fail or silently drop the fields. Since metrics errors are swallowed, the run would look healthy while the rows are lost. The consumer and table schema changes should probably ship alongside this.
There was a problem hiding this comment.
Worth checking. FSM never builds a row from this dict: merge_write_stats copies named keys with .get, and #127 reads start_date/end_date into the existing data_interval_start/data_interval_end columns, using the job window when they're missing. Released FSM simply ignores the new keys, so either deploy order is safe and the table needs no change.
| an accumulator that merged per-partition :meth:`to_dict` outputs across | ||
| executors. The incoming counts are already net (store drops applied | ||
| per partition), so they are summed directly rather than replayed through the | ||
| ``record_*`` methods (which would double-apply the store-drop decrement). |
There was a problem hiding this comment.
merge_from_dict never reads start_date/end_date from the incoming dict. If the driver-side aggregator was built without a window (e.g. the executor-side build_aggregator calls in spark/utils.py:104 and :192 don't pass the new kwargs), a window carried by the merged stats is silently dropped and to_dict()['start_date'] stays None. Suggest filling the window when self.start_date is None, as merge_stats does.
There was a problem hiding this comment.
Fair point. Nothing hits it today, because the executor-side build_aggregator calls are the windowless ones and both driver collectors already carry the task window. merge_from_dict now merges the window with the same min/max rule as merge_stats, so a windowless collector picks it up and the two can't drift.
In 9edeb9c.
| "start_date": _identity("start_date"), | ||
| "end_date": _identity("end_date"), |
There was a problem hiding this comment.
merge_stats keeps the first non-None start_date/end_date, so the result depends on argument order. That contradicts the docstring's "associative, and commutative" claim. Merging [Jan1, Jan2) with [Jan2, Jan3) gives a different answer depending on order, and neither is the actual covered window [Jan1, Jan3). In the Spark AccumulatorParam use case, the result would vary with partition order. Suggest min(start_date) / max(end_date), mirroring how max_event_timestamp is merged.
There was a problem hiding this comment.
Agreed. merge_stats now takes the earliest start_date and the latest end_date, through the same helper as max_event_timestamp, so the result no longer depends on argument order, as the docstring says. Partition order couldn't change the result in practice because executor payloads carry no window, but the code now matches the docstring.
In 9edeb9c.
| @@ -231,7 +231,12 @@ def _materialize_from_offline_store( | |||
|
|
|||
| try: | |||
| collector = build_aggregator( | |||
There was a problem hiding this comment.
The window has to be threaded by hand into every build_aggregator call site (base.get_execution_context plus this direct offline-store path). Any path that is missed, such as a future engine or Ray's _materialize_from_offline_store if it gains metrics, quietly reports a None window. Consider building the collector from the MaterializationTask (e.g. build_aggregator_for_task(task, ...)) so the window can't be forgotten.
There was a problem hiding this comment.
Agreed. I added build_aggregator_for_task(task, ...), and both driver-side sites (get_execution_context, plus this offline-store path, which now takes the task) build their collector through it. The executor-side calls in spark/utils.py stay windowless on purpose, because their partial stats fold into the driver collector, which owns the window.
In 9edeb9c.
…ctors from the task - _to_utc uses make_tzaware, and max_event_timestamp is normalized to UTC like the window. - merge_stats and merge_from_dict take the earliest start_date and latest end_date, so the result no longer depends on merge order. - build_aggregator_for_task builds the driver-side collector from the MaterializationTask. - The /materialize endpoint and `feast materialize --disable-event-timestamp` end the window at the UTC time, not the host's local time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
Each feature view's write-time stats (
MaterializationMetricsAggregator.to_dict(), read withdrain_run_results()) now include two keys:start_date: the start of the window Feast materialized for that feature view runend_date: the end of that windowBoth are tz-aware UTC datetimes. They come from the
MaterializationTaskthe provider gives the compute engine. That means they already include the defaultsmaterialize_incremental()applies (the previous end time, now minus ttl, or one year back) and the timezone handling inmaterialize(). A non-UTC input is converted to UTC, so the instant stays the same.Why
Right now the materialization job works out the incremental start date by copying Feast's
materialize_incremental()rules, and that copy can fall out of sync with Feast. If Feast reports the window it actually used, the job doesn't need to copy those rules.How
start_date/end_date, converts them to UTC and adds them toto_dict().build_aggregatorpasses them through.ComputeEngine.get_execution_context, which covers the local and Spark DAG paths. The Spark engine's offline-store path, which the Expedia provider uses, sets them too.merge_statsandmerge_from_dictboth take the earlieststart_dateand the latestend_date, so the result doesn't depend on merge order.build_aggregator_for_task(task, ...), so a call site can't forget the window. The Spark offline-store path now takes the task._to_utcusesmake_tzaware, andmax_event_timestampis normalized to UTC too, so every timestamp in the stats follows one convention./materializeendpoint andfeast materialize --disable-event-timestampend the window at the UTC time instead of the host's local time, matching upstream Feast. This only changes anything on hosts not running in UTC.merge_statsunionsfields_writtenwith a set for membership, keeping order. The list scan was quadratic in the number of features, which added up to 0.1–2 s on the driver for wide feature views folded over hundreds of Spark partitions.The new keys are additive. Older eg-feast versions such as 0.9.19 don't emit them, so consumers should treat them as optional.
Testing
build_aggregatorFeatureStore.materialize()andmaterialize_incremental()through the local engine, both the first run (start from ttl) and a later run (start from the previous end)max_event_timestamp, and the UTC end on the/materializeand CLI pathspytest tests/unit/test_materialization_metrics.py tests/unit/infra/compute_enginespasses in the default, America/Los_Angeles and Asia/Kolkata time zones (Ray tests not run locally).ruff checkandruff format --checkare clean.mypy feastreports the same results as master.🤖 Generated with Claude Code