Open-Source Wikis

/

Grafana

/

Backend

/

Services

grafana/grafana

Backend services

pkg/services/ is the business-logic tree. With 73 service domains it dominates the backend by both file count and surface area.

Naming pattern

Most services follow a common shape:

pkg/services/<domain>/
├── <domain>.go            # Service interface + types + errors
├── <domain>impl/          # Concrete implementation (or directly: e.g. <domain>Service struct)
├── <domain>test/          # In-package test fakes
├── api/                   # HTTP handlers when the service exposes its own router
├── store/ or database/    # SQL access
└── models/                # Persistent + DTO Go structs

Some long-lived services keep handlers and types directly inside pkg/api/<domain>.go; newer ones prefer a service-local api/ package. There is no single canonical layout — match the surrounding code.

Domain catalog (high level)

The 73 services group naturally into themes:

Identity & access

Tenancy

Dashboards & content

Datasources & queries

Alerting

Plugins & rendering

Storage

Operations & migration

How services are wired

Each service has a ProvideService(...) constructor (Go's wire idiom). The constructor is added to a wire.NewSet and the entire graph is materialized in pkg/server/wire.gopkg/server/wire_gen.go after running make gen-go.

Many services also implement registry.BackgroundService — an interface that lets them run a goroutine for the lifetime of the server (e.g. ngalert scheduler, live coordinator, plugin updater). Background services are started by pkg/registry/ after Wire builds the graph.

Cross-cutting helpers

Where to add a new service

  1. Create pkg/services/<name>/<name>.go defining the interface and types.
  2. Implement under <name>impl/ (or directly).
  3. Add a ProvideService constructor and wire.NewSet.
  4. Reference the new set from pkg/server/wire.go.
  5. Run make gen-go.
  6. Add tests under <name>impl/<name>_test.go and (if HTTP) under pkg/api/.
  7. If HTTP-facing: register routes in pkg/api/api.go or, preferably, expose via an app-platform resource.

See API layer for HTTP wiring details and Patterns and conventions for naming/error conventions.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Services – Grafana wiki | Factory