Script icon
If icon
SlackIncomingWebhook icon
Log icon
Labels icon
Schedule icon

ClickHouse Dictionary Memory Overflow Sentinel

Audits ClickHouse external dictionaries for excessive RAM consumption, alerting OLAP teams on Slack before MEMORY_LIMIT_EXCEEDED errors occur.

Categories
DataInfrastructure

This blueprint acts as an automated memory governor for ClickHouse analytical databases. Scheduled hourly, it queries system.dictionaries across cluster nodes, evaluates bytes_allocated for loaded external dictionaries, flags failed or oversized in-memory structures, and delivers actionable tuning alerts to Slack before memory pressure triggers query failures or kernel out-of-memory kills.

How it works

  1. Hourly Scheduled Audit: The hourly_dict_memory_audit trigger (io.kestra.plugin.core.trigger.Schedule) fires at the top of every hour.
  2. ClickHouse System Dictionary Query: The audit_dictionary_memory task (io.kestra.plugin.scripts.python.Script) queries system.dictionaries via HTTP interface to measure memory allocation and load status per dictionary.
  3. Condition Gate: The check_memory_threshold flowable task (io.kestra.plugin.core.flow.If) branches based on whether any dictionary exceeded the configured warning threshold.
  4. Slack Alert Dispatch: When memory bloat or load failure occurs, notify_slack_olap (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) dispatches an urgent incident card with layout tuning recommendations.
  5. Healthy Confirmation: When all dictionaries remain within safe thresholds, log_dictionaries_healthy records confirmed status.
  6. Manifest Export: The export_dict_manifest task tags the execution with searchable status labels.

Architecture diagram

flowchart TD
    A[Schedule: Hourly] --> B[audit_dictionary_memory: ClickHouse system.dictionaries]
    B --> C{Dictionary Exceeds Limit or Failed?}
    C -- Yes --> D[notify_slack_olap: Slack Webhook]
    C -- No --> E[log_dictionaries_healthy: Log]
    D --> F[export_dict_manifest: Execution Labels]
    E --> F

Use cases

  • Prevent ClickHouse Server OOM Crashes: Catch oversized flat dictionaries that consume tens of gigabytes of node memory before server processes get terminated.
  • Dictionary Layout Tuning: Identify flat dictionaries that should be migrated to HASHED_ARRAY or cached layouts (CACHE) with eviction policies.
  • Failed Dictionary Reload Detection: Detect when source database credentials or network partitions cause dictionary periodic refreshes to fail silently.

Inputs

Name Type Default Description
clickhouse_endpoint STRING http://clickhouse.internal:8123 HTTP endpoint URL for the ClickHouse cluster coordinator or node.
max_dict_memory_mb_warning FLOAT 1024.0 Maximum permissible RAM footprint in megabytes for any single external dictionary.
slack_channel STRING #clickhouse-alerts Slack channel destination for OLAP memory governance alerts.

Expected outputs

  • {{ outputs.audit_dictionary_memory.vars.total_dictionaries_audited }}: Total dictionaries inspected in system catalog.
  • {{ outputs.audit_dictionary_memory.vars.flagged_dictionaries_count }}: Number of dictionaries exceeding memory limit or failed.
  • {{ outputs.audit_dictionary_memory.vars.has_memory_overflow }}: Boolean flag indicating memory overflow risk.
  • {{ outputs.audit_dictionary_memory.vars.max_dictionary_memory_mb }}: Peak memory observed for a single dictionary in megabytes.
  • {{ outputs.audit_dictionary_memory.outputFiles['clickhouse_dictionary_report.json'] }}: Full JSON dictionary memory diagnostics report.

Prerequisites

  • ClickHouse user credentials with SELECT privileges on the system.dictionaries table.
  • Incoming Webhook URL configured for your OLAP operations Slack channel.

Secrets

  • CLICKHOUSE_USER: ClickHouse authentication username.
  • CLICKHOUSE_PASSWORD: ClickHouse authentication password.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint URL.

Quick start

  1. Configure CLICKHOUSE_USER, CLICKHOUSE_PASSWORD, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Import this flow YAML into your Kestra workspace.
  3. Specify your ClickHouse HTTP endpoint in clickhouse_endpoint.
  4. Click Execute in the UI to perform an immediate dictionary memory audit.

Common pitfalls and troubleshooting

  • Cluster-Wide Aggregation: In distributed clusters, system.dictionaries reflects the local node state; query clusterAllReplicas('my_cluster', system.dictionaries) if auditing multi-node topologies.
  • Lazy vs Eager Loading: Dictionaries with LIFETIME(0) or lazy loading only allocate memory upon the first dictGet invocation; maintain periodic background health probes.

How to extend

  • Add automated dictionary reloading via SYSTEM RELOAD DICTIONARY <name> if transient network timeouts caused load failure.
  • Correlate dictionary memory consumption with server max_server_memory_usage settings.
  • Escalate critical memory saturation alerts to PagerDuty or Opsgenie.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.