Schedule icon
Request icon
Get icon
Script icon
Docker icon
Set icon
If icon
SlackIncomingWebhook icon
Log icon

Grafana Loki High-Cardinality Stream Rate & Ingestion Limit Sentinel

Detect Grafana Loki stream cardinality explosions, rate limit discards, and 429 distributor errors with automated KV incident tracking and Slack remediation.

Categories
CloudInfrastructure

Grafana Loki indexes metadata as streams of low-cardinality key-value pairs rather than full-text indexing entire log contents. When application developers or log collection forwarders accidentally extract high-cardinality identifiers like user_id, trace_id, request_id, or IP addresses into indexed stream labels, the distributor experiences a catastrophic stream explosion. Each unique label combination generates a distinct log stream chunk in distributor memory, breaching tenant limits (maximum_active_streams_exceeded or rate_limited) and triggering distributor HTTP 429 errors that drop mission-critical telemetry.

This sentinel workflow proactively audits Grafana Loki distributor telemetry and label indexes. It monitors loki_distributor_bytes_received_total, loki_discarded_samples_total, and active streams, correlates them against indexed stream label keys, detects root-cause tenant and label collisions, stores full incident records in Kestra KV store, and notifies SRE teams on Slack with remediation instructions to transition labels to Grafana Loki 3.0 Structured Metadata.

How it works

  1. Scrape Loki Metrics: An HTTP request fetches the raw Prometheus exposition metrics from the distributor endpoint (/metrics), capturing loki_distributor_bytes_received_total, loki_discarded_samples_total, and active stream counters.
  2. Audit Discovered Labels: A second HTTP request inspects Loki's /loki/api/v1/labels API to identify all actively indexed stream label names for the specified tenant.
  3. Query Index Statistics: Queries Loki's /loki/api/v1/index/stats API to extract active stream counts and chunk index volumes.
  4. Fetch Sentinel History: Retrieves previous execution counters from the Kestra KV store (loki_stream_sentinel_{tenant_id}) to compute exact interval ingestion rates and discarded sample deltas.
  5. Evaluate Cardinality and Stream Rates: A Python task parses the Prometheus exposition lines and label lists. It matches active labels against known high-cardinality keywords (user_id, trace_id, request_id, etc.), calculates interval throughput in MB/s and lines/s, checks for distributor discard reasons (maximum_active_streams_exceeded, rate_limited, entry_too_far_behind), and isolates the offending tenant and label name.
  6. Persist Incident Manifest in KV: Saves a structured incident manifest into Kestra KV with timestamps, breach status, offending labels, discarded sample breakdowns, and tailored remediation instructions.
  7. Dispatch Slack Notification: When an ingestion limit breach or label explosion occurs, an automated Slack alert delivers actionable remediation steps to migrate high-cardinality labels to Structured Metadata.

What you get

  • Cardinality Explosion Detection: Immediate discovery of unbounded labels before distributor memory exhausts ingesters.
  • Discard Cause Isolation: Granular classification of dropped samples across stream limit breaches, distributor rate limits, and clock drift.
  • Offending Tenant and Label Attribution: Exact isolation of which tenant and which label keys caused the ingestion failure.
  • Structured Metadata Migration Runbook: Direct remediation guidance for Promtail, Vector, and LogQL configurations.
  • Persistent Incident Ledger: Historical audit trace in Kestra KV store tracking tenant throughput and discard trends over time.

Who it's for

  • Site Reliability Engineers (SREs): Maintain cluster stability and prevent silent log loss across production Kubernetes fleets.
  • Platform Observability Engineers: Safeguard shared multi-tenant Grafana Loki clusters against misconfigured application forwarders.
  • DevOps Engineers: Enforce logging best practices and smooth transition to Grafana Loki 3.0 Structured Metadata.

Why orchestrate this with Kestra

  • Automated Health Surveillance: Schedules continuous health auditing without deploying separate external synthetic daemonsets.
  • Native KV Delta Calculations: Tracks cumulative Prometheus counter increases across executions directly inside Kestra's built-in namespace KV store.
  • Cross-Component Correlation: Connects Prometheus metric scraping, HTTP REST label querying, and notification channels in a single declarative workflow.
  • Extensible Incident Automation: Can easily trigger auto-remediation flows, such as updating Loki runtime overrides or restarting misconfigured forwarders.

Prerequisites

  • A running Grafana Loki instance (single binary or distributed microservices mode) exposing /metrics and /loki/api/v1/labels.
  • Network connectivity from Kestra runners to the Loki HTTP endpoint.
  • A Slack Incoming Webhook URL configured in Kestra secrets.

Secrets

  • SLACK_WEBHOOK_URL: Slack incoming webhook endpoint used to dispatch incident notifications.

Quick start

  1. Import this blueprint into your Kestra instance.
  2. Add the SLACK_WEBHOOK_URL secret to your Kestra namespace.
  3. Configure loki_endpoint and tenant_id to match your target Loki deployment.
  4. Execute the workflow manually to establish baseline metrics in Kestra KV.
  5. Enable the sentinel_schedule trigger to run audits automatically every 5 minutes.

How to extend

  • Dynamic Limit Overrides: Add a subflow task that invokes Loki's runtime overrides API (/loki/api/v1/overrides) to temporarily increase max_streams_per_user during incident mitigation.
  • PagerDuty Escalation: Route CRITICAL_LABEL_EXPLOSION events to PagerDuty or Opsgenie for high-priority on-call paging.
  • Multi-Tenant Sweep: Wrap the flow in a ForEach loop to iterate over all active tenant IDs in an organization.
  • Automated Forwarder Relabeling: Trigger a GitOps CI/CD pipeline to prune detected high-cardinality labels from Promtail or Vector config files automatically.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.