FuseRule β‘
FuseRule is a high-performance, developer-first rule engine built for the cloud-native ecosystem. It leverages Apache Arrow and DataFusion to provide a lightning-fast, SQL-expressive core for real-time data auditing and event processing.
Designed as an Infrastructure Primitive, FuseRule decouples its deterministic core from pluggable "edges" like persistence, evaluation engines, and notification agents.
π Features
- β‘ Arrow-Native: Zero-copy columnar data processing for maximum performance
- π SQL-Powered Rules: Write complex predicates using standard SQL expressions
- ποΈ Infrastructure-First: Decoupled core with swappable traits for
StateStore,RuleEvaluator, andAgent - π Real-Time Observability: Returns machine-readable
EvaluationTracelogs for every ingestion - π Zero-Downtime Reloading: Hot-swap rules and agents via
SIGHUPwithout restarting the daemon - π Cloud-Native Metrics: Built-in Prometheus-formatted telemetry
- π Stateful Transitions: Built-in state management for
ActivatedandDeactivatedtransitions - πͺ Time Windows: Sliding time windows for aggregate functions (AVG, COUNT, SUM)
- π API Key Authentication: Secure endpoints with configurable API keys
- π¦ Rate Limiting: Built-in rate limiting for ingestion endpoints
- π‘ Multiple Ingestion Sources: HTTP, Kafka, and WebSocket support
- π¨ Action Templates: Handlebars templating for custom webhook payloads
- π Interactive Debugging: REPL and step-through debugger for rule development
π¦ Installation
As a Library
Add to your Cargo.toml:
[]
= "0.1.0"
As a Binary
π― Quickstart
1. Create a Configuration File
Create fuse_rule_config.yaml:
engine:
persistence_path: "fuserule_state"
ingest_rate_limit: 1000 # requests per second
api_keys:
- "sk_live_abc123..."
schema:
- name: "price"
data_type: "float64"
- name: "symbol"
data_type: "utf8"
- name: "volume"
data_type: "int32"
agents:
- name: "logger"
type: "logger"
- name: "slack-webhook"
type: "webhook"
url: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
template: |
{
"text": "π¨ {{rule_name}} triggered!",
"symbol": "{{matched_data.0.symbol}}",
"price": "{{matched_data.0.price}}"
}
rules:
- id: "high_price_alert"
name: "High Price Alert"
predicate: "price > 1000"
action: "slack-webhook"
version: 1
enabled: true
state_ttl_seconds: 3600 # Expire state after 1 hour
- id: "volume_spike"
name: "Volume Spike"
predicate: "AVG(volume) > 10000"
action: "logger"
window_seconds: 60 # 60-second sliding window
version: 1
enabled: true
2. Start the Server
3. Ingest Data
4. Check Rule States
# Get all rule states
# Get specific rule state
π Usage as a Library
Basic Example
use ;
use ;
use ;
use RecordBatch;
use Arc;
async
Programmatic Rule Management
use ;
// Add a rule programmatically
let rule = Rule ;
engine.add_rule.await?;
// Update a rule
engine.update_rule.await?;
// Toggle rule
engine.toggle_rule.await?;
ποΈ Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FuseRule Engine β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Ingest βββββΆβ Evaluate βββββΆβ Activate β β
β β Sources β β Rules β β Agents β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β β β β
β β β β β
β βΌ βΌ βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Arrow RecordBatch (Zero-Copy) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β State β β Windows β β Metrics β β
β β Store β β Buffers β β (Prom) β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Design Philosophy: "Hard Core, Soft Edges"
FuseRule is built on the philosophy that the core logic of a rule engine should be a "boring," deterministic primitive, while the integration points (Ingress, Persistence, Notifications) should be flexible and pluggable.
Core (Hard):
- Rule evaluation logic
- State transitions
- Window management
- Metrics collection
Edges (Soft):
StateStoretrait (Sled, Redis, etc.)RuleEvaluatortrait (DataFusion, custom SQL engines)Agenttrait (Webhooks, Loggers, custom actions)- Ingestion sources (HTTP, Kafka, WebSocket)
π§ CLI Commands
Run Server
Validate Rules
# Validate all rules in config
# Validate specific predicate
Interactive REPL
Rule Debugger
π‘ API Endpoints
Public Endpoints
GET /status- Server statusGET /health- Health check with engine statsGET /metrics- Prometheus metrics
Protected Endpoints (Require X-API-Key header)
Rule Management
GET /rules- List all rulesPOST /api/v1/rules- Create new rulePUT /api/v1/rules/:id- Update rulePATCH /api/v1/rules/:id- Partial update (e.g., enable/disable)DELETE /api/v1/rules/:id- Delete rulePOST /api/v1/rules/validate- Validate rule predicate
State Management
GET /api/v1/state- Get all rule statesGET /api/v1/state/:rule_id- Get specific rule state
Data Ingestion
POST /ingest- Ingest JSON data (rate-limited)
π Monitoring
FuseRule exposes Prometheus metrics at /metrics:
fuserule_batches_processed_total- Total batches ingestedfuserule_activations_total- Total rule activationsfuserule_agent_failures_total- Total agent failuresfuserule_evaluation_duration_seconds- Evaluation latency histogramfuserule_rule_evaluations_total{rule_id}- Per-rule evaluation countfuserule_rule_activations_total{rule_id}- Per-rule activation count
π Ingestion Sources
HTTP (Default)
Kafka
Configure in fuse_rule_config.yaml:
sources:
- type: "kafka"
brokers:
topic: "events"
group_id: "fuserule"
auto_commit: true
WebSocket
Configure in fuse_rule_config.yaml:
sources:
- type: "websocket"
bind: "0.0.0.0:3031"
max_connections: 1000
Connect and send JSON:
const ws = ;
ws.;
π¨ Action Templates
Use Handlebars templates for custom webhook payloads:
agents:
- name: "custom-webhook"
type: "webhook"
url: "https://api.example.com/webhook"
template: |
{
"alert": "{{rule_name}}",
"timestamp": "{{timestamp}}",
"data": {{#each matched_data}}
{
"price": {{price}},
"symbol": "{{symbol}}"
}{{#unless @last}},{{/unless}}
{{/each}},
"count": {{count}}
}
π§ͺ Testing
Unit Tests
Integration Tests
Property-Based Tests
π Documentation
- Architecture Guide - Deep dive into design
- API Documentation - Full API reference (when published)
- Local API Documentation: Generate and view locally with:
This will build and open the documentation in your browser attarget/doc/arrow_rule_agent/index.html - Examples - Code examples
π€ Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
π License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
π Acknowledgments
- Built on Apache Arrow for zero-copy data processing
- Powered by DataFusion for SQL evaluation
- Inspired by the "Hard Core, Soft Edges" philosophy