Skip to content

Latest commit

 

History

History
111 lines (81 loc) · 4.75 KB

sensor-guide.md

File metadata and controls

111 lines (81 loc) · 4.75 KB

Sensor

Sensors define a set of event dependencies (inputs) and triggers (outputs).

  1. Specifications
  2. Terminology
  3. How it works?
  4. How to pass an event payload to a trigger?
  5. Examples

Sensor


Terminology

  • What is an event dependency?

    A dependency is an event the sensor is waiting to happen. It is defined as "gateway-name:event-source-name".

  • What is a dependency group?

    A dependency group is basically a group of event dependencies.

  • What is a circuit?

    Circuit is any arbitrary boolean logic that can be applied on dependency groups.

  • What is a trigger?

    Refer Triggers.

How it works?

  1. Once the sensor receives an event from gateway either over HTTP or through NATS, it validates the event against dependencies defined in sensor spec. If the event is expected, then it is marked as a valid event and the dependency is marked as resolved.

  2. If you haven't defined dependency groups, sensor basically waits for all dependencies to resolve and then kicks off triggers in sequence. If filters are defined, sensor applies the filter on target event and if events pass the filters, triggers are fired.

  3. If you have defined dependency groups, sensor upon receiving an event evaluates the group to which the event belongs to and marks the group as resolved if all other event dependencies in the group are already resolved.

  4. Whenever a dependency group is resolved, sensor evaluates the circuit defined in spec. If the circuit resolves to true, the triggers are fired. Sensor always waits for circuit to resolve to true before firing triggers.

  5. You may not want to fire all the triggers defined in sensor spec. For that, sensor offers when switch on triggers. Basically when switch is way to control when to fire certain trigger depending upon which dependency group is resolved.

  6. After sensor fires triggers, it transitions into complete state, increments completion counter and initializes it's state back to running and start the process all over again. Any event that is received in-between are stored on the internal queue.

Note: If you don't provide dependency groups and circuit, sensor performs an AND operation on event dependencies.

Filters

There are 3 types of filters that you can apply on event payload:

Type Description
Time Filters the signal based on time constraints
EventContext Filters metadata that provides circumstantial information about the signal.
Data Describes constraints and filters for payload

  • Time Filter

    filters:
            time:
              start: "2016-05-10T15:04:05Z07:00"
              stop: "2020-01-02T15:04:05Z07:00"
    

    Example

  • EventContext Filter

    filters:
            context:
                source:
                    host: amazon.com
                contentType: application/json
    

    Example

  • Data filter

    filters:
            data:
                - path: bucket
                  type: string
                  value: argo-workflow-input
    

    Example

How to pass an event payload to a trigger?

Payload of an event can be passed to any trigger. The way it works is you define parameters on trigger resource in sensor spec. The parameters define list of

  1. src -
    1. event: the name of the event dependency
    2. path: which is basically a key within event payload to look for
    3. value: which is a default value if sensor can't find path in event payload.
  2. dest: destination key within trigger spec whose corresponding value needs to be replaced with value from event payload
  • Pass complete event payload to trigger example
  • Extract particular value from event payload and pass to trigger example

Examples

You can find sensor examples here