Skip to content

Prometheus

The prometheus lexicon types Prometheus recording and alerting rules and Alertmanager routing. chant build emits the rule file Prometheus loads through rule_files:, and the alertmanager.yml Alertmanager reads.

import { RuleGroup, Route, Receiver } from "@intentius/chant-lexicon-prometheus";
export const api = new RuleGroup({
name: "api",
rules: [
{ record: "job:http_errors:ratio5m", expr: 'sum by (job) (rate(http_requests_total{code=~"5.."}[5m])) / sum by (job) (rate(http_requests_total[5m]))' },
{ alert: "ApiErrors", expr: "job:http_errors:ratio5m > 0.05", for: "10m", labels: { severity: "page" }, annotations: { summary: "5xx ratio above 5%" } },
],
});
export const oncall = new Receiver({ name: "oncall", pagerduty_configs: [{ routing_key_file: "/etc/alertmanager/secrets/pd-key" }] });
export const fallback = new Receiver({ name: "fallback", webhook_configs: [{ url: "http://alert-sink:8080/" }] });
export const root = new Route({ receiver: fallback, group_by: ["alertname", "job"], routes: [{ matchers: ['severity="page"'], receiver: oncall }] });

The same RuleGroup renders into a Prometheus Operator PrometheusRule through the k8s lexicon, so rules are declared once whichever way Prometheus loads them.

The Slo composite builds a service level objective to a RuleGroup: error ratios per window, the error budget left, and the SRE Workbook’s multiwindow multi-burn-rate alerts. See SLOs.

The GenAiRules composite builds recording rules, opt-in alerts and spend from a declared price table for the otel lexicon’s GenAI collector preset, reading every metric name from its GenAiMetrics. See GenAI Rules.

Checks run at build time: PromQL syntax in every expr (PROM104), unique group names (PROM101), valid durations (PROM103), routes that name declared receivers (PROM201), and every alert severity routed by some route (PROM202). promtool check rules and amtool check-config are wrapped as helpers for tests and CI, and run when installed.

chant import turns an existing rule file or alertmanager.yml into this TypeScript, and chant build on the result gives the file back (see Importing Rule Files and alertmanager.yml).

MetricCount
Resources8
Property types0
Services3
Intrinsic functions0
Pseudo-parameters0
Lint rules36

Lexicon version: 0.122.0
Namespace: Prometheus