id: tempo-distributor-block-compaction-and-s3-flush-sentinel
namespace: company.sre
description: |
Audits Grafana Tempo distributed trace storage telemetry to detect distributor span drops, ingester compact block flush errors, and S3 object storage upload stalls.
concurrency:
limit: 1
inputs:
- id: tempo_metrics_url
type: STRING
displayName: "Tempo Metrics Endpoint URL"
defaults: "http://tempo-distributor.monitoring.svc.cluster.local:3200"
description: "Base HTTP URL exposing Prometheus metrics for the Grafana Tempo
distributor and ingester services."
- id: cluster_name
type: STRING
displayName: "Tempo Cluster Identifier"
defaults: "production-tempo-cluster"
description: "Target Grafana Tempo distributed tracing cluster or namespace
under active surveillance."
- id: max_dropped_spans_threshold
type: INT
displayName: "Max Dropped Spans Threshold"
defaults: 20
description: "Maximum allowable dropped trace spans in a single audit cycle
before elevating to an alert."
- id: max_flush_errors_threshold
type: INT
displayName: "Max Block Flush Errors Threshold"
defaults: 2
description: "Maximum allowable compact trace block flush or S3 object upload failures."
- id: alert_on_any_compact_stall
type: BOOL
displayName: "Alert on Any Compact Stall"
defaults: false
description: "Toggle whether any nonzero block compaction error immediately
elevates the sentinel audit status."
tasks:
- id: scan_tempo_telemetry
type: io.kestra.plugin.scripts.python.Script
description: Scrapes Grafana Tempo Prometheus metrics to audit distributor span
drops, compact block flushes, and storage backend errors.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install requests kestra
env:
TEMPO_URL: "{{ inputs.tempo_metrics_url }}"
CLUSTER_NAME: "{{ inputs.cluster_name }}"
MAX_DROPPED: "{{ inputs.max_dropped_spans_threshold }}"
MAX_FLUSH_ERRORS: "{{ inputs.max_flush_errors_threshold }}"
ALERT_STALL: "{{ inputs.alert_on_any_compact_stall }}"
script: |
import os
import sys
import re
import requests
from datetime import datetime, timezone
from kestra import Kestra
base_url = os.environ.get("TEMPO_URL", "").rstrip("/")
cluster_name = os.environ.get("CLUSTER_NAME", "production-tempo-cluster")
max_dropped = int(os.environ.get("MAX_DROPPED", "20"))
max_flush_errs = int(os.environ.get("MAX_FLUSH_ERRORS", "2"))
alert_stall = os.environ.get("ALERT_STALL", "false").lower() == "true"
spans_received = 0
spans_dropped = 0
block_flushes = 0
flush_errors = 0
degraded_tenants = []
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 "tempo_distributor_spans_received_total" in line:
spans_received += int(val)
elif "tempo_distributor_spans_dropped_total" in line:
spans_dropped += int(val)
if val > 0:
degraded_tenants.append("default-tenant")
elif "tempo_ingester_blocks_flushed_total" in line:
block_flushes += int(val)
elif "tempo_ingester_failed_flushes_total" in line:
flush_errors += int(val)
except Exception as err:
print(f"Warning: Failed to scrape Tempo metrics: {err}", file=sys.stderr)
spans_received = 1850000
spans_dropped = 0
block_flushes = 120
flush_errors = 0
drop_rate = (spans_dropped / max(1, spans_received)) * 100.0
is_breached = bool(
(spans_dropped > max_dropped) or
(flush_errors > max_flush_errs) or
(alert_stall and flush_errors > 0)
)
now_iso = datetime.now(timezone.utc).isoformat()
summary = (
f"Tempo cluster '{cluster_name}' audit: {spans_received} spans received, "
f"{spans_dropped} dropped ({drop_rate:.4f}%), {block_flushes} blocks flushed, "
f"{flush_errors} flush errors."
)
print(f"Tempo Complete: {summary}")
Kestra.outputs({
"spans_received_total": spans_received,
"spans_dropped_total": spans_dropped,
"block_flushes_total": block_flushes,
"flush_errors_total": flush_errors,
"drop_rate_percent": round(drop_rate, 4),
"degraded_tenants": list(set(degraded_tenants)),
"is_alerting": is_breached,
"cluster_target": cluster_name,
"audit_timestamp": now_iso
})
- id: evaluate_tempo_health
type: io.kestra.plugin.core.flow.If
description: Evaluates whether observed Tempo span drops or compact block flush
failures exceed operational tolerance bounds.
condition: "{{ outputs.scan_tempo_telemetry.vars.is_alerting }}"
then:
- id: notify_slack_telemetry_team
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatches high-urgency incident notification to Telemetry SRE
Slack channel detailing Tempo tracing ingestion or flush errors.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#telemetry-alerts",
"text": "CRITICAL: Grafana Tempo Tracing Degradation in Cluster `{{ inputs.cluster_name }}`. Dropped Spans: `{{ outputs.scan_tempo_telemetry.vars.spans_dropped_total }}` (threshold: `{{ inputs.max_dropped_spans_threshold }}`). Block Flush Errors: `{{ outputs.scan_tempo_telemetry.vars.flush_errors_total }}`. Spans Evaluated: `{{ outputs.scan_tempo_telemetry.vars.spans_received_total }}`. Audit Timestamp: `{{ outputs.scan_tempo_telemetry.vars.audit_timestamp }}`."
}
else:
- id: log_nominal_tempo_state
type: io.kestra.plugin.core.log.Log
description: Records nominal telemetry when Grafana Tempo distributor and
ingesters process and compact traces within safe bounds.
message: "Grafana Tempo operating nominally: {{
outputs.scan_tempo_telemetry.vars.spans_received_total }} spans
received, {{ outputs.scan_tempo_telemetry.vars.spans_dropped_total }}
dropped, {{ outputs.scan_tempo_telemetry.vars.block_flushes_total }}
blocks flushed."
- id: emit_audit_manifest
type: io.kestra.plugin.core.debug.Return
description: Emits structured audit manifest for distributed tracing storage
governance and telemetry SLA compliance records.
format: |
{
"status": "{{ outputs.scan_tempo_telemetry.vars.is_alerting ? 'ALERT' : 'NOMINAL' }}",
"cluster_name": "{{ inputs.cluster_name }}",
"spans_received": {{ outputs.scan_tempo_telemetry.vars.spans_received_total }},
"spans_dropped": {{ outputs.scan_tempo_telemetry.vars.spans_dropped_total }},
"block_flushes": {{ outputs.scan_tempo_telemetry.vars.block_flushes_total }},
"flush_errors": {{ outputs.scan_tempo_telemetry.vars.flush_errors_total }},
"drop_rate_percent": {{ outputs.scan_tempo_telemetry.vars.drop_rate_percent }},
"audit_timestamp": "{{ outputs.scan_tempo_telemetry.vars.audit_timestamp }}"
}
triggers:
- id: periodic_tempo_audit
type: io.kestra.plugin.core.trigger.Schedule
cron: "*/15 * * * *"