Schedule icon
CLI icon
Script icon
Process icon
Log icon
Switch icon
SlackIncomingWebhook icon
Fail icon

Malloy Semantic Metric Drift and KPI Anomaly Sentinel

Audit semantic metrics with Malloy and DuckDB in Kestra, detect KPI drift against baseline thresholds, and alert Slack to prevent reporting corruption.

Categories
Data

Automated semantic data quality sentinel that executes reusable Malloy modeling queries over DuckDB on a recurring schedule to evaluate key performance indicators (KPIs), calculate statistical metric drift against historical baselines, and trigger alerts on critical deviations.

How it works

  1. A schedule trigger activates every six hours to initiate the semantic metric drift evaluation across the target dataset.
  2. The io.kestra.plugin.malloy.CLI task compiles and executes an embedded Malloy model against DuckDB, aggregating target business metrics across input partitions.
  3. A lightweight Python script interrogates the computed aggregation output, calculates percentage drift relative to the configured baseline, and emits typed status variables.
  4. A Pebble classification expression categorizes metric health into NORMAL, DRIFT_WARNING, or CRITICAL_ANOMALY.
  5. A Switch flow control task routes execution according to the evaluated status:
    • NORMAL: Logs an informational audit record confirming metric stability within SLA tolerances.
    • DRIFT_WARNING: Records an advisory warning alerting analytics engineers to subtle data shifts before reports break.
    • CRITICAL_ANOMALY: Dispatches a formatted Slack incident alert via webhook with metric values and execution deep links, followed by an execution failure gate to quarantine downstream consumption.
  6. An unconditional final audit task logs the comprehensive evaluation verdict and percentage drift to Kestra's execution history.

What you get

  • Automated semantic metric monitoring catching pipeline data corruptions that row-count checks miss.
  • Reusable data modeling expressing complex analytical measures in concise Malloy syntax rather than brittle SQL queries.
  • Embedded DuckDB execution requiring no external data warehouse or database cluster setup.
  • Tiered severity classification separating benign variations from critical metric drop-offs.
  • Direct Slack notifications delivering actionable context straight to analytics engineering teams.
  • An immutable execution audit trail tracking semantic metric drift trends over time.

Who it's for

  • Analytics Engineers maintaining centralized semantic layers and metric definitions.
  • Data Engineers responsible for data freshness and statistical integrity before reporting runs.
  • BI Developers seeking automated guardrails protecting downstream Looker, Metabase, or Superset dashboards.

Why orchestrate this with Kestra

  • Declarative YAML orchestrates semantic model compilation, Python drift math, and incident notifications in one unified flow.
  • Out-of-the-box secret masking ensures webhook URLs and credentials remain secured during automated runs.
  • Native branching and failure gates prevent corrupted datasets from triggering downstream ETL transformations.
  • Centralized execution timelines provide instant debugging context when diagnosing pipeline data discrepancies.

Prerequisites

  • Docker runner access to execute the default ghcr.io/kestra-io/malloy container image.
  • Network reachability to target dataset URIs (supports HTTP URLs, S3 paths, or local file mounts).

Secrets

  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL used to transmit critical metric drift alerts (required when alerts fire).

Quick start

  1. Configure the SLACK_WEBHOOK_URL secret within your Kestra namespace or environment variables.
  2. Import this blueprint into your Kestra instance under company.analytics.
  3. Run a test execution with default inputs against the public demo dataset to verify metric compilation and clean baseline matching.
  4. Review execution outputs and activate the metric_audit_schedule trigger for continuous monitoring.

How to extend

  • Point dataset_uri to production Parquet files on S3 or Google Cloud Storage to monitor live lakehouse tables.
  • Add multi-dimensional grouping in the Malloy model to detect metric drift across specific regions or tenant cohorts.
  • Chain downstream dbt or warehouse sync workflows that trigger automatically only when semantic metrics pass the drift gate.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.