Skip to content

Metrics

A Metric is a time-series aggregation projected exclusively from Events the Definition selects. This chapter defines how Events contribute, how Dimensions classify contributions, and how projection relates to the write that produced the Event.

  • A Metric selects Events with addEvent on MetricBuilder. Only selected Events contribute; Item state never contributes directly.
  • Each selected Event contributes one value. Without a calculation handler the value is 1. A calculation handler receives the Event and returns a number, or null to exclude that Event.
  • A contribution is attributed to the Event’s creation time.
  • A contribution carries the Event, the Item the Event was published against, the Metric PRN and the Workspace.
  • Each Event contributes at most once per Metric. Projecting an Event a second time adds nothing.
  • A Dimension is declared on an App with addMetricDimension and attached to a Metric with addDimension(dimension, position, handler). Positions are 1 to 4, so a Metric holds at most four Dimensions.
  • A Dimension handler receives the Event, the Dimension instance and a read context. It returns an Item, an Identifier string or undefined.
  • A Dimension value is an Item Identifier. A string result must be a valid Identifier (UUID). A handler that returns any other string, returns undefined or throws yields the null Identifier for that Dimension, and the contribution is still written.
  • A Dimension handler may read current Item data. Its result reflects the Items at projection time, not at the Event’s creation time.
  • Projection runs after the write that appended the Event commits. The projector performs it; the write execution does not.
  • Completion of a Mutation, publish or immediate does not imply that the projection of its Events has completed.
  • Each Event is projected once. A projected Event is marked so it is not selected again. An Event whose projection fails is recorded as a projection error and is not projected again automatically.
  • Projection runs under a system context in the Event’s Workspace.
  • A Metric is queried through MetricQueryBuilder with a Metric PRN, a focal Dimension, a period and an interval.
  • A query is opened with an aggregate function: count, sum, average, maximum or minimum. It returns, for the interval, the contribution values aggregated by that function and the count of distinct focal Dimension values, grouped by the Dimensions the query names.
  • A Metric Grant governs who may query the Metric.