Prometheus Data Flow
End-to-end walkthrough of how metrics travel from scrape targets through storage to query results and alerts. Commit 01822f2
βΆ Full Pipeline Diagram
SCRAPE TARGETS (exporters, node_exporter, etc.)
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Discovery Manager β discovery/manager.go
β (Kubernetes, AWS, Consul, File, DNS, β¦) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββ
β targetgroup.Group
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Scrape Manager β scrape/manager.go
β (one scrapePool per job, relabeling) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββ
β HTTP GET /metrics
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Scrape Loop β scrape/scrape.go
β (parse text/protobuf, apply limits) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββ
β samples / exemplars / histograms
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β fanoutStorage.Appender β storage/fanout.go
ββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β
βββββββββββ΄βββββββββ
βΌ βΌ
βββββββββββ βββββββββββββββββββββββββββββββββ
β Local β β Remote Storage β
β TSDB β β storage/remote/write.go β
β β β WAL Watcher β QueueManager β
β βββββββ β β β HTTP POST remote_write β
β β WAL β β βββββββββββββββββββββββββββββββββ
β ββββ¬βββ β
β β β
β ββββΌβββ β
β βHead β β tsdb/head.go
β β + β β (in-memory XOR chunks, memSeries)
β βmmap β β
β ββββ¬βββ β
β β compaction
β ββββΌβββββββ β
β β Blocks β β tsdb/block.go
β β(on disk)β β (index + chunk files)
β βββββββββββ β
βββββββββββββββ
β
βΌ (Querier)
βββββββββββββββββββββββββββββββββββββββββββββββ
β PromQL Engine β promql/engine.go
β (parse AST β select β eval β result) β
ββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β
βββββββββββ΄ββββββββββ
βΌ βΌ
βββββββββββ βββββββββββββββββββββββ
β HTTP β β Rule Manager β rules/manager.go
β API β β (alerting + record.) β
β/api/v1/ β ββββββββββββ¬βββββββββββ
βββββββββββ β firing alerts
βΌ
βββββββββββββββ
β Notifier β notifier/manager.go
β Alertmanagerβ
βββββββββββββββ
βΆ Startup Sequence
All components are wired together in cmd/prometheus/main.go. Initialization order matters β storage must be ready before scrapers start.
- Config loaded via
config.LoadFile(); flags parsed intoflagConfig - Local TSDB opened:
tsdb.Open()replays WAL, rebuilds Head remote.NewStorage()β remote write queues created per endpointstorage.NewFanout(local, remote)β unified write surfacediscovery.NewManager()starts β SD providers launch goroutinesscrape.NewManager()starts β waits for first config sync from discoverypromql.NewEngine()created with timeout, lookback delta, limitsrules.NewManager()loads rule files, starts evaluation goroutines- Web server starts β
/api/v1/query,/metrics,/targets, etc. - SIGHUP triggers
reloadConfig()β all reloader funcs called in order
βΆ Components
Scrape Pipeline
Discovery β target groups β HTTP scrape β parse metrics β Appender
TSDB Write Path
fanoutStorage β WAL β Head memSeries β m-map chunks β disk Blocks
Remote Write
WAL watcher β QueueManager shards β protobuf HTTP POST
PromQL Engine
Parse AST β index lookup β chunk decode β expression eval
Alerting & Rules
Rule groups β PromQL eval β state machine β Alertmanager notify
βΆ Core Interfaces
All components communicate through a small set of interfaces defined in storage/interface.go.
storage/interface.go β key interfaces
L82
// Storage combines all sub-interfaces
type Storage interface {
SampleAndChunkQueryable // read path
Appendable // write path (deprecated Q2 2026)
AppendableV2 // write path (new)
StartTime() (int64, error)
Close() error
}
// Appender β transactional write interface
type Appender interface {
Append(ref SeriesRef, l labels.Labels, t int64, v float64) (SeriesRef, error)
AppendExemplar(ref SeriesRef, l labels.Labels, e exemplar.Exemplar) (SeriesRef, error)
AppendHistogram(ref SeriesRef, l labels.Labels, t int64, h *histogram.Histogram, ...) (SeriesRef, error)
Commit() error
Rollback() error
}
// Querier β read interface for a time range
type Querier interface {
Select(ctx, sortSeries bool, hints *SelectHints, matchers ...*labels.Matcher) SeriesSet
LabelNames(ctx, hints *LabelHints, matchers ...) ([]string, Warnings, error)
LabelValues(ctx, name string, hints *LabelHints, matchers ...) ([]string, Warnings, error)
Close() error
}
SeriesRef is a uint64 opaque handle returned by Append() that can be reused in subsequent calls to skip label lookup β key hot-path optimization.
βΆ Core Data Types
| Type | Package | Description |
|---|---|---|
| labels.Labels | model/labels | Sorted key=value pairs identifying a time series |
| storage.SeriesRef | storage | uint64 handle for a series within an Appender transaction |
| chunks.HeadSeriesRef | tsdb/chunks | uint64 monotonic ID assigned per series in the Head |
| histogram.Histogram | model/histogram | Native histogram with bucket counts, sum, count |
| exemplar.Exemplar | model/exemplar | High-cardinality trace ID attached to a metric sample |
| chunkenc.Chunk | tsdb/chunkenc | Compressed byte slice of (timestamp, value) pairs |
βΆ Config Reload
Prometheus supports live reload (SIGHUP or /-/reload POST). Each component registers a reloader function.
cmd/prometheus/main.go β reloader list
~L1073
reloaders = []reloader{
{name: "db_storage", reloader: localStorage.reloader},
{name: "remote_storage", reloader: remoteStorage.ApplyConfig},
{name: "web_handler", reloader: webHandler.ApplyConfig},
{name: "query_engine", reloader: func(cfg *config.Config) error { ... }},
{name: "scrape", reloader: scrapeManager.ApplyConfig},
{name: "scrape_sd", reloader: discoveryManagerScrape.ApplyConfig},
{name: "notify", reloader: notifierManager.ApplyConfig},
{name: "notify_sd", reloader: discoveryManagerNotify.ApplyConfig},
{name: "rules", reloader: rulesManager.Update},
{name: "tracing", reloader: tracingManager.ApplyConfig},
}
Reloaders run sequentially. If any fails, the reload is aborted and the previous config stays active.