Grafana Interview Questions

Grafana Agent and Telemetry Collection

questions
Scroll to track progress

You have 500 Linux servers across multiple regions running applications. You're currently using Telegraf for metrics collection, but want to consolidate with a unified agent. Grafana Agent can collect metrics, logs, and traces. Design a phased migration from Telegraf to Grafana Agent while maintaining collection continuity.

Implement gradual Grafana Agent rollout: (1) Parallel collection—install Grafana Agent on test servers alongside Telegraf. Both collect metrics simultaneously for 1-2 weeks, validating equivalence. (2) Configuration migration—convert Telegraf configs to Grafana Agent YAML. Test extensively. (3) Canary rollout—deploy Agent to 5% of servers. Monitor for errors, missing metrics, latency. If good, roll out in stages: 25%, 50%, 100%. (4) Telegraf decommissioning—once Agent is stable, uninstall Telegraf. Keep configs in Git for 6 months (rollback). (5) Metrics validation—continuously compare Agent-collected metrics to Telegraf. Alert on deviations. (6) Unified config management—store Agent configs in Git. Deploy via config management (Ansible, Puppet). (7) Logs + traces consolidation—add log collection to Agent (Loki), add trace collection (Tempo). This moves towards single-agent observability stack. Implement Agent health monitoring: track agent process status, configuration reload success, metric delivery latency per server. Alert if agent is unhealthy. For rollback, maintain Telegraf binaries and configs on servers temporarily. If Agent fails, automatically restart Telegraf. Create dashboard: migration progress (% servers on Agent, metrics completeness). Set target: "100% Agent rollout in 60 days." Test failure scenarios: what if Agent crashes, network partitions, disk fills? Verify graceful degradation. Document runbook: troubleshooting common Agent issues (config errors, permission issues, network connectivity).

Follow-up: Your migration is 80% complete, but 5% of servers show gaps in metrics (Agent isn't collecting some metrics that Telegraf did). You can't identify the pattern. How would you investigate missing metrics?

Your Grafana Agent deploys to edge servers in field locations (factories, remote offices). Network is unreliable: connections drop frequently, latency is high (>500ms). Agent's connection to central Prometheus keeps timing out. Design a resilient agent architecture for edge environments.

Implement edge-resilient agent architecture: (1) Local buffering—Agent buffers metrics locally (on-disk WAL) when remote connection fails. Buffers up to 10GB. (2) Eventual delivery—when connection restores, Agent replays buffered metrics to central Prometheus. Ensures no data loss. (3) Adaptive retry—implement exponential backoff with max retry interval. Don't hammer unreliable connections. (4) Edge aggregation—Agent performs local pre-aggregation (sum, avg) before sending. Reduces bandwidth 90%. (5) Compression—compress metrics at rest and in transit. Further bandwidth savings. (6) Selective collection—collect high-priority metrics frequently (every 30s), low-priority less often (every 5min). Adapts to bandwidth constraints. (7) Local metrics API—expose metrics locally via /metrics endpoint. Local tools (scripts, dashboards) can query without remote connection. Implement bandwidth metering: track bytes sent/received. Alert if approaching network quota. Implement intelligent fallback: if network is consistently slow, reduce collection frequency and resolution. Once network improves, scale up. Build edge analytics: track which servers have connectivity issues, at what times. Infer network health patterns. For compliance, ensure buffered data is encrypted at rest (someone shouldn't be able to read Agent's local WAL files). Test edge scenarios: simulate network degradation (latency, packet loss, disconnections). Verify Agent handles gracefully.

Follow-up: Your Agent buffers 10GB locally, but a server has only 2GB disk available. Local buffering fills disk, crashes the server's application. How would you prevent buffer exhaustion from crashing the system?

You're collecting logs from 200 applications using Grafana Agent. Agent forwards logs to Loki. But a misconfigured application logs credit card numbers to stdout. This sensitive data is now in Loki (and backup tapes). Design a system that detects and redacts sensitive data before it enters the logging system.

Implement log data protection: (1) PII detection rules—define patterns for sensitive data: credit cards, SSNs, API keys, passwords. Agent scans logs against patterns. (2) Redaction—when pattern matches, redact: credit_card = "****-****-****-1234" (keep last 4 digits for debugging). (3) Sampling—if sensitive data is detected, sample heavily: keep 1% of logs. Reduces volume of sensitive logs in Loki. (4) Alerting—alert when sensitive data is detected: "credit card data found in app-X logs. Investigate." (5) Metadata tracking—tag logs containing redacted data with label "sensitive_redacted". Enables filtering. (6) Incident response—provide tool to search Loki, identify logs with sensitive data, and purge from backups/archives. (7) Configuration—store PII patterns in Config file (Git-tracked). Teams can add custom patterns. Implement a whitelist for false positives: some applications legitimately use card numbers (e.g., payment processor testing). Whitelist these applications. For compliance, implement immutable audit log: track all redactions (what, when, why). Retain for 7+ years. Build dashboard: sensitive data detection rate by application and by pattern type. Alert teams to fix logging (don't log credit cards). Create runbook: responding to sensitive data detection (quarantine logs, assess exposure, notify affected parties). Test PII detection: inject test credit cards into logs, verify detection and redaction. Simulate data breach: if Loki is compromised, ensure redacted PII isn't exposed.

Follow-up: Your redaction is working, but a developer needs the exact card number to debug a payment failure. Redacted data doesn't help. How do you enable debugging while maintaining compliance?

Your Grafana Agent collects metrics from Kubernetes pods. In Kubernetes environments, pod IPs change frequently (scale-up/down, rolling updates). Agent service discovery must be dynamic. Design a service discovery system for dynamic Kubernetes environments.

Implement Kubernetes-native service discovery: (1) Kubernetes API discovery—Agent queries Kubernetes API to list all pods/services. Dynamic; as pods are created/destroyed, Agent auto-discovers. (2) Relabeling rules—apply relabeling to discovered targets: extract pod namespace, service name, labels. Add as Prometheus labels. (3) DNS-based discovery—use Kubernetes DNS (service DNS names). Agent resolves to all pod IPs automatically. (4) StatefulSet support—for StatefulSets, Agent discovers each pod with stable hostname. (5) Namespace filtering—Agent can filter to specific namespaces: production, staging. (6) Label selection—Agent selects pods based on labels: "scrape=true". Only annotated pods are scraped. (7) Custom resource discovery—for CustomResourceDefinitions (CRDs), implement custom discovery logic (via webhook or operator). Implement scrape config per service type: Prometheus instances, MySQL databases, Redis, etc. Each has discovery and relabeling rules. Create namespace-level deployment: Grafana Agent runs as DaemonSet on every node. Each Agent discovers services in that namespace. For multi-cluster, Agent discovers across all clusters and de-duplicates targets. Build observability for discovery: track discovered targets, relabeling success rate. Alert on anomalies (pods discovered then immediately disappear—suggests relabeling error). Test scenarios: scale-up (new pods), scale-down (pods terminate), rolling updates (gradual replacement). Verify targets are correctly discovered and scraped. Document discovery rules: explain label selectors, relabeling logic.

Follow-up: Your Kubernetes discovery is adding 10K new scrape targets after a scale-up event. Prometheus ingestion is overloaded. How would you handle explosive target growth?

Your Grafana Agent deployment is using 2GB of memory per server (for buffering and scraping). You have 500 servers. That's 1TB of agent memory consuming resources from applications. Design an efficient, memory-optimized agent architecture.

Implement memory-efficient agent design: (1) Streaming pipeline—instead of buffering entire results, stream metrics to Prometheus incrementally. Process 1000 metrics at a time. (2) Garbage collection tuning—optimize Agent's garbage collection: shorter GC pause times, more frequent collections for steady-state. (3) Metric filtering—filter low-value metrics at collection time (don't scrape debug metrics). Reduce cardinality 50%. (4) Compression—compress buffered metrics before writing to disk. Reduces memory pressure. (5) Pooling—reuse objects (buffers, scrape contexts) instead of allocating new ones. Reduce GC pressure. (6) Target pruning—only scrape active targets. Remove targets that haven't responded in 5 minutes. Reduces resource overhead. (7) Memory limits—set hard memory limits on Agent process (via cgroup). If exceeded, Agent gracefully sheds metrics instead of crashing. Implement memory profiling: capture memory profiles of Agent process periodically. Identify memory leaks or excessive allocations. Build memory usage dashboard: per-server Agent memory utilization. Alert if exceeding threshold. Test memory behavior: monitor memory growth over time (days). Verify no memory leaks. Simulate high cardinality (1M metrics on single server). Verify Agent handles gracefully without OOM. For optimization, work with Grafana team: provide memory profiles, help optimize hot paths. Create runbook: if Agent OOMs on a server, diagnostics steps (memory profile, metric cardinality check, trace analysis).

Follow-up: Your optimization reduced Agent memory to 500MB, but now metric delivery latency is 30s (was <1s). Applications generating alerts are delayed. How would you balance memory efficiency with latency?

Your Grafana Agents across 500 servers are independently scraping Prometheus metrics, generating 10M timeseries total. Duplicated work: every Agent scrapes the same infrastructure metrics (node_cpu, node_memory). This is wasteful. Design a system for de-duplication and centralized collection.

Implement de-duplicated, scalable collection: (1) Hierarchical scraping—Tier-1 Agents (core metrics) scrape common infrastructure. Tier-2 Agents (application-specific) scrape only app metrics. Central aggregator de-duplicates. (2) Scrape delegation—central discovery service decides which Agent scrapes which target. One Agent scrapes node_cpu across cluster, not all 500. (3) Metric federation—smaller Agents expose metrics locally. Central Agent queries all local Agents (federation). Single scrape job pulling from all. (4) Dedup operator—use Prometheus' deduplication on scraped metrics: if metric has same value from 5 Agents, keep 1 copy. (5) Sampling—sample common metrics (infrastructure): every 5th Agent scrapes node_cpu. Central Agent aggregates. Reduces volume. (6) Filtering—each Agent's config specifies which metrics to scrape. Operator-distributed config. (7) Metrics inventory—maintain central registry: which metrics exist, which Agent should scrape, expected cardinality. Use to prevent over-collection. Implement scrape job optimization: periodically audit scrape jobs, remove duplicates. Calculate savings. Build central discovery dashboard: which Agent scrapes what, duplication rate. Alert on excessive duplication (indicating misconfiguration). Test scalability: increase servers to 1000. Measure how collection efficiency changes. Goal: constant total timeseries as servers scale (linear efficiency). For monitoring, track Prometheus scrape latency, ingestion rate, cardinality. Alert if growth is exponential (suggests new duplication).

Follow-up: Your deduplication is working, but Tier-2 Agent scraping app-specific metrics only sees partial picture (infrastructure context missing). Dashboards can't correlate. How do you balance deduplication with context?

Your Grafana Agents (600 servers) are configured via a Git repo with static YAML files. When you change Agent config, you push to Git, then manually update servers (or use configuration management). For 600 servers, this is slow. During incidents, you need config changes deployed in <5 minutes, not hours. Design a rapid config deployment system.

Implement dynamic config management: (1) Config API—expose HTTP API on central server. Agents poll /api/agent-config/my-config every 5 seconds. (2) Push notification—when config is updated, central server pushes notification to Agents (WebSocket or gRPC). Agents fetch immediately. (3) Config versioning—all configs stored in Git with versions. Agents fetch config version X. Easy rollback: revert to version Y. (4) Gradual rollout—push config to 5% of Agents first (canary). Monitor health. If good, roll out to 50%, then 100%. (5) Configuration templates—use templating (Jsonnet, Helm) to generate configs per server (hostname, region). Reduces manual config maintenance. (6) Validation before deployment—in CI/CD, validate config syntax and simulate Agent behavior before pushing. Catch errors early. (7) Rollback mechanism—if Agent detects config causes errors, auto-rollback to previous version. Alert ops. Implement rapid deployment workflow: Push change to Git → CI/CD validates and runs tests → merge to main → Config API pushed → Agents auto-reload within 5 seconds. Target deployment time: 2 minutes end-to-end. Build config change audit log: who changed what, when, approval status. For compliance, require approval for production config changes. Create dashboard: config deployment progress, version distribution (% Agents on each config version). Alert if Agents are stuck on old configs. Test rollout scenarios: simulate gradual rollout, canary failures, rollback. Ensure fast recovery.

Follow-up: Your config deployment is fast, but a bad config is deployed to all Agents. They all fail simultaneously, losing all metrics. How would you prevent catastrophic config failures?

Want to go deeper?