Prometheus — Dependencies#
Module info#
- Module:
github.com/prometheus/prometheus - Go version: 1.25.0
- Direct dependencies: 103 (first
requireblock in go.mod, no// indirectmarker) - Indirect dependencies (explicitly listed): ~148 (second and third
requireblocks) - go.sum entries: 837 lines (~418 unique module/version pairs, capturing the full transitive graph)
Dependency categories#
Core infrastructure#
| Package | Purpose |
|---|---|
github.com/alecthomas/kingpin/v2 | CLI flag/argument parsing (replaces flag stdlib); drives the prometheus binary’s command-line interface |
github.com/alecthomas/units | Human-friendly byte/duration unit parsing for config flags |
github.com/fsnotify/fsnotify | OS-level filesystem events, used for hot-reloading of config files |
github.com/oklog/run | Actor-model runner for composing concurrent long-lived goroutines at startup |
go.uber.org/automaxprocs | Auto-sets GOMAXPROCS to match the container CPU quota (critical for correct scheduling in Kubernetes pods) |
github.com/KimMachineGun/automemlimit | Sets GOMEMLIMIT from cgroup memory limits; mirrors automaxprocs for memory |
go.yaml.in/yaml/v2, v3, v4 | YAML parsing used for all Prometheus configuration files |
github.com/grafana/regexp | Drop-in replacement for regexp with RE2 semantics and better performance; the //nolint:depguard comment in main.go explains that the stdlib package is still needed for client_golang interop |
Networking / HTTP / RPC#
| Package | Purpose |
|---|---|
google.golang.org/grpc | gRPC transport; used for remote write/read and OTLP receiver |
google.golang.org/protobuf + github.com/gogo/protobuf | Protobuf encoding/decoding; dual presence due to historical migration from gogo to the canonical google.golang.org package |
github.com/mwitkow/go-conntrack | HTTP connection tracking and labelling for metrics-aware http.Transport |
github.com/munnerz/goautoneg | HTTP content negotiation (Accept header parsing) for the /metrics endpoint |
github.com/miekg/dns | Pure-Go DNS resolver; used by DNS-based service discovery |
github.com/gorilla/websocket (indirect) | WebSocket support via the Docker SDK dependency chain |
github.com/julienschmidt/httprouter (indirect) | Fast HTTP router pulled in as a transitive dep from prometheus/alertmanager |
Data / Serialization / Storage#
| Package | Purpose |
|---|---|
github.com/cespare/xxhash/v2 | Fast 64-bit non-cryptographic hash; used heavily for label set fingerprinting in TSDB |
github.com/dennwc/varint | Variable-length integer encoding for the TSDB WAL and chunk format |
github.com/edsrzf/mmap-go | Memory-mapped files for TSDB block reads on all platforms |
github.com/golang/snappy | Snappy compression for remote write payloads and TSDB chunks |
github.com/klauspost/compress | Broader compression support (zstd, gzip) used in remote write and chunk encoding |
github.com/oklog/ulid/v2 | Monotonic, sortable IDs used to name TSDB block directories |
github.com/bboreham/go-loser | Loser-tree merge for multi-block label set iteration in TSDB queries |
github.com/json-iterator/go | Fast JSON encoder/decoder; used in high-throughput API and alertmanager notification paths |
github.com/gogo/protobuf | Legacy proto encoding still present for Remote Write v1 protocol compatibility |
go.uber.org/atomic | Type-safe atomic wrappers (supplements sync/atomic); used in TSDB head |
github.com/Code-Hex/go-generics-cache | Generic LRU/TTL cache; used for service-discovery result caching |
OpenTelemetry (OTLP bridge)#
| Package | Purpose |
|---|---|
go.opentelemetry.io/otel (+ metric, trace, sdk) | OTel SDK; Prometheus exposes traces for its own operations |
go.opentelemetry.io/otel/exporters/otlp/otlptrace/* | OTLP trace exporters (gRPC and HTTP) for distributed tracing |
go.opentelemetry.io/collector/component, consumer, pdata, processor | OTel Collector component model; Prometheus acts as a collector pipeline node for OTLP ingestion |
github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor | Converts OTel delta metrics to Prometheus-native cumulative form |
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp | HTTP middleware injecting OTel spans |
github.com/prometheus/otlptranslator | Translates OTLP metric names/types to Prometheus model |
Cloud provider SDKs (service discovery)#
| Provider | Packages |
|---|---|
| AWS | aws-sdk-go-v2 core + ec2, ecs, elasticache, kafka, lightsail, rds, sts, imds |
| Azure | azure-sdk-for-go/sdk/azcore, azidentity, armcompute/v5, armnetwork/v4 |
| GCP | google.golang.org/api, cloud.google.com/go/auth (indirect) |
| DigitalOcean | github.com/digitalocean/godo |
| Hetzner | github.com/hetznercloud/hcloud-go/v2 |
| Linode | github.com/linode/linodego |
| Vultr | github.com/vultr/govultr/v3 |
| Scaleway | github.com/scaleway/scaleway-sdk-go |
| IONOS | github.com/ionos-cloud/sdk-go/v6 |
| Outscale | github.com/outscale/osc-sdk-go/v2 |
| OVH | github.com/ovh/go-ovh |
| OpenStack | github.com/gophercloud/gophercloud/v2 |
| StackIT | github.com/stackitcloud/stackit-sdk-go/core |
These are the most striking part of Prometheus’s dependency graph: every major cloud is a first-class direct dependency because each service discovery provider gets its own SDK.
HashiCorp ecosystem#
| Package | Purpose |
|---|---|
github.com/hashicorp/consul/api | Consul service discovery |
github.com/hashicorp/nomad/api | Nomad service discovery |
github.com/hashicorp/go-retryablehttp (indirect) | Retrying HTTP client pulled in by Consul/Nomad SDKs |
Observability (self-instrumentation)#
| Package | Purpose |
|---|---|
github.com/prometheus/client_golang | Prometheus uses its own client library to instrument itself — a clear dogfooding signal |
github.com/prometheus/client_golang/exp | Experimental client features (new Remote API) |
github.com/prometheus/client_model | Shared protobuf types for the Prometheus exposition format |
github.com/prometheus/common | Shared utilities: promslog, promhttp, model types |
github.com/prometheus/alertmanager | Alertmanager API types and client, for sending alerts |
github.com/prometheus/exporter-toolkit | TLS and web config for the web server |
github.com/prometheus/sigv4 | AWS SigV4 signing for authenticated remote write to AWS endpoints |
github.com/felixge/fgprof | Full goroutine profiler (flame-graph style) exposed on /debug/fgprof |
github.com/google/pprof | pprof profile format support |
Other infrastructure / Kubernetes#
| Package | Purpose |
|---|---|
k8s.io/client-go, k8s.io/api, k8s.io/apimachinery | Kubernetes service discovery (the most complex SD backend) |
k8s.io/klog/v2 | Kubernetes logging framework; pulled in transitively by client-go |
github.com/docker/docker | Docker service discovery and Docker daemon API |
github.com/go-zookeeper/zk | Zookeeper service discovery (Nerve/Serverset) |
github.com/kolo/xmlrpc | XML-RPC client for Puppet-based service discovery (Puppet DB) |
github.com/envoyproxy/go-control-plane/envoy | xDS service discovery (Envoy control plane) |
github.com/envoyproxy/protoc-gen-validate | Protobuf validation used by the xDS integration |
golang.org/x/oauth2 | OAuth2 flows for GCP, GitHub, and generic OAuth2 SD backends |
Testing#
| Package | Purpose |
|---|---|
github.com/stretchr/testify | Standard assertion library (assert, require) |
github.com/nsf/jsondiff | JSON diff output for assertion messages |
github.com/google/go-cmp | Deep equality comparison, especially useful for proto structs |
go.uber.org/goleak | Goroutine leak detection in tests |
github.com/pb33f/libopenapi + libopenapi-validator | OpenAPI spec parsing and validation; used to test the Prometheus HTTP API spec compliance |
OpenAPI validation (unusual choice)#
pb33f/libopenapi and pb33f/libopenapi-validator are used to validate that the live Prometheus API responses conform to the bundled OpenAPI spec. This is a sophisticated approach to API contract testing and brings in a significant transitive dependency tree of its own (go-openapi/*, JSON Schema, etc.).
Stdlib reliance#
Prometheus’s core packages are stdlib-heavy. Key stdlib usage observed in cmd/prometheus/main.go and tsdb/head.go:
context— pervasive cancellation and deadline propagationnet/http— HTTP server for the web UI, API, and/metricsendpointsync(Mutex,RWMutex,WaitGroup,Once) — extensive use in TSDB and scrape managerencoding/json— used at API layerlog/slog— the project migrated tolog/slog(Go 1.21+) for structured logging, thoughprometheus/common/promslogwraps itmath,math/bits— TSDB integer arithmetic and chunk encodingregexp— still directly imported in some places wheregrafana/regexpisn’t applicableos,runtime,syscall— OS integration for signal handling, resource limits, mmap
The TSDB and PromQL engine layers are particularly stdlib-dependent: the parser, AST, and query evaluation loop use only Go builtins and internal packages, keeping that critical path dependency-free.
Shared dependencies#
Dependencies shared with other projects in the research set that create natural comparison points:
| Dependency | Also used by |
|---|---|
github.com/hashicorp/consul/api | Consul (the server), Vault, Nomad |
github.com/hashicorp/nomad/api | Nomad |
k8s.io/client-go | Kubernetes itself (source), many cloud-native tools |
google.golang.org/grpc | etcd, Kubernetes, most CNCF projects |
google.golang.org/protobuf | etcd, Kubernetes |
github.com/stretchr/testify | Virtually universal across all 50 projects |
go.opentelemetry.io/otel | Increasingly adopted by all CNCF-adjacent projects |
github.com/docker/docker | Projects with container-aware SD or tooling |
golang.org/x/oauth2 | Cloud-facing projects (Terraform, Vault, etc.) |
Vendoring#
No vendor/ directory present. Prometheus relies entirely on the Go module proxy and go.sum for dependency integrity. This is the standard modern approach for a project of this scale, though it means reproducible builds depend on module proxy availability (or a local GOMODCACHE).
The go.mod contains two exclude directives:
github.com/linode/linodego v1.0.0— excluded because that version was removed from GitHubgithub.com/grpc-ecosystem/grpc-gateway v1.14.7andgoogle.golang.org/api v0.30.0— excluded due to breaking changes (issue #7621)
And two replace directives:
- Pins
cloud.google.com/gotov0.123.0 - Pins
github.com/go-openapi/testify/v2tov2.0.2to preserve YAML assertion support
Notable dependency decisions#
Every cloud = a direct dep. Rather than abstracting cloud SDKs behind an internal HTTP layer, each service discovery provider imports its vendor SDK directly. This maximises fidelity (auth, pagination, regional endpoints) but means adding a new SD provider requires evaluating a new SDK’s entire transitive dependency tree. The build-tag plugin architecture partially mitigates this by allowing users to build a binary with only the SD providers they need.
grafana/regexp over stdlib regexp. Prometheus replaced
regexpwith a Grafana-maintained fork that offers significantly better performance for the workloads PromQL generates (many label-matching regexes against large label sets). The//nolint:depguardcomment at the import site documents exactly where the stdlib package is still required — a clean engineering decision that leaves a breadcrumb for future maintainers.Dual protobuf stacks (gogo + google). The presence of both
github.com/gogo/protobufandgoogle.golang.org/protobufreflects a long-running migration. Remote Write v1 was designed aroundgogofor performance (zero-copy, arena allocation); Remote Write v2 uses the canonical library. Prometheus deliberately maintains both to avoid breaking the installed base of receivers.OpenTelemetry as a first-class integration layer. The OTel dependency is not just for self-instrumentation; Prometheus implements full OTel Collector component interfaces (
component,consumer,processor) so it can act as a node in an OTel pipeline. This is a strategic architectural choice that positions Prometheus as a citizen of the OTel ecosystem rather than a competing silo.Minimal abstraction over stdlib HTTP. Prometheus does not use any third-party HTTP router framework (no Gin, Echo, Chi, Gorilla Mux). Routes are registered directly on
http.ServeMuxor viajulienschmidt/httprouter(which comes in transitively). This keeps the web layer thin and dependency-light.go.yaml.in instead of gopkg.in/yaml. The project has migrated to the
go.yaml.infork (v2, v3, v4 all present simultaneously), which is the CNCF-governed continuation of the widely-usedgopkg.in/yaml.v3. Having all three versions at once is a transient compatibility state, but shows forward motion toward the new fork.