How akira-core/kube-state-graph works
kube-state-graph is a Go REST service that builds multi-cluster Kubernetes workload and storage graphs from VictoriaMetrics data. The main workflow is an HTTP graph request, shared request parsing and filtering, PromQL retrieval, graph construction/projection, and Cytoscape JSON serialization. The README also documents a separate storage-graph endpoint and authentication, health, metrics, and documentation routes. The excerpts show the API and graph-engine seams, but not the complete query/build implementation; edges reflect only shown calls or documented relationships.
Main entry points: engine.go Graph engine · handlers.go Graph handlers · resolver.go Route resolver · server.go HTTP server
Components 20
HTTP API
- HTTP server
internal/api/server.go - Graph handlers
internal/api/handlers.go - API key auth
internal/api/auth_middleware.go - Runtime config
internal/config/config.go
Graph engine
- Request parsing
pkg/kubegraph/parse.go - Graph engine
pkg/kubegraph/engine.go - Graph model
pkg/graph - Graph projection
pkg/graph/project.go - Storage projection
pkg/graph/project_storage.go - Cytoscape output
pkg/cytoscape/cytoscape.go
Metrics access
- PromQL router
pkg/promql/router.go - VictoriaMetrics client
pkg/promql/client.go - Backend routing config
pkg/promql/backendsfile/backendsfile.go
Route resolution
- Route resolver
pkg/route/resolver.go - Config snapshot
pkg/route/snapshot/snapshot.go - Route translation
pkg/route/translate/translate.go - Route config store
pkg/route/store/store.go - Route match check
pkg/route/matchcheck/matchcheck.go
Other components
- API caller
- VictoriaMetrics
Connections 22
- API caller → HTTP server: requests
README.md - HTTP server → Graph handlers: routes to
internal/api/server.go - HTTP server → API key auth: authenticates
- Graph handlers → Request parsing: parses with
internal/api/handlers.go - Graph handlers → Graph engine: builds via
internal/api/handlers.go - Graph handlers → Graph model: uses
internal/api/handlers.go - Graph handlers → Cytoscape output: serializes with
internal/api/handlers.go - Graph engine → PromQL router: queries through
pkg/kubegraph/engine.go - Graph engine → Graph model: builds
pkg/kubegraph/engine.go - Graph engine → Graph projection: projects graph
- Graph engine → Storage projection: projects storage
pkg/kubegraph/engine.go - Graph engine → Cytoscape output: serializes result
pkg/kubegraph/engine.go - PromQL router → VictoriaMetrics client: dispatches queries
- VictoriaMetrics client → VictoriaMetrics: queries metrics
README.md - Backend routing config → PromQL router: configures routes
- Route resolver → Route config store: loads config
pkg/route/resolver.go - Route resolver → Config snapshot: loads snapshot
pkg/route/resolver.go - Route resolver → Route translation: translates config
pkg/route/resolver.go - Route resolver → Route match check: runs checks
pkg/route/resolver.go - Config snapshot → Route config store: reads data
pkg/route/snapshot/snapshot.go - Config snapshot → Route translation: uses translator
pkg/route/snapshot/snapshot.go - Route translation → Route resolver: resolves gateways
pkg/route/translate/translate.go