Guidance for AI coding agents working in this repository. Keep this file concise and current. For end‑user docs, see README.md and https://prometheus.io/docs/alerting/alertmanager/.
Alertmanager handles alerts sent by clients such as Prometheus. It deduplicates, groups, routes, silences, and inhibits alerts, and dispatches them to receiver integrations (email, PagerDuty, Slack, webhook, etc.).
- Language: Go (see
go.modfor the required version, currentlygo 1.25). - Frontend (legacy): Elm app under
ui/app/(Node version pinned in.nvmrc). - Frontend (new): React + TypeScript + Mantine under
ui/mantine-ui/. - API: OpenAPI v2 spec in
api/v2/openapi.yaml; Go server/client/models are generated viascripts/swagger.sh. - Module path:
github.com/prometheus/alertmanager.
Top‑level packages worth knowing:
cmd/alertmanager/— main binary entry point (main.go); thin wrapper that parses flags and callsapp.app/— embeddable Alertmanager runtime extracted fromcmd/alertmanager. Owns the process lifecycle (New/Start/Stop/Reload/Run), subsystem wiring (setup), config-reload subgraph (reloader), listeners andOptions. Lets tests and other binaries run Alertmanager in‑process. See #406.cmd/amtool/— CLI for interacting with the Alertmanager API.api/— HTTP API.api/v2/is the active API;api/v1_deprecation_router.goonly returns deprecation responses.cli/—amtoolcommand implementations.cluster/— HA gossip clustering (memberlist-based).config/— YAML config parsing, validation, secrets, coordinator.dispatch/— routing tree, alert grouping, dispatcher loop.inhibit/— inhibition rule engine.mute/,silence/,timeinterval/— muting, silences (with nflog), time‑based mutes.nflog/— notification log (persisted dedup state).notify/— notification pipeline plus one subpackage per integration (slack,pagerduty,email,webhook,discord,jira,msteams,msteamsv2,opsgenie,pushover,rocketchat,sns,telegram,victorops,webex,wechat,mattermost,incidentio).template/— notification templating (Go templates + default email template).template/email.tmplis generated fromtemplate/email.html.provider/mem/— in‑memory alert provider (the only provider).store/— alert/silence store helpers.types/— core domain types (Alert,Silence,Matcher, ...).matcher/— label matcher parsing (used by routes, silences, inhibitions).featurecontrol/— feature flags wired through--enable-feature.limit/,httpserver/,tracing/— server plumbing.ui/web.go— embeds the built UI assets and serves them.examples/,doc/examples/— example configs and HA setups.test/with_api_v2/andtest/cli/— integration/e2e tests.
Generated code (do not hand‑edit):
api/v2/{models,restapi,client}/— regenerated byscripts/swagger.shfromapi/v2/openapi.yaml.ui/app/src/Data/— Elm types generated from the OpenAPI spec.template/email.tmpl— generated fromtemplate/email.htmlviatemplate/Makefile.cluster/clusterpb/cluster.pb.go,nflog/nflogpb/nflog.pb.go,silence/silencepb/silence.pb.go— regenerate viascripts/genproto.shif the.protoschema must change.
Builds and tests are driven by the shared Makefile.common plus the repo‑specific Makefile.
make build— buildalertmanagerandamtool(also builds Elm UI assets).make build-all— UI assets + regenerated API + binaries.make build BINARIES=amtool— build a single binary.make assets— regenerate ElmDatatypes andtemplate/email.tmpl.make apiv2— regenerateapi/v2/{models,restapi,client}fromapi/v2/openapi.yaml(runsscripts/swagger.sh; needs Docker).make test— full Go test suite (go test ./...) plus UI tests.make test-short(viaMakefile.common) —go test -short ./....make lint—golangci-lint run(version pinned inMakefile.common) plus UI lint.make common-format—go fmt+golangci-lint fmt(gofumpt + goimports with local prefixgithub.com/prometheus/alertmanager).make fuzz-config— short fuzz run over./config.make clean— remove generated API code, generated email template, and UI build output.
Run a single Go test package or test:
go test ./notify/slack/...
go test ./dispatch -run TestDispatcherRace -v
Run the UI dev servers directly when iterating on the frontend:
# Legacy Elm UI
cd ui/app && make build # see ui/app/CONTRIBUTING.md
# New Mantine UI
cd ui/mantine-ui && npm install && npm run dev
Run Alertmanager locally:
./alertmanager --config.file=doc/examples/simple.yml
# multi-node HA via Procfile (requires goreman):
goreman start
- Follow the lint rules in
.golangci.yml. Notable forbidden imports (enforced bydepguard):- Use
github.com/stretchr/testify/require, not.../testify/assert. - Use
github.com/go-kit/log, notgithub.com/go-kit/kit/log. - Use the standard
errors/fmt, notgithub.com/pkg/errors.
- Use
- Formatting:
gofumpt+goimportswith local prefixgithub.com/prometheus/alertmanager. Runmake common-formatbefore committing. - Comments on exported identifiers must be full sentences ending in a period (
godotlint). - Logging uses
log/slog(sloglint). Prefer structured key/value logging. - Errors: wrap with
fmt.Errorf("...: %w", err)and check witherrors.Is/errors.As(errorlint). - Keep package‑level documentation up to date (
revive: package-comments). - Tests live next to the code as
*_test.go. Larger integration tests live undertest/. Thenotify/testpackage provides shared testing helpers for notifier integrations.
- Edit
api/v2/openapi.yaml. - Run
make apiv2to regenerateapi/v2/{models,restapi,client}(requires Docker; seescripts/swagger.sh). - Run
make assetsso the Elm UI'sDatatypes stay in sync. - Update
api/v2/api.gohandlers for any new operations. - Run
make test lint.
Do not hand‑edit generated files under api/v2/models, api/v2/restapi, api/v2/client, or ui/app/src/Data.
- Each integration lives in its own package under
notify/<name>/. - Add config in
config/notifiers.go(struct, validation, defaults) and wire it intoconfig/config.goreceivers. - Register the notifier in
cmd/alertmanager/main.gowhere receivers are built. - Add unit tests in the notifier package; reuse helpers from
notify/test/. - Update
template/default.tmplonly if you are introducing new default templates. - Note the change in
CHANGELOG.mdunder the unreleased section.
config/config.goowns top‑level YAML parsing; field changes typically need:- Struct +
yamltags. UnmarshalYAMLvalidation.- Defaults in
DefaultGlobalConfig/ receiver defaults. - Tests in
config/config_test.go, possiblytestdata/fixtures.
- Struct +
- Validate behaviour with
make fuzz-configfor parser changes.
GitHub Actions and CircleCI run build, tests, and golangci-lint. Before pushing:
make common-format
make lint
make test
If you regenerate API code or UI data, commit the regenerated files alongside the source changes.
- Don't reintroduce APIv1; it was removed in 0.27.0. The only thing left under
api/v1_deprecation_router.gois a deprecation responder. - Don't bypass the notification pipeline (
notify/notify.go) — new stages should be added asnotify.Stageimplementations. - Don't add new top‑level dependencies without checking
.golangci.ymldepguardrules andgo.modminimums. - Don't commit generated artifacts unless the corresponding source (
openapi.yaml,email.html, etc.) changed in the same commit.
- Architecture diagram:
doc/arch.svg(sourcedoc/arch.xml). - Example configs:
doc/examples/simple.yml,examples/ha/,examples/webhook/. - Maintainers and ownership:
MAINTAINERS.md,CODEOWNERS. - Release process:
RELEASE.md. - UI contributing guide:
ui/app/CONTRIBUTING.md.