Okay, the user's query is about key operational aspects of a time-series platform: cardinality controls, downsampling, retention, and query guardrails. This seems like a technical discussion about platform management, likely from someone designing or maintaining such a system—maybe a DevOps engineer, SRE, or platform architect.
The user probably wants both high-level strategies and practical implementation details. They might be weighing trade-offs or troubleshooting existing issues. The mention of "query guardrails" hints at concerns about runaway queries affecting stability, which is a common pain point in TSDBs like Prometheus or InfluxDB.
I should structure this to address each component clearly, with actionable recommendations and pitfalls to avoid. Real-world examples (like Prometheus relabeling or Thanos compaction) would help ground it. Since cardinality is often the root cause of scaling issues, I’ll emphasize it first and link it to retention/query implications. Downsampling and retention need to tie together—compression vs. resolution trade-offs. Query guardrails should cover both proactive limits and reactive mitigation.
The tone should be authoritative but not academic; the user likely needs to implement this, not just theory. Avoid vendor-specific fluff unless it illustrates a pattern (e.g., "like Cortex/Thanos does X"). Assume they’re familiar with TSDB concepts but need synthesis.
Excellent question. These four pillars—Cardinality, Downsampling, Retention, and Query Guardrails—are the fundamental operational and cost-control mechanisms for any production-grade time-series platform (like Prometheus, VictoriaMetrics, Thanos, Mimir, or commercial offerings). Getting them wrong leads to unbounded storage costs, degraded query performance, and platform instability.
Here is a breakdown of each, including why they matter, how to implement them, and common pitfalls.
1. Cardinality Controls
The Problem: Cardinality = the number of unique time series (metric name + label set). Uncontrolled cardinality (often from high-cardinality labels like user_id, request_id, pod_name in a large cluster) is the #1 cause of TSDB explosions.
Impact: Memory/disk usage scales linearly with cardinality. High cardinality kills query performance and can crash the TSDB.
Controls & Strategies:
Label Design Policy: Enforce that only low-cardinality, queryable labels are used. http_request_total{method="GET", status="200", route="/api/users"} is good. http_request_total{user_id="12345"} is bad (unless it's a very small set of users).
Metric Relabeling/Filtering (Drop Rules): Actively drop metrics or label values you don't need at ingestion.
Example (Prometheus relabel_config):
yaml
# Drop all metrics with a ' pod_name ' label from kube-state-metrics if pod count > 500
- source_labels: [pod_name]
regex: .+
action: labeldrop
Recording Rules (Pre-aggregation): Create pre-aggregated series at lower cardinality before they hit your long-term store.
sum(http_requests_total) by (method, status, region) instead of keeping every pod label.
Limit Max Cardinality per Metric: Some platforms (like VictoriaMetrics) allow setting per-metric cardinality limits.
Audit & Alerting: Regularly audit top cardinality labels. Alert when cardinality for a metric grows abnormally fast (e.g., >10% in 24h).
2. Downsampling (Data Resolution Management)
The Problem: Raw, per-second data is expensive. You rarely need nanosecond precision for a 30-day trend.
Impact: Storing 30 days of 1s data vs. 1h data can be ~86,400x larger. Downsampling is non-negotiable for long-term retention.
Strategies:
Automated Downsampling Policies: The TSDB must automatically roll up data into coarser buckets as it ages.
Typical Policy:
0-24h: 1s resolution (raw)
1d-30d: 1m resolution (avg, min, max, sum, count)
30d-2y: 1h resolution (avg, etc.)
>2y: 1d resolution (optional)
Implementation:
Thanos/Cortex/Mimir: Use --downsampling.disable or configure resolution and retention in their respective configs/compactors.
VictoriaMetrics: Built-in, automatic, and configurable via -storage.minRawSamplesPerBlock and retention flags.
Prometheus (standalone):Does not do this natively. You must use recording rules to pre-compute downsampled series and store them as new metrics before the raw data ages out. This is a major reason people move to long-term stores.
Key Principle: Never downsample in-place. Create new, coarser-resolution series. Preserve raw data for the shortest necessary period.
3. Retention
The Problem: Infinite storage is not free. You must define a business purpose for how long data lives.
Impact: Drives infrastructure cost directly. Also affects compliance (e.g., GDPR "right to be forgotten" can be tricky with immutable TSDB blocks).
Strategies:
Multi-Tier Retention: Align with your downsampling policy.
Raw Tier: 7-30 days (high-res, expensive).
Downsampled Tier (1m/1h): 90-365 days (medium cost, medium resolution).
Archive Tier (1d): 2-10+ years (low cost, low resolution).
Configuration:
Per-Metric Retention: Advanced platforms allow setting different retention by metric name or label matcher (e.g., keep audit_log_* for 5 years, node_cpu for 90 days).
Global Defaults: Set sensible defaults (e.g., -retentionPeriod=30d for raw, -retentionPeriod=2y for 1m).
Delete, Don't Just Expire: Ensure your platform's compaction process actually deletes old blocks from disk/object storage. Some misconfigured systems keep blocks forever if references exist.
4. Query Guardrails
The Problem: A single bad query ({__name__=~".+"}) can scan billions of series, saturate I/O, and outage your entire platform.
Query Timeout: Absolute max time a query can run (e.g., 30s, 60s). Enable this always.
Query Concurrency Limits: Max simultaneous queries per user/tenant. Prevent a single user from DoS-ing the system.
Maximum Series Scan Limit: The most critical guardrail. Hard-cap the number of series a single query can touch (e.g., 100,000 - 1,000,000 series). If your group by or regex would match more series, the query is killed immediately.
Maximum Query Range: Prevent queries for absurd time ranges (e.g., > 5 years at 1s resolution). Often tied to the "max series" limit.
Step Parameter Enforcement: For range queries, enforce a maximum step (e.g., don't allow step=1ms for a 1-year range).
Resource Quotas (Multi-Tenant): Per-tenant limits on: query concurrency, max query duration, max series, and even storage ingestion rate.
Query Caching: Use a query cache (like Prometheus or Grafana) aggressively for common dashboard queries to reduce load on the TSDB.
User Interface Warnings: Tools like Grafana should warn users before running an obviously expensive query (e.g., "This query will scan 2.4M series").
Integrated Deployment Strategy
Start with Cardinality: Before setting retention, measure your ingestion rate (samples/sec) and cardinality growth. Your storage needs are a function of: (Cardinality * SamplesPerSeries) * RetentionTime.
Define Your Data Tiers: Based on business needs (SLA, compliance, troubleshooting).
text
Tier 1 (Hot/Raw): 15 days @ 15s resolution
Tier 2 (Warm): 90 days @ 1m resolution
Tier 3 (Cold): 3 years @ 1h resolution
Configure Platform:
Ingestion: Apply label filters/drops at the scrape/collection point.
TSDB: Set downsampling policies and retention periods aligned to your tiers.
Query Stats:slow queries, queries errored due to limits, series scanned per query.
Compaction/Downsampling Lag (ensure it's keeping up).
Automate Response:
Alert on cardinality spikes >5% in 1h.
Alert if any query exceeds 80% of the max series limit.
Use recording rules to pre-compute high-value, lower-cardinality aggregations for common dashboards.
Common Pitfalls to Avoid
❌ ** relying on Prometheus alone for >30 days of data** without an external long-term store with downsampling.
❌ Using client-side labels (e.g., instance=pod-12345) that blow up cardinality. Use static, group-level labels.
❌ Not setting max_series query limits and waiting for an outage to happen.
❌ Setting retention first without understanding your cardinality -> you'll set an arbitrary number and quickly run out of space or money.
❌ Downsampling only at query time (e.g., Grafana's "Min Step"). This does not save storage; the raw data is still stored.
Bottom Line: Treat your time-series platform like a regulated utility. You must control the input (cardinality), manage the inventory (retention/downsampling), and enforce fair usage (query guardrails) to keep it stable, performant, and cost-effective.