Skip to main content

Architecture

jEAP Reaction Observer Service is the consumer and aggregator for the events emitted by the sibling jEAP Reaction Observer library. It stores two kinds of information:

  • identified reactions: the structural trigger/action pattern of a reaction
  • observed reactions: counted occurrences of those reactions within a timeframe

The persisted data is aggregated into a graph-oriented read model served over HTTP.

Runtime flow​

Modules​

ModuleResponsibility
jeap-reaction-observer-domainDomain model, repository interfaces, graph filtering, graph building, aggregation service
jeap-reaction-observer-kafkaKafka listeners that transform incoming Avro events into domain objects
jeap-reaction-observer-micrometerThe metrics the domain defines, as Micrometer counters on the registry of the application
jeap-reaction-observer-persistenceJPA entities, JDBC/JPA repository implementations, Flyway migrations
jeap-reaction-observer-webSpring Boot application, HTTP API, in-memory graph snapshot, scheduling, security, OpenAPI
jeap-reaction-observer-service-testShared event builders and test model objects for integration tests and consumers
jeap-reaction-observer-service-instancePOM-only packaging module for downstream service instances

The Java types of the domain, Kafka, Micrometer, persistence and web modules are internal: they are how the modules work with each other, and they can change incompatibly with a minor version. The changelog names such a change. A service instance and the consumers of the service build on what the other pages describe: the REST API, the consumed events, the configuration properties, the metrics, the builders of jeap-reaction-observer-service-test with the domain types they hand out, and what Testing describes for the tests of a service instance.

Write path​

Reaction definitions​

ReactionIdentifiedEventListener consumes reaction-identified-event messages and stores a Reaction containing:

  • producer system name, normalized to lower case
  • producer component/service name
  • reaction id
  • optional trigger observation
  • zero or more action observations
  • identification timestamp
  • reaction model version of the emitter

The incoming event payload can contain a full reaction, trigger-only payload, or action-only payload; all three forms are handled.

Every observation is stored with its type and FQN as reported, whatever the type: event and command (messages), http_request (HTTP operations), and any type the service does not know yet. The type and FQN of an interface can be up to 1024 characters long; the library cuts FQNs at 512 characters.

A reaction is created by its first identification. A later identification of a known reaction keeps its structure and identification timestamp and only replaces the reaction model version, which is stored for information only. Events that predate the field count as reaction model version 1.

There is no reaction model version below 1. An event that reports one is rejected: the listener fails with a permanent error for the error handling (error code INVALID_REACTION_MODEL_VERSION), and nothing of the event is stored. Processing such an event again does not help, its emitter has to be corrected. The library cannot report such a version; the check is there because the service takes the reaction model version of a count as evidence for what the emitter observed (see Lineage and status).

When a reaction is identified for the first time concurrently, exactly one reaction is created and the other events fail when their transaction commits, so they end up in the error handling. Processing such an event again finds the reaction. Over Kafka this is rare, as the reaction id is the message key and the identifications of a reaction are processed one after the other.

Observed counts​

ReactionsObservedEventListener consumes reactions-observed-event messages and stores ObservedReaction records with:

  • component name from the event publisher service
  • reaction id
  • timeframe start/end
  • count
  • reaction model version of the emitter, which applies to all counts of the event
  • unidentified actions, which are actions the emitter detects while observing a reaction but cannot identify: the minimum number of different unidentified actions per observed reaction, the number of times the reaction was observed with at least one unidentified action, and the total number of unidentified actions

The reaction model version and the unidentified actions are stored per count. The daily aggregation uses the reaction model version (see Aggregation and graph building), not the unidentified actions. Events that predate these fields count as reaction model version 1 without unidentified actions. An event that reports a reaction model version below 1 is rejected as a whole, as described for the reaction definitions: none of its counts is stored.

Persistence is idempotent per event idempotence id: ObservedReactionRepositoryImpl saves a batch only if no row with the same idempotence id exists yet.

A count of a reaction id that has not been identified is skipped, and the other counts of the event are saved. The skipped counts are logged and counted in reaction_observer_service_unknown_reaction_counts_total (see Metrics). The known reactions of an event are looked up with one query per component.

Counts that arrive before their reaction is identified are lost

Until 12.17, one unknown reaction id failed the whole reactions-observed-event, which ended up in the error handling - and since an instance reports every five minutes until it restarts, so did every later count of that instance. Since 12.18, such a count is dropped instead. This happens when counts are processed before the identification of their reaction, for example while a backlog is consumed after a deployment of the service. The metric shows how often it happens.

Persistence model​

Flyway creates four main tables over time:

  • reaction for identified reactions
  • observation_property for trigger/action properties
  • observed_reaction for raw timeframe-based counts
  • observed_reactions_aggregated for daily aggregated counts

Later migrations add ShedLock support, multi-action storage, the producer system name, an idempotence index, an interface table used to normalize trigger/action interface definitions, and longer interface columns (type and fqn up to 1024 characters, observation ids up to 4096, as an id embeds its encoded FQN), the reaction model version and unidentified actions, the reaction model version of a daily count, and a longer reaction id (up to 2048 characters): the id of a reaction with a trigger starts with the id of the trigger, so that a reaction triggered by an HTTP request has an id of up to 1582 characters. The length of the column is not the only limit: component and reaction id together have to fit into one entry of the unique index on both, which PostgreSQL limits to about 2700 bytes. The longest id of 1582 bytes leaves about 1100 bytes for the name of the component; values that fit both columns can still be rejected by the index.

Aggregation and graph building​

ScheduledTasksService coordinates recurring jobs. The three that write hold a ShedLock, so exactly one instance performs them:

  • aggregate yesterday's raw observations into observed_reactions_aggregated
  • delete raw observed_reaction rows whose timeframe starts before today
  • delete aggregated rows older than the configured statistics window

The graph refresh does not hold one, and must not:

  • rebuild the in-memory graph on a schedule and once at startup

The graph is held per JVM in GraphHolder, and rebuilding it writes nothing - it reads the reactions and the aggregated observations and replaces a field. A lock would therefore let one instance refresh and leave every other one serving the graph it built while it started, for as long as that instance lives. With more than one replica that is a stale answer, and - since the entity tags of the API are derived from the graph - an index from one replica and content from another that disagree. The startup refresh has always run unlocked on every instance for the same reason.

A refresh also builds the snapshot the API answers from: the graph plus the fingerprint of every subgraph that can be asked for. That is what lets an index be a lookup rather than an extraction of every subgraph, and a conditional request be answered without extracting, serializing or hashing anything - see REST API.

The daily aggregation adds up the counts of a day per reaction. The daily count gets the highest reaction model version among the counts of the day that were greater than zero, and none when the day has no such count: an emitter that reports a reaction with a count of zero has not executed it. The model version has to be taken at this point, as the single counts are deleted afterwards.

ReactionGraphBuilderService builds the graph with every refresh:

  1. It reads the statistics of each reaction with a daily count since fromDate, in one query: the median of the daily counts, the last day with a count greater than zero, the highest reaction model version of the window, the one of that last day, and whether every counted day has a model version.
  2. It reads the registered reactions and keeps those with statistics. The reactions of the graph are those the statistics were read for, so every reaction has its median. ReactionRepositoryImpl hands over each reaction with its trigger and its actions, each with its observation id and its interface: the id, the type and the FQN of the normalized InterfaceEntity row. The persistence does not know the graph.
  3. It derives the lineage of these reactions: the edges to their predecessors and which reactions are superseded (see Lineage and status).
  4. It creates the reaction nodes, one node per interface these reactions refer to, and the edges. The reaction nodes come first and the interface nodes after them, each in the order of their ids, whatever order the reactions are read in: where two stored interfaces are the same message type and variant, the graph of that message in the API v1 is the one of the first. The edges have a fixed order as well - by reaction, the actions of a reaction by their ids, the predecessor edges by the ids of their ends. A subgraph is cut from the graph in a fixed way, too: the reactions in the order of the graph and the interfaces in the order of the edges that lead to them, the graph of a message or of an interface in the order its nodes are found from it. So every instance of the service answers the same graph in the same order.
    • reaction nodes represent producer components within systems, with their statistics and status
    • trigger edges connect an interface -> reaction
    • action edges connect a reaction -> interface
    • predecessor edges connect a reaction -> reaction

Lineage and status are derived before any reaction node is created, because nodes and edges hold the same Reaction records: enriching only one of the two would leave records that no longer compare equal, and GraphExtractor matches an edge to its node by value.

InterfaceNodeFactory creates the interface node from the observation type and FQN, with one parser per type:

TypeNodeFQN
event, commandMessagemessageType or messageType/variant
http_requestHttpOperationprovider METHOD pattern, split at the first two spaces
any otherGenericInterfacekept as it is

The kind of node is a hint for how to present it; the identity of an interface remains its type and FQN. If the parser of a known type cannot parse an FQN, the factory does not fail: the interface becomes a GenericInterface and is counted, once per interface and instance, in reaction_observer_service_unparsable_interfaces_total (see Metrics). A single interface reported wrongly therefore cannot break the graph of the whole landscape.

The domain only says what is counted, with the interface ReactionObserverMetrics. The counters are in the module jeap-reaction-observer-micrometer, which the web module adds: neither the domain nor the persistence depends on micrometer-core. The service does not start without an implementation of the interface.

Lineage and status​

When a component moves to a later reaction model version, the library reports the same behaviour as a new reaction, and until the old one falls out of the statistics window the same behaviour is in the graph twice. The service connects the two with a predecessor edge and marks the earlier one as presumably superseded. What this means for a consumer of the API v2 is described in REST API; this section describes how it is derived (Lineage).

The catalogue of observation types (ObservationTypeCatalog) says from which reaction model version on the library observes each type, and up to which model version this is confirmed:

TypeObserved from model version
event, command1
http_request2

The released model version is 2. The catalogue is a constant and maintained by hand, on purpose: a type may only be added, and the released model version only be raised, for a model version that is additive:

  1. it only makes new types visible, and the ids of the observations visible before stay the same,
  2. it groups observations into reactions as before - in particular, an action without a trigger still is a reaction of its own,
  3. its new actions do not push actions visible before out of a limit of the library.

A model version that only adds types then needs nothing but an entry here. One that changes ids or the grouping needs a rule of its own.

Earlier views. For a reaction R' with a trigger, the service asks what a model version below a threshold t would have reported for the same execution. The thresholds of R' are the model versions above 1 from which one of its types is observed, today at most one: 2, if it has an http_request. Every observation whose type is observed from t on is left out:

R'Earlier views below 2
E → {A1, HTTP call}E → {A1}
E → {HTTP call}E without actions
HTTP request → {A1, A2}→ A1 and → A2
HTTP request → {HTTP call}none
E → {A1}, → HTTP callnone: no threshold, or no trigger

Without its trigger, a reaction leaves one view per remaining action, as the library reports an action outside of a trigger as a reaction of its own. This is the one place where the service reproduces a rule of the library.

Predecessor edge. There is an edge from R' to R if all of this holds:

  • R has exactly the structure of an earlier view of R' below a threshold t: the same component, the same trigger or none, and the same set of actions. Two observations are the same if they have the same observation id and the same interface; the ids are compared as a whole and never taken apart. Several stored reactions with that structure all get the edge.
  • Both reactions only have types of the catalogue, and both have a daily count greater than zero within the window.
  • Every daily count of R that is greater than zero has a model version, and the highest one is below t. A model version from t on that counted R reported an execution with exactly this structure: R then is a variant of its own. A day without a model version could be such a count.
  • The highest model version of R' is known, at least the highest threshold of R' and at most the released one. The upper limit keeps a model version that is not confirmed to be additive out; the lower one an emitter that reports what its model version does not observe. A day of R' without a model version does not matter here.

Status. R is superseded if there is an edge from some R' to R and R' was last observed on a later day than R. Counts are never compared by their size - model version 2 drops executions with a failed call, so the numbers of the two forms are not comparable - only days are.

Neither edges nor status are stored, and there is no parameter: the same data and the same start of the window give the same graph on every instance, and a corrected rule applies to the whole window with the next version of the service. A refresh logs the number of predecessor edges and of superseded reactions.

Existing data. The migration that adds the model version to the daily counts sets it to 1 for the existing days with a count greater than zero of every component without a trace of a model version above 1. Such a component is taken to have counted its days with model version 1. A trace is a reaction of the component

  • that was last identified by a model version above 1, or
  • that has a single count a model version above 1 reported. The single counts carry their model version, and when the migration runs, those of the current day are not deleted yet, nor those of the day before until the nightly housekeeping, or
  • that has a trigger or an action of a type model version 1 does not observe, which is every type but event and command. The library identifies such a reaction only from model version 2 on, and reactions are never deleted, so this trace lasts. It counts whatever model version is stored with the reaction: a reaction stored before the service recorded the model version has a 1 until it is identified again.

The days of all other components stay without a model version, and no edge leads to a reaction counted on such a day until the day has left the window.

The trace is missing for a component that counted with model version 2 without ever reporting a reaction with an HTTP request, whose reactions were all identified last by an instance with model version 1, e.g. after a rollback or while instances of both model versions run, and of which no single count of a model version above 1 is left. Its existing days get a 1 although model version 2 counted them. This has no effect as long as the component reports no reaction with an HTTP request. Afterwards a variant that model version 2 counted before the migration can be superseded, until model version 2 counts it again or its days have left the window.

Operating the service.

  • A daily count aggregated by a version of the service before 12.30 has no model version. Do not deploy while the daily aggregation runs (data-aggregation-cron-expression, 01:00 by default), and fix a problem of this version with a new version rather than by rolling the service back overnight: for every reaction counted on a day aggregated by the earlier version, no edge leads to it until that day has left the window.
  • Deploy this version before the components of an environment move to reaction model version 2. For a component with a trace of model version 2, the migration leaves the existing days without a model version (see above), and no edge leads to its reactions counted before the deployment until those days have left the window.

Known limits.

  • A valid variant with exactly the structure of an earlier view is superseded until the later model version has counted it (see REST API).
  • A change of a name within the same model version is not connected: both reactions stay in the graph until the old one has left the window.
  • The earlier views assume that an HTTP request was the outermost trigger of its thread. The reports do not show a trigger handled within another one, so the service cannot check this. Where it does not hold, the earlier reaction gets no edge, and a reaction of another flow of the component that has the structure of the earlier view can be taken for the predecessor (see REST API).
  • The limits of the library apply before the service sees anything: a reaction the library does not report is missing with its edges, and a reaction model version 2 counted without a call it did not observe counts as a variant of its own.
  • The system of a reaction is stored with its first identification and not updated. If a component was assigned to another system since, an edge between its reactions is in neither of the two system graphs.

Read path​

GraphHolder stores the current graph in memory: the full graph with every kind of interface node, and the view of it the API v1 serves, which only has message nodes (see REST API). GraphController serves, from that view:

  • the full graph
  • a graph filtered to one system
  • a graph filtered to one component
  • one subgraph per variant of a message type

GraphV2Controller serves the API v2 from the full graph, with every kind of interface (see REST API):

  • the full graph
  • a graph filtered to one system
  • a graph filtered to one component
  • the graph of one interface: every reaction that has it as its trigger or as one of its actions

Each response includes a fingerprint produced by GraphFingerprintCalculator from canonical JSON so consumers can detect changes. The fingerprints and indexes of both API versions are computed once per refresh and kept in the same snapshot, each over the representation its version serves.

The repository also exposes supporting lookup/statistics endpoints for known systems, known components, and the last observation date per component. This API shape matches the service's role as an internal source for system-behaviour tooling.