In this article, we will learn how to combine results from two separate analytic computations to generate an alert signal. We will break down each stage of the pipeline, from data enrichment to complex analytics and end with custom alerting rules.
Here’s what each stage covers:
Pre-ProcessingHow to enrich events by pulling signal thresholds from a database and associating them with each event.
User-defined function (UDF)How to apply sliding window analytics with an exponential moving average (EMA) function, which calculates trends over time for specific fields.
Aggregate analyticsHow to merge analytics results using JavaScript expressions to create difference calculations, such as the Moving Average Convergence Divergence (MACD) signal.
Alerting RulesHow to set up alerting rules based on calculated thresholds and emit alert events when conditions are met.
By the end, we will understand how to set up a streamlined alerting process using a mix of database enrichment, custom functions and real-time rule evaluation.
Overview
This example demonstrates how two independent computed analytic pipeline results can be combined to generate an alerting signal.
Sreaming analytics pipeline
Stream processing application
Stage 1 - Pre-processing
Enrich event with signal thresholds using the internal in-memory database.
Stage 2 - User defined function
Perform complex analytics using event based sliding windows and a stateful analytic user defined function (exponential mean average).
Stage 3 - Aggregate analytic
Combine the results of the stateful analytics in to two basic difference calculations using Javascript expressions.
Stage 4 - Alerting Rules
Finally once the calculations have been completed perform the final predicate using the having expression to send an alerting event to a downstream system
- enricher:
fields:
company_signals:
by query: "select * from reference_data.nasdaq_companies where Symbol = ?"
query fields: [ symbol ]
with values: [ bid_signal_threshold, ask_signal_threshold ]
using: JouleDB
- user defined function:
ema:
parameters:
ema_factor: 0.33333
fields: [ bid,ask ]
event history: 12
- user defined function:
ema:
parameters:
ema_factor: 0.33333
fields: [ bid,ask ]
event history: 26
- analytic:
expression: ema12_ask - ema26_ask
assign to: macd_ask_signal
- analytic:
expression: ema12_bid - ema26_bid
assign to: macd_bid_signal