Schedule icon
Request icon
Switch icon
SlackIncomingWebhook icon
If icon
Log icon

CouchDB Active Task and Continuous Replication Sentinel

Audit CouchDB /_active_tasks for replication lag and stalled compactions, dispatch Slack incident alerts, and automate /_compact maintenance.

Categories
DataInfrastructure

Apache CouchDB is an open-source, distributed document-oriented NoSQL database featuring multi-version concurrency control (MVCC) and master-master replication. Organizations rely on CouchDB for edge-to-cloud synchronization, offline-first mobile applications, and multi-region document stores. In distributed environments, background tasks for document replication, view indexing, and database compaction run concurrently and are exposed via the /_active_tasks management API. When network partitions occur, authentication credentials expire, or high-volume document updates saturate worker threads, continuous replication tasks stall and changes_pending accumulates rapidly. If left unchecked, target clusters fall out of synchronization and append-only .couch files exhaust host disk storage. This blueprint provides automated continuous surveillance over /_active_tasks, detects replication backlogs, alerts engineering teams via Slack, and automates safe database compaction via POST /{db}/_compact.

How it works

  1. Scheduled trigger (every_fifteen_minutes) initiates diagnostic health verification every 15 minutes, with manual runs supported via customizable inputs.
  2. Diagnostic probe (probe_active_tasks) connects to the CouchDB HTTP REST interface (port 5984) via io.kestra.plugin.core.http.Request and queries /_active_tasks with HTTP Basic Authentication.
  3. Classification logic evaluates the JSON task array using Pebble templating, discerning whether any replication tasks have accumulated pending changes exceeding max_pending_changes (CRITICAL), if moderate pending changes exist (WARNING), if all tasks are healthy (HEALTHY), or if the HTTP endpoint was unreachable (PROBE_FAILED).
  4. Routing task (route_by_task_health) switches execution along dedicated paths according to the classified severity.
  5. On CRITICAL or WARNING states, structured Slack incident cards notify operations channels with cluster host details, pending change counts, and targeted databases.
  6. Guarded remediation (check_remediation) checks whether auto_compact is enabled and dry_run is disabled. If confirmed, trigger_database_compaction dispatches a POST request to /{target_database}/_compact to reclaim disk space from old document revisions and unblock I/O bottlenecks.
  7. On PROBE_FAILED, dedicated alerts notify administrators of unreachable ports or invalid credentials.
  8. Audit log task (log_audit_summary) writes execution metadata and classified status to task logs.

What you get

  • Automated continuous surveillance of CouchDB active background tasks across replication, compaction, and indexing pipelines.
  • Early detection of replication lag before multi-region or edge document stores fall out of sync.
  • Automated self-healing database compaction triggering POST /{db}/_compact without manual operator intervention.
  • Differentiated incident routing separating active backlog spikes from nominal replication processing.
  • Full execution traceability and audit logging without leaking database passwords in logs or alert payloads.

Who it's for

  • Database Administrators and SREs managing production CouchDB distributed document clusters.
  • Platform Engineers maintaining edge-to-cloud data synchronization and mobile backend stores.
  • Data Infrastructure Teams deploying resilient multi-master document databases.

Why orchestrate this with Kestra

  • Declarative YAML definition unifies distributed document store surveillance, conditional severity triage, and automated self-healing into version-controlled GitOps workflows.
  • Native HTTP request capabilities interact directly with CouchDB's REST APIs without external agent daemons or Python container overhead.
  • Built-in conditional routing and dry-run safety gates isolate discovery from administrative maintenance triggers.
  • Immutable execution history provides operational evidence documenting replication lag recovery timelines and compaction intervals.
  • Cloud-native scheduling and flow-level error-trapping ensure continuous sentinel operation independent of external cron infrastructure.

Prerequisites

  • Apache CouchDB instance running with HTTP REST API access enabled (default port 5984).
  • Database user with permissions to query /_active_tasks and trigger /{db}/_compact.
  • Slack incoming webhook URL for operational incident dispatch.

Secrets

  • COUCHDB_USERNAME: Username for authenticating to CouchDB administrative endpoints (e.g. admin).
  • COUCHDB_PASSWORD: Password for the CouchDB administrative user.
  • SLACK_WEBHOOK_URL: Incoming webhook URL for posting incident cards to Slack.

Quick start

  1. Configure COUCHDB_USERNAME, COUCHDB_PASSWORD, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Deploy this blueprint to your Kestra instance and trigger an initial run with dry_run: true to verify connectivity against your CouchDB server.
  3. Review the execution log in the Kestra UI to verify /_active_tasks response parsing.
  4. Enable the every_fifteen_minutes schedule trigger to activate automated continuous monitoring and remediation.

How to extend

  • Add GET /_node/_local/_up health checks to verify node-level cluster member readiness.
  • Integrate PagerDuty alerting via io.kestra.plugin.pagerduty.notifications.PagerDutyAlert for continuous replication outages lasting longer than one hour.
  • Attach view index compaction triggers via POST /{db}/_compact/{design_doc} to optimize MapReduce secondary indexes.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.