Chronicle.Discovery.DriftDetector (cratis_chronicle v3.16.1)

Copy Markdown View Source

Compares a discovery report with what the kernel already knows, before registration.

Three kinds of drift are detected:

  • :schema_changed_without_generation — a registered event type generation's stored schema no longer has the same coarse shape (see Chronicle.Discovery.EventSchemaShape) as the module that currently declares it — its struct changed without a bumped :generation.
  • :observer_missing_from_code — the kernel has a client-owned reactor, reducer or projection/read-model observer on the event-log sequence whose id is no longer declared by any current artifact. Always :info: an event store can be shared by several clients, and their observers are also client-owned, so this is evidence only, never a reason to fail startup.
  • :observer_event_types_changed — a still-declared observer's handled event type ids no longer match what the kernel has recorded for it.

Does not decide what to do about a finding — drift_policy on Chronicle.Client and Chronicle.Registration.Coordinator do that.

Summary

Functions

Detects likely artifact identity drift for the given report.

Functions

detect(channel, report, opts)

@spec detect(term(), Chronicle.Discovery.Report.t(), keyword()) ::
  {:ok, [Chronicle.Discovery.Drift.t()]} | {:error, term()}

Detects likely artifact identity drift for the given report.

opts requires :event_store and accepts :namespace (default "Default"). Returns {:ok, findings} (possibly empty) or {:error, reason} when the kernel could not be reached — an indeterminate result, never to be treated the same as a clean one.

The check makes one AllEventTypes call, then AllEventTypeGenerations only for event types whose local generation is not the kernel's latest (bounded-parallel), all within a total deadline (5 seconds, :deadline in milliseconds) after which it returns {:error, :timeout}. A raise inside the check is returned as {:error, {:exception, exception}}.

:fetch_all_event_types_fun, :fetch_event_type_generations_fun and :fetch_observers_fun are test-only seams replacing the real kernel calls; production code never passes them.