Outlining blueprint details
I'm thinking about what to include in the blueprint. I want to provide values and suggestions to help with tuning. I should definitely list: 1) Goals/inputs, 2) Cardinality controls, 3) Downsampling, 4) Retention, 5) Query guardrails, and 6) Implementation checklist. I also need to mention debugging tools like the cardinality explorer, checking top series by label pair, and conducting query analysis. That seems like a solid plan!
Below is a practical deployment blueprint for a time-series platform (Prometheus-like metrics, PromQL-like queries, remote storage/object storage optional) focused on cardinality controls, downsampling, retention, and query guardrails. Treat the numbers as starting defaults—tune to your ingest rate, query load, and cost targets.
1) Cardinality controls (prevent “series explosion”)
1.1 Establish explicit cardinality budgets
Define budgets per tenant/team, per job, and per cluster:
- Active series budget (e.g., per team): 1–5M active series (org-dependent)
- New series creation rate (series churn): alert if spikes (often more damaging than steady high series)
- Top-k high-cardinality metrics: track and enforce thresholds
Operational rule: if a team wants to add labels/metrics that may increase cardinality, they need a budget impact estimate + rollout plan.
1.2 Label hygiene rules (the biggest win)
Hard rules to keep labels bounded:
- Never use unbounded identifiers as labels:
user_id, email, session_id, request_id, order_id, uuid, full URL with query params.
- Prefer bounded dimensions:
method, status_code, route (templated), region, namespace, service, endpoint_group.
- Normalize values:
- Use templated routes (
/users/:id) not raw paths (/users/123).
- Strip query strings from URLs.
- Bucket “reason”/“error” strings into bounded enums.
Alternative for per-request debugging: use tracing/logs or exemplars rather than labels.
1.3 Instrumentation patterns that cap cardinality
- Use histograms for latency and sizes; avoid embedding raw values in labels.
- Avoid dynamic metric names (e.g.,
http_requests_total_{customer}); use labels with bounded sets.
- For “top N” style dimensions, pre-aggregate at the source (app) or via a pipeline; don’t emit unbounded cardinality and hope the TSDB survives.
1.4 Ingestion-time enforcement (drop/keep/rewrite)
Implement enforcement at the edges:
- Scrape-time relabeling: drop labels and/or entire metrics before they enter the TSDB.
- Remote-write relabeling: same, but for remote targets.
- Enforce:
- allow-lists for “safe” labels per metric family
- drop known-dangerous labels (
pod_uid, container_id, instance in some cases if not needed)
- rename/normalize labels (e.g., map raw path → route template)
1.5 Cardinality monitoring and alerting
Continuously measure:
- Active series per tenant/job/metric
- Series churn (new series/sec)
- Label cardinality per metric (
top label keys by unique values)
- “Worst offenders” list (metric + labelset)
Alert when:
- Active series exceeds budget for N minutes
- Churn spikes >X% (often indicates bad deploy/instrumentation bug)
- Remote-write queue/backpressure correlates with churn spikes
2) Downsampling (rollups) and aggregation strategy
2.1 Use tiers, not one-size-fits-all
Downsampling is about reducing stored samples and query cost while keeping enough fidelity.
Typical tiering:
- Raw: high resolution (10–30s scrape) for short window
- 1m rollup: medium-term
- 5m/15m rollup: long-term trending / capacity planning
Example tier plan:
- Raw (10–30s): 7–14 days
- 1m: 30–180 days
- 5m or 15m: 1–3 years
2.2 Decide what you downsample
Downsampling should preserve meaningful aggregates:
- Gauges:
avg, min, max (sometimes last)
- Counters: store rate-friendly representations (often keep raw counters at shorter retention; rollups store
sum(rate()) over window or keep counter but at lower resolution carefully)
- Histograms:
- preserve bucket series if you need quantiles later (costly)
- or roll up to precomputed quantiles (cheaper but less flexible; beware quantile math pitfalls)
- a common compromise: keep histograms raw for short retention; long-term store only
count/sum or precomputed p50/p95/p99
2.3 Reduce cardinality during rollup
Downsampling is the best time to drop dimensions:
- Raw: keep
pod, instance if needed for debugging
- Rollups: aggregate away
pod/instance, keep service/namespace/cluster/route
This often yields a 10–100× reduction in series for long retention.
2.4 Precompute common queries (recording rules / materialized views)
For heavy dashboards and alerts:
- Create recording rules for:
- SLO burn rates
- common error ratios
- p95 latency per service/route
- node and cluster utilization
This both reduces query load and standardizes semantics.
3) Retention (cost control + performance)
3.1 Retention by tier (recommended)
A defensible default:
- Short-term hot (local SSD): raw, high-res, 7–14 days
- Warm (distributed TSDB): raw or lightly compacted, 30–90 days
- Cold (object storage): downsampled, 6–36 months
If you can only do one tier: prioritize a shorter raw retention + rollups for long-term.
3.2 Compaction and block sizing
Ensure your TSDB’s compaction settings align with retention:
- Larger blocks reduce index overhead but can increase query fan-out if too large.
- For object storage backends, compaction/downsampling typically runs asynchronously—monitor compactor lag.
3.3 Deletion and compliance
Have a plan for:
- deleting metrics/labelsets (tombstones)
- tenant deletion (offboarding)
- “right to be forgotten” scenarios (metrics shouldn’t include personal data in labels in the first place)
4) Query guardrails (protect the cluster from expensive queries)
4.1 Hard limits (set globally + per tenant)
Common guardrails (names vary by vendor):
- Max query time range (e.g., raw: 14d; rollups: 180d/1y allowed)
- Max samples scanned per query (prevents “select everything”)
- Max series returned
- Max datapoints returned (range query step enforcement)
- Query timeout (e.g., 30–120s depending on UX)
- Max concurrent queries per tenant/user
- Max query length / complexity (regex-heavy label matchers are expensive)
Practical defaults to start:
- Dashboard queries: timeout 30–60s
- Ad hoc: 60–120s
- Enforce minimum step (e.g., don’t allow 1s step over 30 days)
4.2 Step/range shaping
Automatically “shape” range queries:
- Clamp step to something reasonable:
step >= range / 1000 (keeps ≤ ~1000 points per series)
- Route long-range queries to downsampled data automatically (if supported)
4.3 Restrict expensive patterns
These are common foot-guns:
- Label regex matchers over high-card labels (
=~".*")
sum by (very_high_card_label)
topk over huge cardinality without pre-aggregation
- wide joins with
group_left / on() across huge series sets
Mitigations:
- Limit regex usage (or disallow on known-dangerous labels)
- Require dashboards to use recording rules for known-expensive expressions
- Provide “approved metrics + dimensions” catalog
4.4 Frontend protections: caching, queuing, and fairness
Add a query frontend (or equivalent) that provides:
- Result cache for identical queries
- Query splitting/sharding (especially for long ranges)
- Per-tenant fairness and rate limiting
- Priority lanes (alerts > dashboards > ad hoc)
4.5 Provide safe defaults for users
Make the “easy path” safe:
- Curated dashboards that hit recording rules
- Default time range (e.g., last 1h/6h/24h)
- Prebuilt templates that avoid dangerous dimensions
5) Minimal implementation checklist (what to do first)
- Cardinality policy: banned label list + bounded label guidelines + per-team budgets.
- Enforcement: relabel/drop rules at scrape/remote-write; block known-dangerous labels.
- Observability of observability: dashboards/alerts for active series, churn, ingest rate, compaction lag, query latency, query failures/timeouts.
- Rollup tier: at least one downsample tier (1m) with reduced label dimensions.
- Retention tiers: short raw + longer rollup retention.
- Query guardrails: max range, max samples, timeouts, concurrency; step clamping; cache/splitting if available.
If you tell me which stack you’re deploying (e.g., Prometheus+Thanos, Grafana Mimir, VictoriaMetrics, InfluxDB, Timescale, OpenSearch metrics, etc.), your ingest rate, and desired retention/resolution, I can map the above into concrete config knobs and suggested initial values for that specific platform.