createState Function

Create a blank state for refinement.

Signature

createState(metrics: Array.<Metric>) -> MetricState

Type Definitions

    Metric

    The definition of a metric and the points it should produce.

    Properties

    events: Array.<String>

    Convenience property for defining a type constraint on this metric to make it use only the events specified.

    name: String

    A name to associate with the points produced by this metric. It is worth noting that this name does not have to be unique. You can have multiple metrics generating points with the same "name" but from different sources.

    constraints: Array.<Constraint>

    Constraints that control how and when points are produced. This is the "meat" of the metric and gives you a lot of power in refining raw application events into points.

    dataPoints: Array.<DataPoint>

    Data that the metric point should contain.

    A data point is a map between a name, something that describes the data in the metric point, and a value.

    The name is arbitrary and gives you a chance to rename application event data when it makes sense to do so. The value can be generated in a number of ways as explained in DataPoint.

    Below are sample definitions:

    {
      dataPoints: [
        // point data "a" will contain application event data "aaa"
        {
          name: 'a',
          value: data => data.aaa
        },
        // point data "b" will be true or false based on whether
        // the event data "b" is present
        {
          name: 'b',
          value: DataPoint.flag('b')
        }
      ]
    }

    Passing a String for a DataPoint will cause it to morph into one that simply reflects the value found in the application event data. This is merely a convenience property since it's what you may want to do most of the time. For example:

    {
      dataPoints: [ 'a' ]
    }

    The metric point will contain a data point called "a" that is equal to whatever "a" was set to in the event's data.

    MetricState

    The "metric state" is a transient structure to be used as input for refinement. It contains a reference to the metrics to be used as well as the output of the process; the metric points and, optionally, the adjusted context.

    Properties

    metrics: Array.<Metric>
    points: Array.<MetricPoint>
    context: Any?