summaryrefslogtreecommitdiff
path: root/gemfeed
diff options
context:
space:
mode:
Diffstat (limited to 'gemfeed')
-rw-r--r--gemfeed/2025-12-24-x-rag-observability-hackathon.html (renamed from gemfeed/DRAFT-x-rag-observability-hackathon.html)36
-rw-r--r--gemfeed/atom.xml1066
-rw-r--r--gemfeed/index.html1
3 files changed, 937 insertions, 166 deletions
diff --git a/gemfeed/DRAFT-x-rag-observability-hackathon.html b/gemfeed/2025-12-24-x-rag-observability-hackathon.html
index f37f1b7b..81992426 100644
--- a/gemfeed/DRAFT-x-rag-observability-hackathon.html
+++ b/gemfeed/2025-12-24-x-rag-observability-hackathon.html
@@ -9,10 +9,12 @@
</head>
<body>
<p class="header">
-<a href="https://foo.zone">Home</a> | <a href="https://codeberg.org/snonux/foo.zone/src/branch/content-md/gemfeed/DRAFT-x-rag-observability-hackathon.md">Markdown</a> | <a href="gemini://foo.zone/gemfeed/DRAFT-x-rag-observability-hackathon.gmi">Gemini</a>
+<a href="https://foo.zone">Home</a> | <a href="https://codeberg.org/snonux/foo.zone/src/branch/content-md/gemfeed/2025-12-24-x-rag-observability-hackathon.md">Markdown</a> | <a href="gemini://foo.zone/gemfeed/2025-12-24-x-rag-observability-hackathon.gmi">Gemini</a>
</p>
<h1 style='display: inline' id='x-rag-observability-hackathon'>X-RAG Observability Hackathon</h1><br />
<br />
+<span class='quote'>Published at 2025-12-24T09:45:29+02:00</span><br />
+<br />
<span>This blog post describes my hackathon efforts adding observability to X-RAG, a distributed Retrieval-Augmented Generation (RAG) platform built by my brother Florian. I especially made time available over the weekend to join his 3-day hackathon (attending 2 days) with the goal of instrumenting his existing distributed system with observability. What started as "let&#39;s add some metrics" turned into a comprehensive implementation of the three pillars of observability: tracing, metrics, and logs.</span><br />
<br />
<a class='textlink' href='https://github.com/florianbuetow/x-rag'>X-RAG source code on GitHub</a><br />
@@ -60,7 +62,7 @@
</ul><br />
<h2 style='display: inline' id='what-is-x-rag'>What is X-RAG?</h2><br />
<br />
-<span>X-RAG is a distributed RAG (Retrieval-Augmented Generation) platform running on Kubernetes. The idea behind RAG is simple: instead of asking an LLM to answer questions from its training data alone, you first retrieve relevant documents from your own knowledge base, then feed those documents to the LLM as context. The LLM synthesises an answer grounded in your actual content—reducing hallucinations and enabling answers about private or recent information the model was never trained on.</span><br />
+<span>X-RAG is the extendendible RAG (Retrieval-Augmented Generation) platform running on Kubernetes. The idea behind RAG is simple: instead of asking an LLM to answer questions from its training data alone, you first retrieve relevant documents from your own knowledge base, then feed those documents to the LLM as context. The LLM synthesises an answer grounded in your actual content—reducing hallucinations and enabling answers about private or recent information the model was never trained on.</span><br />
<br />
<span>X-RAG handles the full pipeline: ingest documents, chunk them into searchable pieces, generate vector embeddings, store them in a vector database, and at query time, retrieve relevant chunks and pass them to an LLM for answer generation. The system supports both local LLMs (Florian runs his on a beefy desktop) and cloud APIs like OpenAI. I configured an OpenAI API key since my laptop&#39;s CPU and GPU aren&#39;t fast enough for decent local inference.</span><br />
<br />
@@ -83,15 +85,15 @@
<br />
<pre>
┌─────────────────────────────────────────────────────────────────────────┐
-│ X-RAG Kubernetes Cluster │
+│ X-RAG Kubernetes Cluster │
├─────────────────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Search UI │ │Search Svc │ │Embed Service│ │ Indexer │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │ │
│ └────────────────┴────────────────┴────────────────┘ │
-│ │ │
-│ ▼ │
+│ │ │
+│ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Weaviate │ │ Kafka │ │ MinIO │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
@@ -120,7 +122,7 @@ xrag-k8-worker2 kindest/node:v1.32.0
<br />
<pre>
┌─────────────────────────────────────────────────────────────────────────┐
-│ Docker Host │
+│ Docker Host │
├─────────────────────────────────────────────────────────────────────────┤
│ ┌───────────────────┐ ┌───────────────────┐ ┌───────────────────┐ │
│ │ xrag-k8-control │ │ xrag-k8-worker │ │ xrag-k8-worker2 │ │
@@ -208,19 +210,19 @@ tempo-55df7dbcdd-t8fg9 1/1 Running
<br />
<pre>
┌──────────────────────────────────────────────────────────────────────┐
-│ LOGS PIPELINE │
+│ LOGS PIPELINE │
├──────────────────────────────────────────────────────────────────────┤
│ Applications write to stdout → containerd stores in /var/log/pods │
-│ │ │
-│ File tail │
-│ ▼ │
-│ Grafana Alloy (DaemonSet) │
-│ Discovers pods, extracts metadata │
-│ │ │
-│ HTTP POST /loki/api/v1/push │
-│ ▼ │
-│ Grafana Loki │
-│ Indexes labels, stores chunks │
+│ │ │
+│ File tail │
+│ ▼ │
+│ Grafana Alloy (DaemonSet) │
+│ Discovers pods, extracts metadata │
+│ │ │
+│ HTTP POST /loki/api/v1/push │
+│ ▼ │
+│ Grafana Loki │
+│ Indexes labels, stores chunks │
└──────────────────────────────────────────────────────────────────────┘
</pre>
<br />
diff --git a/gemfeed/atom.xml b/gemfeed/atom.xml
index 2f52f81d..b7d829a8 100644
--- a/gemfeed/atom.xml
+++ b/gemfeed/atom.xml
@@ -1,12 +1,928 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
- <updated>2025-12-07T10:16:25+02:00</updated>
+ <updated>2025-12-24T09:45:29+02:00</updated>
<title>foo.zone feed</title>
<subtitle>To be in the .zone!</subtitle>
<link href="https://foo.zone/gemfeed/atom.xml" rel="self" />
<link href="https://foo.zone/" />
<id>https://foo.zone/</id>
<entry>
+ <title>X-RAG Observability Hackathon</title>
+ <link href="https://foo.zone/gemfeed/2025-12-24-x-rag-observability-hackathon.html" />
+ <id>https://foo.zone/gemfeed/2025-12-24-x-rag-observability-hackathon.html</id>
+ <updated>2025-12-24T09:45:29+02:00</updated>
+ <author>
+ <name>Paul Buetow aka snonux</name>
+ <email>paul@dev.buetow.org</email>
+ </author>
+ <summary>This blog post describes my hackathon efforts adding observability to X-RAG, a distributed Retrieval-Augmented Generation (RAG) platform built by my brother Florian. I especially made time available over the weekend to join his 3-day hackathon (attending 2 days) with the goal of instrumenting his existing distributed system with observability. What started as 'let's add some metrics' turned into a comprehensive implementation of the three pillars of observability: tracing, metrics, and logs.</summary>
+ <content type="xhtml">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ <h1 style='display: inline' id='x-rag-observability-hackathon'>X-RAG Observability Hackathon</h1><br />
+<br />
+<span>This blog post describes my hackathon efforts adding observability to X-RAG, a distributed Retrieval-Augmented Generation (RAG) platform built by my brother Florian. I especially made time available over the weekend to join his 3-day hackathon (attending 2 days) with the goal of instrumenting his existing distributed system with observability. What started as "let&#39;s add some metrics" turned into a comprehensive implementation of the three pillars of observability: tracing, metrics, and logs.</span><br />
+<br />
+<a class='textlink' href='https://github.com/florianbuetow/x-rag'>X-RAG source code on GitHub</a><br />
+<br />
+<h2 style='display: inline' id='table-of-contents'>Table of Contents</h2><br />
+<br />
+<ul>
+<li><a href='#x-rag-observability-hackathon'>X-RAG Observability Hackathon</a></li>
+<li>⇢ <a href='#what-is-x-rag'>What is X-RAG?</a></li>
+<li>⇢ <a href='#running-kubernetes-locally-with-kind'>Running Kubernetes locally with Kind</a></li>
+<li>⇢ <a href='#motivation'>Motivation</a></li>
+<li>⇢ <a href='#the-observability-stack'>The observability stack</a></li>
+<li>⇢ <a href='#grafana-alloy-the-unified-collector'>Grafana Alloy: the unified collector</a></li>
+<li>⇢ <a href='#centralised-logging-with-loki'>Centralised logging with Loki</a></li>
+<li>⇢ ⇢ <a href='#alloy-configuration-for-logs'>Alloy configuration for logs</a></li>
+<li>⇢ ⇢ <a href='#querying-logs-with-logql'>Querying logs with LogQL</a></li>
+<li>⇢ <a href='#metrics-with-prometheus'>Metrics with Prometheus</a></li>
+<li>⇢ ⇢ <a href='#alloy-configuration-for-application-metrics'>Alloy configuration for application metrics</a></li>
+<li>⇢ ⇢ <a href='#kubernetes-metrics-kubelet-cadvisor-and-kube-state-metrics'>Kubernetes metrics: kubelet, cAdvisor, and kube-state-metrics</a></li>
+<li>⇢ ⇢ <a href='#infrastructure-metrics-kafka-redis-minio'>Infrastructure metrics: Kafka, Redis, MinIO</a></li>
+<li>⇢ <a href='#distributed-tracing-with-tempo'>Distributed tracing with Tempo</a></li>
+<li>⇢ ⇢ <a href='#understanding-traces-spans-and-the-trace-tree'>Understanding traces, spans, and the trace tree</a></li>
+<li>⇢ ⇢ <a href='#how-trace-context-propagates'>How trace context propagates</a></li>
+<li>⇢ ⇢ <a href='#implementation'>Implementation</a></li>
+<li>⇢ ⇢ <a href='#alloy-configuration-for-traces'>Alloy configuration for traces</a></li>
+<li>⇢ <a href='#async-ingestion-trace-walkthrough'>Async ingestion trace walkthrough</a></li>
+<li>⇢ ⇢ <a href='#step-1-ingest-a-document'>Step 1: Ingest a document</a></li>
+<li>⇢ ⇢ <a href='#step-2-find-the-ingestion-trace'>Step 2: Find the ingestion trace</a></li>
+<li>⇢ ⇢ <a href='#step-3-fetch-the-complete-trace'>Step 3: Fetch the complete trace</a></li>
+<li>⇢ ⇢ <a href='#step-4-analyse-the-async-trace'>Step 4: Analyse the async trace</a></li>
+<li>⇢ ⇢ <a href='#viewing-traces-in-grafana'>Viewing traces in Grafana</a></li>
+<li>⇢ <a href='#end-to-end-search-trace-walkthrough'>End-to-end search trace walkthrough</a></li>
+<li>⇢ ⇢ <a href='#step-1-make-a-search-request'>Step 1: Make a search request</a></li>
+<li>⇢ ⇢ <a href='#step-2-query-tempo-for-the-trace'>Step 2: Query Tempo for the trace</a></li>
+<li>⇢ ⇢ <a href='#step-3-analyse-the-trace'>Step 3: Analyse the trace</a></li>
+<li>⇢ ⇢ <a href='#step-4-search-traces-with-traceql'>Step 4: Search traces with TraceQL</a></li>
+<li>⇢ ⇢ <a href='#viewing-the-search-trace-in-grafana'>Viewing the search trace in Grafana</a></li>
+<li>⇢ <a href='#correlating-the-three-signals'>Correlating the three signals</a></li>
+<li>⇢ <a href='#grafana-dashboards'>Grafana dashboards</a></li>
+<li>⇢ <a href='#results-two-days-well-spent'>Results: two days well spent</a></li>
+<li>⇢ <a href='#slis-slos-and-slas'>SLIs, SLOs and SLAs</a></li>
+<li>⇢ <a href='#using-amp-for-ai-assisted-development'>Using Amp for AI-assisted development</a></li>
+<li>⇢ <a href='#other-changes-along-the-way'>Other changes along the way</a></li>
+<li>⇢ <a href='#lessons-learned'>Lessons learned</a></li>
+</ul><br />
+<h2 style='display: inline' id='what-is-x-rag'>What is X-RAG?</h2><br />
+<br />
+<span>X-RAG is the extendendible RAG (Retrieval-Augmented Generation) platform running on Kubernetes. The idea behind RAG is simple: instead of asking an LLM to answer questions from its training data alone, you first retrieve relevant documents from your own knowledge base, then feed those documents to the LLM as context. The LLM synthesises an answer grounded in your actual content—reducing hallucinations and enabling answers about private or recent information the model was never trained on.</span><br />
+<br />
+<span>X-RAG handles the full pipeline: ingest documents, chunk them into searchable pieces, generate vector embeddings, store them in a vector database, and at query time, retrieve relevant chunks and pass them to an LLM for answer generation. The system supports both local LLMs (Florian runs his on a beefy desktop) and cloud APIs like OpenAI. I configured an OpenAI API key since my laptop&#39;s CPU and GPU aren&#39;t fast enough for decent local inference.</span><br />
+<br />
+<span>All services are implemented in Python. I&#39;m more used to Ruby, Go, and Bash these days, but for this project it didn&#39;t matter—Python&#39;s OpenTelemetry integration is straightforward, I wasn&#39;t planning to write or rewrite tons of application code, and with GenAI assistance the language barrier was a non-issue. The OpenTelemetry concepts and patterns should translate to other languages too—the SDK APIs are intentionally similar across Python, Go, Java, and others.</span><br />
+<br />
+<span>X-RAG consists of several independently scalable microservices:</span><br />
+<br />
+<ul>
+<li>Search UI: FastAPI web interface for queries</li>
+<li>Ingestion API: Document upload endpoint</li>
+<li>Embedding Service: gRPC service for vector embeddings</li>
+<li>Indexer: Kafka consumer that processes documents</li>
+<li>Search Service: gRPC service orchestrating the RAG pipeline</li>
+</ul><br />
+<span>The Embedding Service deserves extra explanation because in the beginning I didn&#39;t really knew what it was. Text isn&#39;t directly searchable in a vector database—you need to convert it to numerical vectors (embeddings) that capture semantic meaning. The Embedding Service takes text chunks and calls an embedding model (OpenAI&#39;s <span class='inlinecode'>text-embedding-3-small</span> in my case, or a local model on Florian&#39;s setup) to produce these vectors. For the LLM search completion answer, I used <span class='inlinecode'>gpt-4o-mini</span>.</span><br />
+<br />
+<span>Similar concepts end up with similar vectors, so "What is machine learning?" and "Explain ML" produce vectors close together in the embedding space. At query time, your question gets embedded too, and the vector database finds chunks with nearby vectors—that&#39;s semantic search.</span><br />
+<br />
+<span>The data layer includes Weaviate (vector database with hybrid search), Kafka (message queue), MinIO (object storage), and Redis (cache). All of this runs in a Kind Kubernetes cluster for local development, with the same manifests deployable to production.</span><br />
+<br />
+<pre>
+┌─────────────────────────────────────────────────────────────────────────┐
+│ X-RAG Kubernetes Cluster │
+├─────────────────────────────────────────────────────────────────────────┤
+│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
+│ │ Search UI │ │Search Svc │ │Embed Service│ │ Indexer │ │
+│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
+│ │ │ │ │ │
+│ └────────────────┴────────────────┴────────────────┘ │
+│ │ │
+│ ▼ │
+│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
+│ │ Weaviate │ │ Kafka │ │ MinIO │ │
+│ └─────────────┘ └─────────────┘ └─────────────┘ │
+└─────────────────────────────────────────────────────────────────────────┘
+</pre>
+<br />
+<h2 style='display: inline' id='running-kubernetes-locally-with-kind'>Running Kubernetes locally with Kind</h2><br />
+<br />
+<span>X-RAG runs on Kubernetes, but you don&#39;t need a cloud account to develop it. The project uses Kind (Kubernetes in Docker)—a tool originally created by the Kubernetes SIG for testing Kubernetes itself.</span><br />
+<br />
+<a class='textlink' href='https://kind.sigs.k8s.io/'>Kind - Kubernetes in Docker</a><br />
+<br />
+<span>Kind spins up a full Kubernetes cluster using Docker containers as nodes. The control plane (API server, etcd, scheduler, controller-manager) runs in one container, and worker nodes run in separate containers. Inside these "node containers," pods run just like they would on real servers—using containerd as the container runtime. It&#39;s containers all the way down.</span><br />
+<br />
+<span>Technically, each Kind node is a Docker container running a minimal Linux image with kubelet and containerd installed. When you deploy a pod, kubelet inside the node container instructs containerd to pull and run the container image. So you have Docker running node containers, and inside those, containerd running application containers. Network-wise, Kind sets up a Docker bridge network and uses CNI plugins (kindnet by default) for pod networking within the cluster.</span><br />
+<br />
+<pre>
+$ docker ps --format "table {{.Names}}\t{{.Image}}"
+NAMES IMAGE
+xrag-k8-control-plane kindest/node:v1.32.0
+xrag-k8-worker kindest/node:v1.32.0
+xrag-k8-worker2 kindest/node:v1.32.0
+</pre>
+<br />
+<span>The <span class='inlinecode'>kindest/node</span> image contains everything needed: kubelet, containerd, CNI plugins, and pre-pulled pause containers. Port mappings in the Kind config expose services to the host—that&#39;s how http://localhost:8080 reaches the search-ui running inside a pod, inside a worker container, inside Docker.</span><br />
+<br />
+<pre>
+┌─────────────────────────────────────────────────────────────────────────┐
+│ Docker Host │
+├─────────────────────────────────────────────────────────────────────────┤
+│ ┌───────────────────┐ ┌───────────────────┐ ┌───────────────────┐ │
+│ │ xrag-k8-control │ │ xrag-k8-worker │ │ xrag-k8-worker2 │ │
+│ │ -plane (container)│ │ (container) │ │ (container) │ │
+│ │ │ │ │ │ │ │
+│ │ K8s API server │ │ Pods: │ │ Pods: │ │
+│ │ etcd, scheduler │ │ • search-ui │ │ • weaviate │ │
+│ │ │ │ • search-service │ │ • kafka │ │
+│ │ │ │ • embedding-svc │ │ • prometheus │ │
+│ │ │ │ • indexer │ │ • grafana │ │
+│ └───────────────────┘ └───────────────────┘ └───────────────────┘ │
+└─────────────────────────────────────────────────────────────────────────┘
+</pre>
+<br />
+<span>Why Kind? It gives you a real Kubernetes environment—the same manifests deploy to production clouds unchanged. No minikube quirks, no Docker Compose translation layer. Just Kubernetes. I already have a k3s cluster running at home, but Kind made collaboration easier—everyone working on X-RAG gets the exact same setup by cloning the repo and running <span class='inlinecode'>make cluster-start</span>.</span><br />
+<br />
+<span>Florian developed X-RAG on macOS, but it worked seamlessly on my Linux laptop. The only difference was Docker&#39;s resource allocation: on macOS you configure limits in Docker Desktop, on Linux it uses host resources directly. That&#39;s because under macOS the Linux Docker containers run on an emulation layer as macOS is not Linux.</span><br />
+<br />
+<span>My hardware: a ThinkPad X1 Carbon Gen 9 with an 11th Gen Intel Core i7-1185G7 (4 cores, 8 threads at 3.00GHz) and 32GB RAM (running Fedora Linux). During the hackathon, memory usage peaked around 15GB—comfortable headroom. CPU was the bottleneck; with ~38 pods running across all namespaces (rag-system, monitoring, kube-system, etc.), plus Discord for the remote video call and Tidal streaming hi-res music, things got tight. When rebuilding Docker images or restarting the cluster, Discord video and audio would stutter—my fellow hackers probably wondered why I kept freezing mid-sentence. A beefier CPU would have meant less waiting and smoother calls, but it was manageable.</span><br />
+<br />
+<h2 style='display: inline' id='motivation'>Motivation</h2><br />
+<br />
+<span>When I joined the hackathon, Florian&#39;s X-RAG was functional but opaque. With five services communicating via gRPC, Kafka, and HTTP, debugging was cumbersome. When a search request take 5 seconds, there was no visibility into where the time was being spent. Was it the embedding generation? The vector search? The LLM synthesis? Nobody would be able to figure it out quickly.</span><br />
+<br />
+<span>Distributed systems are inherently opaque. Each service logs its own view of the world, but correlating events across service boundaries is archaeology. Grepping through logs on many pods, trying to mentally reconstruct what happened—not fun. This was the perfect hackathon project: Explore this Observability Stack in greater depth.</span><br />
+<br />
+<h2 style='display: inline' id='the-observability-stack'>The observability stack</h2><br />
+<br />
+<span>Before diving into implementation, here&#39;s what I deployed. The complete stack runs in the monitoring namespace:</span><br />
+<br />
+<pre>
+$ kubectl get pods -n monitoring
+NAME READY STATUS
+alloy-84ddf4cd8c-7phjp 1/1 Running
+grafana-6fcc89b4d6-pnh8l 1/1 Running
+kube-state-metrics-5d954c569f-2r45n 1/1 Running
+loki-8c9bbf744-sc2p5 1/1 Running
+node-exporter-kb8zz 1/1 Running
+node-exporter-zcrdz 1/1 Running
+node-exporter-zmskc 1/1 Running
+prometheus-7f755f675-dqcht 1/1 Running
+tempo-55df7dbcdd-t8fg9 1/1 Running
+</pre>
+<br />
+<span>Each component has a specific role:</span><br />
+<br />
+<ul>
+<li><span class='inlinecode'>Grafana Alloy</span>: The unified collector. Receives OTLP from applications, scrapes Prometheus endpoints, tails log files. Think of it as the central nervous system.</li>
+<li><span class='inlinecode'>Prometheus</span>: Time-series database for metrics. Stores counters, gauges, and histograms with 15-day retention.</li>
+<li><span class='inlinecode'>Tempo</span>: Trace storage. Receives spans via OTLP, correlates them by trace ID, enables TraceQL queries.</li>
+<li><span class='inlinecode'>Loki</span>: Log aggregation. Indexes labels (namespace, pod, container), stores log chunks, enables LogQL queries.</li>
+<li><span class='inlinecode'>Grafana</span>: The unified UI. Queries all three backends, correlates signals, displays dashboards.</li>
+<li><span class='inlinecode'>kube-state-metrics</span>: Exposes Kubernetes object metrics (pod status, deployments, resource requests).</li>
+<li><span class='inlinecode'>node-exporter</span>: Exposes host-level metrics (CPU, memory, disk, network) from each Kubernetes node.</li>
+</ul><br />
+<span>Everything is accessible via port-forwards:</span><br />
+<br />
+<ul>
+<li>Grafana: http://localhost:3000 (unified UI for all three signals)</li>
+<li>Prometheus: http://localhost:9090 (metrics queries)</li>
+<li>Tempo: http://localhost:3200 (trace queries)</li>
+<li>Loki: http://localhost:3100 (log queries)</li>
+</ul><br />
+<h2 style='display: inline' id='grafana-alloy-the-unified-collector'>Grafana Alloy: the unified collector</h2><br />
+<br />
+<span>Before diving into the individual signals, I want to highlight Grafana Alloy—the component that ties everything together. Alloy is Grafana&#39;s vendor-neutral OpenTelemetry Collector distribution, and it became the backbone of the observability stack.</span><br />
+<br />
+<a class='textlink' href='https://grafana.com/docs/alloy/latest/'>Grafana Alloy documentation</a><br />
+<br />
+<span>Why use a centralised collector instead of having each service push directly to backends?</span><br />
+<br />
+<ul>
+<li><span class='inlinecode'>Decoupling</span>: Applications don&#39;t need to know about Prometheus, Tempo, or Loki. They speak OTLP, and Alloy handles the translation.</li>
+<li><span class='inlinecode'>Unified timestamps</span>: All telemetry flows through one system, making correlation in Grafana more reliable.</li>
+<li><span class='inlinecode'>Processing pipeline</span>: Batch data before sending, filter noisy metrics, enrich with labels—all in one place.</li>
+<li><span class='inlinecode'>Backend flexibility</span>: Switch from Tempo to Jaeger without changing application code.</li>
+</ul><br />
+<span>Alloy uses a configuration language called River, which feels similar to Terraform&#39;s HCL—declarative blocks with attributes. If you&#39;ve written Terraform, River will look familiar. The full Alloy configuration runs to over 1400 lines with comments explaining each section. It handles OTLP receiving, batch processing, Prometheus export, Tempo export, Kubernetes metrics scraping, infrastructure metrics, and pod log collection. All three signals—metrics, traces, logs—flow through this single component, making Alloy the central nervous system of the observability stack.</span><br />
+<br />
+<span>In the following sections, I&#39;ll cover each observability pillar and show the relevant Alloy configuration for each.</span><br />
+<br />
+<h2 style='display: inline' id='centralised-logging-with-loki'>Centralised logging with Loki</h2><br />
+<br />
+<span>Getting all logs in one place was the foundation. I deployed Grafana Loki in the monitoring namespace, with Grafana Alloy running as a DaemonSet on each node to collect logs.</span><br />
+<br />
+<pre>
+┌──────────────────────────────────────────────────────────────────────┐
+│ LOGS PIPELINE │
+├──────────────────────────────────────────────────────────────────────┤
+│ Applications write to stdout → containerd stores in /var/log/pods │
+│ │ │
+│ File tail │
+│ ▼ │
+│ Grafana Alloy (DaemonSet) │
+│ Discovers pods, extracts metadata │
+│ │ │
+│ HTTP POST /loki/api/v1/push │
+│ ▼ │
+│ Grafana Loki │
+│ Indexes labels, stores chunks │
+└──────────────────────────────────────────────────────────────────────┘
+</pre>
+<br />
+<h3 style='display: inline' id='alloy-configuration-for-logs'>Alloy configuration for logs</h3><br />
+<br />
+<span>Alloy discovers pods via the Kubernetes API, tails their log files from /var/log/pods/, and ships to Loki. Importantly, Alloy runs as a DaemonSet on each worker node—it doesn&#39;t run inside the application pods. Since containerd writes all container stdout/stderr to /var/log/pods/ on the node&#39;s filesystem, Alloy can tail logs for every pod on that node from a single location without any sidecar injection:</span><br />
+<br />
+<pre>
+loki.source.kubernetes "pod_logs" {
+ targets = discovery.relabel.pod_logs.output
+ forward_to = [loki.process.pod_logs.receiver]
+}
+
+loki.write "default" {
+ endpoint {
+ url = "http://loki.monitoring.svc.cluster.local:3100/loki/api/v1/push"
+ }
+}
+</pre>
+<br />
+<h3 style='display: inline' id='querying-logs-with-logql'>Querying logs with LogQL</h3><br />
+<br />
+<span>Now I could query logs in Loki (e.g. via Grafana UI) with LogQL:</span><br />
+<br />
+<pre>
+{namespace="rag-system", container="search-ui"} |= "ERROR"
+</pre>
+<br />
+<h2 style='display: inline' id='metrics-with-prometheus'>Metrics with Prometheus</h2><br />
+<br />
+<span>I added Prometheus metrics to every service. Following the Four Golden Signals (latency, traffic, errors, saturation), I instrumented the codebase with histograms, counters, and gauges:</span><br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><b><u><font color="#000000">from</font></u></b> prometheus_client <b><u><font color="#000000">import</font></u></b> Histogram, Counter, Gauge
+
+search_duration = Histogram(
+ <font color="#808080">"search_service_request_duration_seconds"</font>,
+ <font color="#808080">"Total duration of Search Service requests"</font>,
+ [<font color="#808080">"method"</font>],
+ buckets=[<font color="#000000">0.1</font>, <font color="#000000">0.25</font>, <font color="#000000">0.5</font>, <font color="#000000">1.0</font>, <font color="#000000">2.5</font>, <font color="#000000">5.0</font>, <font color="#000000">10.0</font>, <font color="#000000">20.0</font>, <font color="#000000">30.0</font>, <font color="#000000">60.0</font>],
+)
+
+errors_total = Counter(
+ <font color="#808080">"search_service_errors_total"</font>,
+ <font color="#808080">"Error count by type"</font>,
+ [<font color="#808080">"method"</font>, <font color="#808080">"error_type"</font>],
+)
+</pre>
+<br />
+<span>Initially, I used Prometheus scraping—each service exposed a /metrics endpoint, and Prometheus pulled metrics every 15 seconds. This worked, but I wanted a unified pipeline.</span><br />
+<br />
+<h3 style='display: inline' id='alloy-configuration-for-application-metrics'>Alloy configuration for application metrics</h3><br />
+<br />
+<span>The breakthrough came with Grafana Alloy as an OpenTelemetry collector. Services now push metrics via OTLP (OpenTelemetry Protocol), and Alloy converts them to Prometheus format:</span><br />
+<br />
+<pre>
+┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
+│ search-ui │ │search-svc │ │embed-svc │ │ indexer │
+│ OTel Meter │ │ OTel Meter │ │ OTel Meter │ │ OTel Meter │
+│ │ │ │ │ │ │ │ │ │ │ │
+│ OTLPExporter│ │ OTLPExporter│ │ OTLPExporter│ │ OTLPExporter│
+└──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘
+ │ │ │ │
+ └────────────────┴────────────────┴────────────────┘
+ │
+ ▼ OTLP/gRPC (port 4317)
+ ┌─────────────────────┐
+ │ Grafana Alloy │
+ └──────────┬──────────┘
+ │ prometheus.remote_write
+ ▼
+ ┌─────────────────────┐
+ │ Prometheus │
+ └─────────────────────┘
+</pre>
+<br />
+<span>Alloy receives OTLP on ports 4317 (gRPC) or 4318 (HTTP), batches the data for efficiency, and exports to Prometheus:</span><br />
+<br />
+<pre>
+otelcol.receiver.otlp "default" {
+ grpc { endpoint = "0.0.0.0:4317" }
+ http { endpoint = "0.0.0.0:4318" }
+ output {
+ metrics = [otelcol.processor.batch.metrics.input]
+ traces = [otelcol.processor.batch.traces.input]
+ }
+}
+
+otelcol.processor.batch "metrics" {
+ timeout = "5s"
+ send_batch_size = 1000
+ output { metrics = [otelcol.exporter.prometheus.default.input] }
+}
+
+otelcol.exporter.prometheus "default" {
+ forward_to = [prometheus.remote_write.prom.receiver]
+}
+</pre>
+<br />
+<span>Instead of sending each metric individually, Alloy accumulates up to 1000 metrics (or waits 5 seconds) before flushing. This reduces network overhead and protects backends from being overwhelmed.</span><br />
+<br />
+<h3 style='display: inline' id='kubernetes-metrics-kubelet-cadvisor-and-kube-state-metrics'>Kubernetes metrics: kubelet, cAdvisor, and kube-state-metrics</h3><br />
+<br />
+<span>Alloy also pulls metrics from Kubernetes itself—kubelet resource metrics, cAdvisor container metrics, and kube-state-metrics for cluster state.</span><br />
+<br />
+<span>Why three separate sources? It does feel fragmented, but each serves a distinct purpose. <span class='inlinecode'>kubelet</span> exposes resource metrics about pod CPU and memory usage from its own bookkeeping—lightweight summaries of what&#39;s running on each node. <span class='inlinecode'>cAdvisor</span> (Container Advisor) runs inside kubelet and provides detailed container-level metrics: CPU throttling, memory working sets, filesystem I/O, network bytes. These are the raw runtime stats from containerd. <span class='inlinecode'>kube-state-metrics</span> is different—it doesn&#39;t measure resource usage at all. Instead, it queries the Kubernetes API and exposes the *desired state*: how many replicas a Deployment wants, whether a Pod is pending or running, what resource requests and limits are configured. You need all three because "container used 500MB" (cAdvisor), "pod requested 1GB" (kube-state-metrics), and "node has 4GB available" (kubelet) are complementary views. The fragmentation is a consequence of Kubernetes&#39; architecture—no single component has the complete picture.</span><br />
+<br />
+<span>None of these components speak OpenTelemetry—they all expose Prometheus-format metrics via HTTP endpoints. That&#39;s why Alloy uses <span class='inlinecode'>prometheus.scrape</span> instead of receiving OTLP pushes. Alloy handles both worlds: OTLP from our applications, Prometheus scraping for infrastructure.</span><br />
+<br />
+<pre>
+prometheus.scrape "kubelet_resource" {
+ targets = discovery.relabel.kubelet.output
+ job_name = "kubelet-resource"
+ scheme = "https"
+ scrape_interval = "30s"
+ bearer_token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token"
+ tls_config { insecure_skip_verify = true }
+ forward_to = [prometheus.remote_write.prom.receiver]
+}
+
+prometheus.scrape "cadvisor" {
+ targets = discovery.relabel.cadvisor.output
+ job_name = "cadvisor"
+ scheme = "https"
+ scrape_interval = "60s"
+ bearer_token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token"
+ tls_config { insecure_skip_verify = true }
+ forward_to = [prometheus.relabel.cadvisor_filter.receiver]
+}
+
+prometheus.scrape "kube_state_metrics" {
+ targets = [
+ {"__address__" = "kube-state-metrics.monitoring.svc.cluster.local:8080"},
+ ]
+ job_name = "kube-state-metrics"
+ scrape_interval = "30s"
+ forward_to = [prometheus.relabel.kube_state_filter.receiver]
+}
+</pre>
+<br />
+<span>Note that <span class='inlinecode'>kubelet</span> and <span class='inlinecode'>cAdvisor</span> require HTTPS with bearer token authentication (using the service account token mounted by Kubernetes), while <span class='inlinecode'>kube-state-metrics</span> is a simple HTTP target. <span class='inlinecode'>cAdvisor</span> is scraped less frequently (60s) because it returns many more metrics with higher cardinality.</span><br />
+<br />
+<h3 style='display: inline' id='infrastructure-metrics-kafka-redis-minio'>Infrastructure metrics: Kafka, Redis, MinIO</h3><br />
+<br />
+<span>Application metrics weren&#39;t enough. I also needed visibility into the data layer. Each infrastructure component has a specific role in X-RAG and got its own exporter:</span><br />
+<br />
+<span><span class='inlinecode'>Redis</span> is the caching layer. It stores search results and embeddings to avoid redundant API calls to OpenAI. We collect 25 metrics via oliver006/redis_exporter running as a sidecar, including cache hit/miss rates, memory usage, connected clients, and command latencies. The key metric? <span class='inlinecode'>redis_keyspace_hits_total / (redis_keyspace_hits_total + redis_keyspace_misses_total)</span> tells you if caching is actually helping.</span><br />
+<br />
+<span><span class='inlinecode'>Kafka</span> is the message queue connecting the ingestion API to the indexer. Documents are published to a topic, and the indexer consumes them asynchronously. We collect 12 metrics via danielqsj/kafka-exporter, with consumer lag being the most critical—it shows how far behind the indexer is. High lag means documents aren&#39;t being indexed fast enough.</span><br />
+<br />
+<span><span class='inlinecode'>MinIO</span> is the S3-compatible object storage where raw documents are stored before processing. We collect 16 metrics from its native /minio/v2/metrics/cluster endpoint, covering request rates, error counts, storage usage, and cluster health.</span><br />
+<br />
+<span>You can verify these counts by querying Prometheus directly:</span><br />
+<br />
+<pre>
+$ curl -s &#39;http://localhost:9090/api/v1/label/__name__/values&#39; \
+ | jq -r &#39;.data[]&#39; | grep -c &#39;^redis_&#39;
+25
+$ curl -s &#39;http://localhost:9090/api/v1/label/__name__/values&#39; \
+ | jq -r &#39;.data[]&#39; | grep -c &#39;^kafka_&#39;
+12
+$ curl -s &#39;http://localhost:9090/api/v1/label/__name__/values&#39; \
+ | jq -r &#39;.data[]&#39; | grep -c &#39;^minio_&#39;
+16
+</pre>
+<br />
+<a class='textlink' href='https://github.com/florianbuetow/x-rag/blob/main/infra/k8s/monitoring/alloy-config.yaml'>Full Alloy configuration with detailed metric filtering</a><br />
+<br />