RedisCLI icon
Docker icon
Loop icon
Sequential icon
OutputValues icon
Log icon
If icon
SlackIncomingWebhook icon
Fail icon
Schedule icon

Redis Replica Health Guard

Check Redis replicas for missing links, lag and replica-read-only off, alert Slack, and set replica-read-only back on with CONFIG SET and verify.

Categories
DataInfrastructure

Redis replication fails quietly:

  • a replica restarted with the wrong replicaof is now a standalone primary serving stale data;
  • another lost its link after the primary's password changed;
  • one was started with replica-read-only no for a test, and a client wrote session data to it, which the next full resync deletes without a trace.

Sentinel or the client library keeps working, so nobody notices until a failover promotes the replica that was behind.

This blueprint reads INFO replication on the primary and on every expected replica, plus replica-read-only on each replica. It alerts Slack on anything off, and can set replica-read-only back to yes with CONFIG SET, then read the setting again to verify.

This blueprint was created by zkasuran.

Findings

Finding Severity Rule Fix
PRIMARY_NOT_MASTER Critical The primary host reports a role other than master Report only
MISSING_REPLICAS High Fewer connected_slaves than expected replicas Report only
REPLICA_UNREACHABLE High No INFO reply from a replica Report only
NOT_A_REPLICA High An expected replica reports role master Report only
LINK_DOWN High master_link_status is not up Report only
REPLICA_LAG Medium The replica's offset is more than max_lag_bytes behind the primary's Report only
REPLICA_WRITABLE High replica-read-only is no CONFIG SET replica-read-only yes

Only the writable replica is fixed automatically. Re-pointing a replica or forcing a resync changes data, and is left to a person.

How it works

  1. primary_info (io.kestra.plugin.redis.cli.RedisCLI, read-only) runs INFO replication on the primary.
  2. replicas_info (io.kestra.plugin.core.flow.Loop) runs INFO replication and CONFIG GET replica-read-only on each replica. An unreachable replica does not stop the others.
  3. findings parses every reply and applies the rules in one jq expression. summary logs the result.
  4. route (io.kestra.plugin.core.flow.If):
    • healthy: logs it.
    • findings: alert posts to Slack.
      • remediate_gate runs only when auto_remediate is true, dry_run is false, and a replica is writable.
      • remediate (concurrencyLimit: 1) runs CONFIG SET replica-read-only yes and then reads the setting back.
      • verify_result fails if any replica is still writable.
  5. errors alerts Slack when the flow fails, for example on an unreachable primary.

What you get

  • One check of a whole replication group: the primary's view and each replica's own view.
  • Early warning of replicas that would serve stale data, or lose writes, at the next failover or resync.
  • A narrow automatic fix, verified, with everything else left for review.

Who it's for

  • Teams running Redis primary and replicas, with or without Sentinel, on VMs, Docker or Kubernetes.
  • SREs who have been surprised by a failover to a stale or diverged replica.
  • Teams evaluating the Redis plugin who want an example of RedisCLI across several hosts in a Loop.

Why orchestrate this with Kestra

Each INFO replication answers for one node at one moment. Kestra queries every node of the group on a schedule, compares the primary's view with each replica's, and sends the gaps to Slack. It applies the one safe fix behind auto_remediate and dry_run, verifies it, and keeps a history that shows when each replica fell behind or disconnected.

Tested end to end

On Kestra 2.0.5 OSS against Redis 7 containers (one primary and replicas started with --replicaof), with a local HTTP sink standing in for Slack.

Run Setup Result
1 One replica started with --replica-read-only no 1 finding, REPLICA_WRITABLE. Alert sent
2 same, dry run Same finding. CONFIG GET replica-read-only still no
3 same, remediate Set and verified. SET on the replica now returns READONLY You can't write against a read only replica
4 healthy No finding
5 One replica promoted with REPLICAOF NO ONE, the other stopped MISSING_REPLICAS (0 of 2), NOT_A_REPLICA, REPLICA_UNREACHABLE
6 Primary password changed, replica with a wrong masterauth, 1.5 MB written MISSING_REPLICAS, LINK_DOWN, REPLICA_LAG of 57,797,753 bytes. The flow authenticated with REDIS_PASSWORD
7 Unknown primary host errors alert sent

Prerequisites

  • Redis primary and replicas reachable from the Docker containers the RedisCLI tasks start. CONFIG must be allowed on the replicas for remediation.
  • Local testing:
    • docker run -d --name redis-primary redis:7-alpine;
    • docker run -d --name redis-replica-1 redis:7-alpine redis-server --replicaof redis-primary 6379 --replica-read-only no, on the same Docker network.

Secrets

  • SLACK_WEBHOOK_URL: used by alert and the errors block.
  • REDIS_PASSWORD: only when use_password is true.
  • In Kestra OSS, provide each one as a base64-encoded environment variable prefixed SECRET_.

Inputs

Input Default Purpose
primary_host redis-primary Primary
replica_hosts 2 example replicas Expected replicas
port 6379 Port on every node
max_lag_bytes 1048576 Lag threshold
use_password false Authenticate to the primary
network empty Docker network for the redis-cli containers
auto_remediate false Allow CONFIG SET replica-read-only yes
dry_run true Must be false for a change to apply

Quick start

  1. Add the SLACK_WEBHOOK_URL secret, and REDIS_PASSWORD if the primary requires one.
  2. Import the flow and set primary_host, replica_hosts and, if Redis runs in Docker, network.
  3. Run it once and read the findings.
  4. Run it with auto_remediate: true and dry_run: false to make writable replicas read-only, then persist the setting.
  5. Enable the every_5_minutes trigger, which always runs in safe mode.

How to extend

  • Ask Sentinel for the current primary (SENTINEL get-master-addr-by-name) instead of a fixed primary_host.
  • Check min-replicas-to-write on the primary, so writes stop when replicas are gone.
  • Run CONFIG REWRITE after the fix when your nodes use a writable config file.
  • Open an incident for NOT_A_REPLICA and LINK_DOWN instead of a Slack message.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.