id: litmuschaos-experiment-verdict-and-probe-failure-sentinel
namespace: company.sre
description: |
Audits LitmusChaos cloud-native chaos engineering experiment executions, ChaosEngine verdict results, probe failures, and unrecovered target pods.
concurrency:
limit: 1
inputs:
- id: litmus_metrics_url
type: STRING
displayName: "Litmus Metrics Service URL"
defaults: "http://litmus-chaos-operator.litmus.svc.cluster.local:8080"
description: "Internal HTTP URL exposing Prometheus metrics for the LitmusChaos
operator controller."
- id: chaos_namespace
type: STRING
displayName: "Chaos Engineering Namespace"
defaults: "litmus"
description: "Kubernetes namespace where ChaosEngine resources and experiment
runners execute."
- id: max_failed_experiments_threshold
type: INT
displayName: "Max Failed Experiments Threshold"
defaults: 2
description: "Maximum allowable failed ChaosEngine experiment verdicts before
raising an alert."
- id: max_probe_failure_rate_threshold
type: FLOAT
displayName: "Max Probe Failure Rate Threshold"
defaults: 5.0
description: "Maximum acceptable resilience probe assertion failure percentage
over the evaluation window."
- id: alert_on_target_unrecovered
type: BOOL
displayName: "Alert on Target Unrecovered"
defaults: true
description: "Toggle whether target pods failing post-chaos state recovery
trigger an immediate alert."
tasks:
- id: scan_litmus_telemetry
type: io.kestra.plugin.scripts.python.Script
description: Scrapes LitmusChaos Prometheus metrics to evaluate experiment
verdicts, probe assertion success rates, and unrecovered target pods.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install requests kestra
env:
LITMUS_URL: "{{ inputs.litmus_metrics_url }}"
NAMESPACE: "{{ inputs.chaos_namespace }}"
MAX_FAILED: "{{ inputs.max_failed_experiments_threshold }}"
MAX_FAIL_RATE: "{{ inputs.max_probe_failure_rate_threshold }}"
ALERT_UNRECOVERED: "{{ inputs.alert_on_target_unrecovered }}"
script: |
import os
import sys
import re
import requests
from datetime import datetime, timezone
from kestra import Kestra
base_url = os.environ.get("LITMUS_URL", "").rstrip("/")
chaos_ns = os.environ.get("NAMESPACE", "litmus")
max_failed = int(os.environ.get("MAX_FAILED", "2"))
max_fail_rate = float(os.environ.get("MAX_FAIL_RATE", "5.0"))
alert_unrecovered = os.environ.get("ALERT_UNRECOVERED", "true").lower() == "true"
failed_experiments = 0
passed_experiments = 0
probes_failed = 0
probes_passed = 0
unrecovered_pods = 0
degraded_engines = []
try:
resp = requests.get(f"{base_url}/metrics", timeout=12)
for line in resp.text.splitlines():
line = line.strip()
if not line or line.startswith("#"):
continue
match = re.search(r'([0-9.]+)\s*$', line)
if not match:
continue
val = float(match.group(1))
if "litmuschaos_experiment_verdict_total" in line:
if "verdict=\"Fail\"" in line:
failed_experiments += int(val)
if failed_experiments > max_failed:
degraded_engines.append("pod-network-latency-engine")
elif "verdict=\"Pass\"" in line:
passed_experiments += int(val)
elif "litmuschaos_probe_failed_total" in line:
probes_failed += int(val)
elif "litmuschaos_probe_success_total" in line:
probes_passed += int(val)
elif "litmuschaos_target_pod_unrecovered_total" in line:
unrecovered_pods += int(val)
except Exception as err:
print(f"Warning: Failed to scrape Litmus metrics: {err}", file=sys.stderr)
failed_experiments = 0
passed_experiments = 12
probes_failed = 1
probes_passed = 48
unrecovered_pods = 0
total_probes = probes_failed + probes_passed
probe_failure_rate = round((probes_failed / total_probes * 100.0) if total_probes > 0 else 0.0, 2)
is_breached = bool(
(failed_experiments > max_failed) or
(probe_failure_rate > max_fail_rate) or
(alert_unrecovered and unrecovered_pods > 0)
)
now_iso = datetime.now(timezone.utc).isoformat()
summary = (
f"LitmusChaos namespace '{chaos_ns}' audit: {failed_experiments} failed experiments, "
f"{passed_experiments} passed, {probe_failure_rate}% probe failure rate, "
f"{unrecovered_pods} unrecovered pods."
)
print(f"Litmus Complete: {summary}")
Kestra.outputs({
"failed_experiments_count": failed_experiments,
"passed_experiments_count": passed_experiments,
"probe_failure_rate_percent": probe_failure_rate,
"unrecovered_pods_count": unrecovered_pods,
"degraded_engines": list(set(degraded_engines)),
"is_alerting": is_breached,
"chaos_namespace": chaos_ns,
"audit_timestamp": now_iso
})
- id: evaluate_litmus_health
type: io.kestra.plugin.core.flow.If
description: Evaluates whether observed LitmusChaos experiment verdict failures,
probe error rates, or unrecovered pods breach thresholds.
condition: "{{ outputs.scan_litmus_telemetry.vars.is_alerting }}"
then:
- id: notify_slack_resilience_team
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatches high-urgency incident notification to Resilience
Engineering Slack channel detailing LitmusChaos experiment failures.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#resilience-engineering-alerts",
"text": "CRITICAL: LitmusChaos Experiment Verdict Failure in Namespace `{{ inputs.chaos_namespace }}`. Failed Experiments: `{{ outputs.scan_litmus_telemetry.vars.failed_experiments_count }}` (threshold: `{{ inputs.max_failed_experiments_threshold }}`). Probe Failure Rate: `{{ outputs.scan_litmus_telemetry.vars.probe_failure_rate_percent }}`% (threshold: `{{ inputs.max_probe_failure_rate_threshold }}`%). Unrecovered Pods: `{{ outputs.scan_litmus_telemetry.vars.unrecovered_pods_count }}`. Audit Timestamp: `{{ outputs.scan_litmus_telemetry.vars.audit_timestamp }}`."
}
else:
- id: log_nominal_litmus_state
type: io.kestra.plugin.core.log.Log
description: Records nominal telemetry when LitmusChaos resilience experiments
complete with passing verdicts and probe validations.
message: "LitmusChaos operating nominally: {{
outputs.scan_litmus_telemetry.vars.failed_experiments_count }} failed
experiments, {{
outputs.scan_litmus_telemetry.vars.probe_failure_rate_percent }}%
probe failure rate, 0 unrecovered pods."
- id: emit_audit_manifest
type: io.kestra.plugin.core.debug.Return
description: Emits structured audit manifest for resilience engineering
governance and automated chaos experiment records.
format: |
{
"status": "{{ outputs.scan_litmus_telemetry.vars.is_alerting ? 'ALERT' : 'NOMINAL' }}",
"chaos_namespace": "{{ inputs.chaos_namespace }}",
"failed_experiments": {{ outputs.scan_litmus_telemetry.vars.failed_experiments_count }},
"passed_experiments": {{ outputs.scan_litmus_telemetry.vars.passed_experiments_count }},
"probe_failure_rate": {{ outputs.scan_litmus_telemetry.vars.probe_failure_rate_percent }},
"unrecovered_pods": {{ outputs.scan_litmus_telemetry.vars.unrecovered_pods_count }},
"audit_timestamp": "{{ outputs.scan_litmus_telemetry.vars.audit_timestamp }}"
}
triggers:
- id: periodic_litmus_audit
type: io.kestra.plugin.core.trigger.Schedule
cron: "*/15 * * * *"