Skip to content

Editors

See amlint's findings in your editor as you type, and hover a route to see where its alerts go. amlint lsp is a language server, so it works with VS Code, Neovim, Helix and any other editor that speaks the Language Server Protocol.

You need amlint 0.6.0 or newer:

pip install -U amlint
amlint lsp --help    # check that the command is there

What you get

  • Findings as you type, on the same lines amlint check reports. amlint lints the editor buffer, so you don't have to save first. Each check code links to its section in these docs.
  • Findings in template files (.tmpl), on the line where the problem is: bad-template-file, undefined-template and template-unknown-field, with the same message as on the config's templates: line. See which files get findings.
  • Hover on a route: its matchers and the matchers on the way to it, its receiver, group_by and timings, and where each value comes from: set on this route, inherited from a parent, or Alertmanager's default. It also shows an example alert that ends on the route and the receivers it goes to, from the same simulation as amlint route.
  • Quick fixes that change the config: a misspelled receiver or time interval (undefined-receiver, undefined-time-interval) offers "Change 'db-pagr' to 'db-pager'" for the closest names, useless-continue offers to remove the continue: true line, and deprecated syntax (deprecated-match, deprecated-mute-time-intervals) is rewritten the way amlint fix does it.
  • Quick fixes for a finding you accept: add # amlint: disable=<code> to its line, or # amlint: disable-file=<code> to the top of the file. See inline suppressions.
  • Go to definition, find references and rename for receiver and time interval names. From a route's receiver:, go to the receiver; from a receiver, list the routes that use it. Rename a receiver or a time interval and every route that uses it changes too. The new name keeps the old one's quotes, and gets quotes when it needs them ("yes", "123"). Renaming to a name that already exists is refused.
  • Completion: receiver names after receiver:, time interval names in mute_time_intervals and active_time_intervals, and label names and values in matchers, source_matchers, target_matchers, match:, group_by and equal. Labels and values come from the config's matchers, and from your Prometheus rules when rules: is set (alertname= completes your rule names). It works on a line you're still typing, with names from the last version of the file that parsed.
  • Test coverage above each route: "2 of 12 tests reach this route", or "no test reaches this route", from the amlint test files that tests: maps the config to. A case reaches a route when its alert goes through it, as for amlint test --coverage.
  • Outline: the route tree, with each route's matchers and → receiver, then the receivers (with their integrations), inhibit rules (source → target) and time intervals. In VS Code it's the Outline view and the breadcrumbs above the editor.

A hover over a route looks like this:

Route route.routes[0].routes[0] · amlint

Matchers: severity="critical"

setting          value       from
receiver         db-oncall   set here
group_by         alertname   inherited from route
group_wait       10s         inherited from route.routes[0]
group_interval   5m          Alertmanager default
repeat_interval  4h          Alertmanager default

Alerts that reach it match every route on the way, unless an earlier sibling
route without continue: true takes them first:
- route.routes[0]: team="db"
- route.routes[0].routes[0]: severity="critical"

For example, an alert with team=db, severity=critical ends here and goes to db-oncall.

Which files get findings

Every YAML file that holds an Alertmanager config, in any format amlint check reads:

  • a document with route: or receivers: at the top
  • a Kubernetes Secret or ConfigMap with an alertmanager.yaml key
  • kube-prometheus-stack Helm values (alertmanager:), or a Mimir or Cortex config (alertmanager_config:)
  • prometheus-operator AlertmanagerConfig resources

Other YAML files, such as Kubernetes manifests or Prometheus rule files, get nothing. A config that doesn't parse gets one error at the broken line.

Template files (.tmpl, amlint 0.8.0 or newer) get the template findings of every config that loads them:

  • a syntax error, such as a function Alertmanager doesn't have
  • a call to a template that no file defines
  • a field the data doesn't have, such as .Labels in a define a Slack text: calls with the notification data. The type comes from the calls in the config, so the finding is in the template file, but the fix may be in the config.

amlint finds the configs among the YAML files in the workspace folder, and keeps those whose templates: globs match the file, resolved against each config's directory. Outside a workspace folder it looks in the template's directory and the one above it. A problem that several configs find, such as prod and staging loading the same file, shows once.

A template file no config loads gets its syntax errors only, and only if it reads Alertmanager's data (.Alerts, .CommonLabels, .GroupLabels and the like) or calls one of Alertmanager's own templates. Other .tmpl files, such as chezmoi or gomplate templates, get nothing: their functions aren't Alertmanager's.

Unsaved changes count both ways: edit a template and the config's templates: line updates, along with the other open template files that call it; edit the config and the template updates.

VS Code

Install the amlint extension from the Marketplace: search for "amlint" in the Extensions view, or run:

code --install-extension dpyly.amlint

Cursor, VSCodium and Gitpod install extensions from Open VSX instead of the Marketplace. Until amlint is published there, install the .vsix from the latest run of the VS Code extension workflow (its amlint-vscode artifact): cursor --install-extension amlint-<version>.vsix, or codium --install-extension ....

Then open an alertmanager.yml. The extension runs the amlint you installed, so new checks come with pip install -U amlint, not with an extension update. Settings:

Setting Default What it does
amlint.enable true Turn amlint off without uninstalling the extension.
amlint.path amlint The amlint executable. ~ and ${workspaceFolder} are expanded, for example ${workspaceFolder}/.venv/bin/amlint.
amlint.trace.server off messages or verbose logs the traffic to the amlint output channel.

amlint: Restart Server in the command palette restarts it, for example after you upgrade amlint.

If it doesn't start:

  • "can't find amlint": VS Code doesn't see amlint on its PATH, which can differ from your terminal's. Install it with pipx install amlint, or with Homebrew: brew tap danikdanik2013/amlint https://github.com/danikdanik2013/amlint, then brew install danikdanik2013/amlint/amlint. Or run which amlint in a terminal and put that path in amlint.path. Installed with Homebrew on Apple Silicon? It's in /opt/homebrew/bin, which VS Code sees only if your shell profile runs brew shellenv. Extension versions after 0.1.2 look there themselves; with 0.1.2, set amlint.path to /opt/homebrew/bin/amlint.
  • "the editor needs 0.6.0 or newer": the amlint VS Code finds predates amlint lsp. Upgrade it with brew upgrade danikdanik2013/amlint/amlint, pipx upgrade amlint or pip install -U amlint, then restart the server.

Neovim

Neovim 0.11 or newer. In your config:

vim.lsp.config("amlint", {
  cmd = { "amlint", "lsp" },
  filetypes = { "yaml", "template" },  -- Neovim calls .tmpl files "template"
  root_markers = { ".amlint.yml", ".amlint.yaml", ".git" },
})
vim.lsp.enable("amlint")

It runs next to yaml-language-server if you use that too. K shows the hover; quick fixes are in vim.lsp.buf.code_action().

Helix

In ~/.config/helix/languages.toml:

[language-server.amlint]
command = "amlint"
args = ["lsp"]

[[language]]
name = "yaml"
language-servers = ["amlint", "yaml-language-server"]

# template files: Helix has no language for .tmpl, so add it to Go templates
[[language]]
name = "gotmpl"
file-types = ["gotmpl", "tmpl"]
language-servers = ["amlint", "gopls"]

Helix asks the first server in the list for hovers, so put amlint first to get its route hovers.

Other editors

Configure your LSP client to run amlint lsp over stdio for YAML files and .tmpl template files. The server needs no initialization options.

Configure the checks

The editor reads the same project config as the CLI: ignore, severity and rules from .amlint.yml, .amlint.yaml or pyproject.toml in the workspace folder. A file outside any workspace folder uses the config next to it. Edits to the project config apply at the next change to the file; VS Code re-lints open files right away.

With rules: set, the checks against your Prometheus rules run as you type too. amlint reads the rule files again when one of them changes. If a glob matches nothing, a warning on the first line says so.

Limits

  • The Prometheus rules checks (check --rules) don't run in the editor.
  • template-file-missing looks for template files next to the file on disk, so a new file that was never saved skips it.
  • A template file is checked with a config only when amlint can read every file the config loads. A config with an absolute path in templates: (/etc/alertmanager/*.tmpl) can't be followed, so its template files get syntax errors only.
  • amlint searches the workspace folder for configs once. A config file added later counts once you open it, or after a restart of the server (amlint: Restart Server).