openenvforge's picture
3amBench v0.2.0
44084af verified
Raw History Blame Contribute Delete
23.8 kB
#!/bin/bash
# partial: even-indexed requirements + one plausible mistake
set -euo pipefail
cd /workspace/monitoring
mkdir -p 'alertmanager'
cat > 'alertmanager/alertmanager.yml' <<'AF_EOF'
# Shared Alertmanager config (this repo, platform and data Prometheus servers).
# Receivers belong to the teams; ask before touching someone else's.
global:
resolve_timeout: 5m
slack_api_url_file: /etc/alertmanager/secrets/slack-url
smtp_smarthost: smtp.mercadorila.example:587
smtp_from: alertmanager@mercadorila.example
templates:
- /etc/alertmanager/templates/*.tmpl
route:
receiver: slack-alerts-default
group_by: [alertname, service]
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
routes:
# rule evaluation problems. Nobody pages on these (yet).
- matchers:
- alertname=~"PrometheusRuleFailures|PrometheusRuleEvaluationSlow"
receiver: slack-prometheus-meta
# SRE sees every page as FYI; owners get paged by their own subtree below.
- matchers:
- severity=~"page|critical"
receiver: slack-sre-fyi
continue: true
- matchers:
- team="fulfillment"
receiver: slack-fulfillment
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-fulfillment
continue: true
- matchers:
- severity="ticket"
receiver: jira-fulfillment
continue: true
- receiver: slack-fulfillment
- matchers:
- team="checkout-core"
receiver: slack-checkout-core
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-checkout-core
continue: true
- matchers:
- severity="ticket"
receiver: jira-checkout-core
continue: true
- receiver: slack-checkout-core
- matchers:
- team="growth"
receiver: slack-growth
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-growth
continue: true
- matchers:
- severity="ticket"
receiver: jira-growth
continue: true
- receiver: slack-growth
- matchers:
- team="product-catalog"
receiver: slack-product-catalog
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-product-catalog
continue: true
- matchers:
- severity="ticket"
receiver: jira-product-catalog
continue: true
- receiver: slack-product-catalog
# storefront: still on the old match syntax
- match:
team: storefront
receiver: slack-storefront
routes:
- match_re:
severity: page|critical
receiver: pagerduty-storefront
continue: true
- match:
severity: ticket
receiver: jira-storefront
continue: true
- receiver: slack-storefront
# product-catalog services from before team labels were everywhere
- matchers:
- service=~"catalog-api|pricing-svc"
receiver: slack-product-catalog
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-product-catalog
continue: true
- receiver: slack-product-catalog
# teams below route alerts from the platform and data Prometheus servers
- matchers:
- team="messaging"
receiver: slack-messaging
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-messaging
continue: true
- matchers:
- severity="ticket"
receiver: jira-messaging
continue: true
- receiver: slack-messaging
# edge asked for hourly repeats while something is still firing
- matchers:
- team="edge"
receiver: slack-edge
repeat_interval: 1h
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-edge
continue: true
- matchers:
- severity="ticket"
receiver: jira-edge
continue: true
- receiver: slack-edge
# network wanted tickets in Slack as well as Jira (INFRA-1736)
- matchers:
- team="network"
receiver: slack-network
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-network
continue: true
- matchers:
- severity="ticket"
receiver: jira-network
continue: true
- receiver: slack-network
- matchers:
- team="build-infra"
receiver: slack-build-infra
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-build-infra
continue: true
- matchers:
- severity="ticket"
receiver: jira-build-infra
continue: true
- receiver: slack-build-infra
- matchers:
- team="platform"
receiver: slack-platform
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-platform
continue: true
- matchers:
- severity="ticket"
receiver: jira-platform
continue: true
# tickets and warnings per pod in Slack, so the channel shows which pod; pages group per service above
- receiver: slack-platform
group_by: [alertname, pod, service]
- matchers:
- team="storage"
receiver: slack-storage
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-storage
continue: true
- matchers:
- severity="ticket"
receiver: jira-storage
continue: true
- receiver: slack-storage
- matchers:
- team="security-ops"
receiver: slack-security-ops
routes:
- matchers:
- severity=~"page|critical"
receiver: pagerduty-security-ops
continue: true
- matchers:
- severity="ticket"
receiver: jira-security-ops
continue: true
- receiver: slack-security-ops
receivers:
- name: slack-alerts-default
slack_configs:
- channel: "#alerts-default"
send_resolved: true
- name: slack-sre-fyi
slack_configs:
- channel: "#sre-fyi"
send_resolved: false
- name: slack-prometheus-meta
slack_configs:
- channel: "#prometheus-meta"
- name: pagerduty-sre
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/sre
- name: pagerduty-build-infra
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/build-infra
- name: slack-build-infra
slack_configs:
- channel: "#build-infra-alerts"
send_resolved: true
- name: jira-build-infra
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/build_infra
- name: pagerduty-checkout-core
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/checkout-core
- name: slack-checkout-core
slack_configs:
- channel: "#checkout-core-alerts"
send_resolved: true
- name: jira-checkout-core
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/checkout_core
- name: pagerduty-edge
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/edge
- name: slack-edge
slack_configs:
- channel: "#edge-alerts"
send_resolved: true
- name: jira-edge
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/edge
- name: pagerduty-fulfillment
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/fulfillment
- name: slack-fulfillment
slack_configs:
- channel: "#fulfillment-alerts"
send_resolved: true
- name: jira-fulfillment
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/fulfillment
- name: pagerduty-growth
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/growth
- name: slack-growth
slack_configs:
- channel: "#growth-alerts"
send_resolved: true
- name: jira-growth
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/growth
- name: pagerduty-messaging
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/messaging
- name: slack-messaging
slack_configs:
- channel: "#messaging-alerts"
send_resolved: true
- name: jira-messaging
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/messaging
- name: pagerduty-network
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/network
- name: slack-network
slack_configs:
- channel: "#network-alerts"
send_resolved: true
- name: jira-network
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/network
- name: pagerduty-platform
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/platform
- name: slack-platform
slack_configs:
- channel: "#platform-alerts"
send_resolved: true
- name: jira-platform
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/platform
- name: pagerduty-pricing
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/pricing
- name: slack-pricing
slack_configs:
- channel: "#pricing-alerts"
send_resolved: true
- name: jira-pricing
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/pricing
- name: pagerduty-product-catalog
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/product-catalog
- name: slack-product-catalog
slack_configs:
- channel: "#product-catalog-alerts"
send_resolved: true
- name: jira-product-catalog
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/product_catalog
# routing key rotated in INFRA-2503
- name: pagerduty-security-ops
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/security-ops
- name: slack-security-ops
slack_configs:
- channel: "#security-ops-alerts"
send_resolved: true
- name: jira-security-ops
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/security_ops
- name: pagerduty-storage
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/storage
- name: slack-storage
slack_configs:
- channel: "#storage-alerts"
send_resolved: true
- name: jira-storage
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/storage
- name: pagerduty-storefront
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty/storefront
- name: slack-storefront
slack_configs:
- channel: "#storefront-alerts"
send_resolved: true
- name: jira-storefront
webhook_configs:
- url: https://jira-bridge.mercadorila.example/hooks/storefront
# unused since 2024, the SMTP relay it points at is gone
- name: email-oncall
email_configs:
- to: oncall@mercadorila.example
send_resolved: false
inhibit_rules:
# a critical copy holds back the warning copy of the same alert
- source_matchers:
- severity="critical"
target_matchers:
- severity="warning"
equal: [alertname, service]
AF_EOF
mkdir -p 'rules'
cat > 'rules/legacy-checkout-core.yml' <<'AF_EOF'
# checkout-core alerts from before the conventions in README.md.
# Don't reformat in passing; move things out when you touch them for a reason.
groups:
# old dashboard records; the svc-overview board still reads these
- name: checkout-core-records
rules:
- record: job:http_requests:rate5m
expr: sum by (job, service) (rate(http_requests_total{service="checkout-api"}[5m]))
- record: job:http_errors:rate5m
expr: sum by (job, service) (rate(http_requests_total{service="checkout-api",code=~"5.."}[5m]))
- name: checkout-api
rules:
- alert: CheckoutApiHighErrorRatio
expr: sum by (service) (rate(http_requests_total{service="checkout-api",code=~"5.."}[5m])) / sum by (service) (rate(http_requests_total{service="checkout-api"}[5m])) > 0.1
for: "10m"
labels: {severity: page, team: checkout-core}
annotations:
summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
runbook_url: https://runbooks.mercadorila.example/alerts/CheckoutApiHighErrorRatio
- alert: CheckoutApiLatencyHigh
expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="checkout-api"}[5m]))) > 0.5
for: "10m"
labels: {severity: warning, team: checkout-core}
annotations:
summary: "{{ $labels.service }} p99 above 500ms"
runbook_url: https://runbooks.mercadorila.example/alerts/CheckoutApiLatencyHigh
- alert: CheckoutApiLatencyHigh
expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="checkout-api"}[5m]))) > 1
for: "10m"
labels: {severity: critical, team: checkout-core}
annotations:
summary: "{{ $labels.service }} p99 above 1s"
runbook_url: https://runbooks.mercadorila.example/alerts/CheckoutApiLatencyHigh
- alert: ReplicationLagHigh
expr: max by (service) (pg_replication_lag_seconds{service="checkout-api"}) > 30
for: "10m"
labels: {severity: page, team: checkout-core, current: "{{ $value | humanize }}s"}
annotations:
summary: "{{ $labels.service }} replica is behind the primary"
runbook_url: https://runbooks.mercadorila.example/alerts/ReplicationLagHigh
- alert: CheckoutApiHighErrorRatio
expr: sum by (service) (rate(http_requests_total{service="checkout-api",code=~"5.."}[5m])) / sum by (service) (rate(http_requests_total{service="checkout-api"}[5m])) > 0.1
for: "10m"
labels: {severity: page, team: checkout-core}
annotations:
summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
runbook_url: https://wiki.mercadorila.example/display/INFRA/CheckoutApiHighErrorRatio+runbook
AF_EOF
mkdir -p 'rules'
cat > 'rules/legacy-fulfillment.yml' <<'AF_EOF'
# fulfillment alerts from before the conventions in README.md.
# Don't reformat in passing; move things out when you touch them for a reason.
groups:
# old dashboard records; the svc-overview board still reads these
- name: fulfillment-records
rules:
- record: job:grpc_calls:rate5m
expr: sum by (job, service) (rate(grpc_server_handled_total{service="inventory-svc"}[5m]))
- record: job:grpc_errors:rate5m
expr: sum by (job, service) (rate(grpc_server_handled_total{service="inventory-svc",grpc_code=~"Unavailable|Internal|DeadlineExceeded|Unknown|DataLoss"}[5m]))
- record: job:http_requests:rate5m
expr: sum by (job, service) (rate(http_requests_total{service="returns-api"}[5m]))
- record: job:http_errors:rate5m
expr: sum by (job, service) (rate(http_requests_total{service="returns-api",code=~"5.."}[5m]))
- name: returns-api
rules:
- alert: ReturnsApiHighErrorRatio
expr: sum by (service) (rate(http_requests_total{service="returns-api",code=~"5.."}[5m])) / sum by (service) (rate(http_requests_total{service="returns-api"}[5m])) > 0.02
for: "10m"
labels: {severity: page, team: fulfillment}
annotations:
summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
runbook_url: https://runbooks.mercadorila.example/alerts/ReturnsApiHighErrorRatio
- alert: ReturnsApiLatencyHigh
expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="returns-api"}[5m]))) > 0.5
for: "10m"
labels: {severity: warning, team: fulfillment}
annotations:
summary: "{{ $labels.service }} p99 above 500ms"
runbook_url: https://runbooks.mercadorila.example/alerts/ReturnsApiLatencyHigh
- alert: ReturnsApiLatencyHigh
expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="returns-api"}[5m]))) > 1
for: "10m"
labels: {severity: critical, team: fulfillment}
annotations:
summary: "{{ $labels.service }} p99 above 1s"
runbook_url: https://runbooks.mercadorila.example/alerts/ReturnsApiLatencyHigh
- alert: ReturnsApiDbConnectionsHigh
expr: max by (service) (db_pool_connections_active{service="returns-api"} / db_pool_connections_max{service="returns-api"}) > 0.8
for: "5m"
labels: {severity: warning, team: fulfillment}
annotations:
summary: "{{ $labels.service }} is using over 80% of its DB pool"
runbook_url: https://runbooks.mercadorila.example/alerts/ReturnsApiDbConnectionsHigh
- alert: ReturnsApiDbConnectionsHigh
expr: max by (service) (db_pool_connections_active{service="returns-api"} / db_pool_connections_max{service="returns-api"}) > 0.95
for: "5m"
labels: {severity: critical, team: fulfillment}
annotations:
summary: "{{ $labels.service }} DB pool nearly exhausted"
runbook_url: https://runbooks.mercadorila.example/alerts/ReturnsApiDbConnectionsHigh
# average the pods: they all run with the same limit, so the mean is what we size it by
- alert: ReturnsApiCpuThrottled
expr: avg by (service) (rate(container_cpu_cfs_throttled_periods_total{service="returns-api",container="returns-api"}[5m]) / rate(container_cpu_cfs_periods_total{service="returns-api",container="returns-api"}[5m])) > 0.25
for: "30m"
labels: {severity: ticket, team: fulfillment}
annotations:
summary: "{{ $labels.service }} pods spend over a quarter of their CPU periods throttled"
runbook_url: https://runbooks.mercadorila.example/alerts/ReturnsApiCpuThrottled
- name: inventory-svc
rules:
# threshold agreed with fulfillment in INFRA-1899
- alert: InventorySvcHighErrorRatio
expr: sum by (service) (rate(grpc_server_handled_total{service="inventory-svc",grpc_code=~"Unavailable|Internal|DeadlineExceeded|Unknown|DataLoss"}[5m])) / sum by (service) (rate(grpc_server_handled_total{service="inventory-svc"}[5m])) > 0.05
for: "10m"
labels: {severity: page, team: fulfillment}
annotations:
summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
runbook_url: https://runbooks.mercadorila.example/alerts/InventorySvcHighErrorRatio
AF_EOF
mkdir -p 'rules'
cat > 'rules/legacy-storefront.yml' <<'AF_EOF'
# storefront alerts from before the conventions in README.md.
# Don't reformat in passing; move things out when you touch them for a reason.
groups:
# old dashboard records; the svc-overview board still reads these
- name: storefront-records
rules:
- record: job:http_requests:rate5m
expr: sum by (job, service) (rate(http_requests_total{service="cart-svc"}[5m]))
- record: job:http_errors:rate5m
expr: sum by (job, service) (rate(http_requests_total{service="cart-svc",code=~"5.."}[5m]))
- name: cart-svc
rules:
- alert: CartSvcHighErrorRatio
expr: sum by (service) (rate(http_requests_total{service="cart-svc",code=~"5.."}[5m])) / sum by (service) (rate(http_requests_total{service="cart-svc"}[5m])) > 0.1
for: "10m"
labels: {severity: page, team: storefront}
annotations:
summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
runbook_url: https://runbooks.mercadorila.example/alerts/CartSvcHighErrorRatio
- alert: CartSvcLatencyHigh
expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="cart-svc"}[5m]))) > 0.5
for: "10m"
labels: {severity: warning, team: storefront}
annotations:
summary: "{{ $labels.service }} p99 above 500ms"
runbook_url: https://runbooks.mercadorila.example/alerts/CartSvcLatencyHigh
# TODO(2024) move to a latency SLO once we have one
- alert: CartSvcLatencyHigh
expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="cart-svc"}[5m]))) > 1
for: "10m"
labels: {severity: critical, team: storefront}
annotations:
summary: "{{ $labels.service }} p99 above 1s"
runbook_url: https://runbooks.mercadorila.example/alerts/CartSvcLatencyHigh
AF_EOF
mkdir -p 'rules'
cat > 'rules/product-catalog-rules.yaml' <<'AF_EOF'
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: product-catalog-rules
namespace: monitoring
labels:
role: alert-rules
spec:
groups:
- name: catalog-api
rules:
- alert: CatalogApiDown
expr: |
sum by (service) (up{service="catalog-api"}) == 0
or absent(up{service="catalog-api"})
for: 3m
labels:
severity: page
team: product-catalog
annotations:
summary: catalog-api has no healthy scrape targets
runbook_url: https://runbooks.mercadorila.example/alerts/CatalogApiDown
- alert: CatalogApiHighErrorRatio
expr: |
sum by (service) (rate(http_requests_total{service="catalog-api",code=~"5.."}[5m]))
/ sum by (service) (rate(http_requests_total{service="catalog-api"}[5m])) > 0.05
for: 10m
labels:
severity: page
team: product-catalog
annotations:
summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
runbook_url: https://runbooks.mercadorila.example/alerts/CatalogApiHighErrorRatio
# two windows so it stops paging a few minutes after the errors stop
- alert: CatalogApiErrorBudgetBurnFast
expr: |
slo:sli_error:ratio_rate1h{service="catalog-api"} > (3.36 * 0.0005)
and slo:sli_error:ratio_rate5m{service="catalog-api"} > (3.36 * 0.0005)
for: 2m
labels:
severity: page
team: product-catalog
slo: catalog-api-availability
annotations:
summary: "{{ $labels.service }} is spending its error budget fast"
runbook_url: https://runbooks.mercadorila.example/alerts/CatalogApiErrorBudgetBurnFast
- alert: CatalogApiErrorBudgetBurnSlow
expr: |
slo:sli_error:ratio_rate6h{service="catalog-api"} > (1.4 * 0.0005)
and slo:sli_error:ratio_rate30m{service="catalog-api"} > (1.4 * 0.0005)
for: 15m
labels:
severity: ticket
team: product-catalog
slo: catalog-api-availability
annotations:
summary: "{{ $labels.service }} is spending its error budget steadily"
runbook_url: https://runbooks.mercadorila.example/alerts/CatalogApiErrorBudgetBurnSlow
- name: pricing-svc
rules:
- alert: PricingSvcDown
expr: |
sum by (service) (up{service="pricing-svc"}) == 0
or absent(up{service="pricing-svc"})
for: 3m
labels:
severity: page
team: pricing
annotations:
summary: pricing-svc has no healthy scrape targets
runbook_url: https://runbooks.mercadorila.example/alerts/PricingSvcDown
- alert: PricingSvcHighErrorRatio
expr: |
sum by (service) (rate(grpc_server_handled_total{service="pricing-svc",grpc_code=~"Unavailable|Internal|DeadlineExceeded|Unknown|DataLoss"}[5m]))
/ sum by (service) (rate(grpc_server_handled_total{service="pricing-svc"}[5m])) > 0.05
for: 10m
labels:
severity: page
team: pricing
annotations:
summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
runbook_url: https://runbooks.mercadorila.example/alerts/PricingSvcHighErrorRatio
- alert: PricingSvcErrorBudgetBurnFast
expr: |
slo:sli_error:ratio_rate1h{service="pricing-svc"} > (14.4 * 0.001)
and slo:sli_error:ratio_rate5m{service="pricing-svc"} > (14.4 * 0.001)
for: 2m
labels:
severity: page
team: pricing
slo: pricing-svc-availability
annotations:
summary: "{{ $labels.service }} is spending its error budget fast"
runbook_url: https://runbooks.mercadorila.example/alerts/PricingSvcErrorBudgetBurnFast
- alert: PricingSvcErrorBudgetBurnSlow
expr: |
slo:sli_error:ratio_rate6h{service="pricing-svc"} > (6 * 0.001)
and slo:sli_error:ratio_rate30m{service="pricing-svc"} > (6 * 0.001)
for: 15m
labels:
severity: ticket
team: pricing
slo: pricing-svc-availability
annotations:
summary: "{{ $labels.service }} is spending its error budget steadily"
runbook_url: https://runbooks.mercadorila.example/alerts/PricingSvcErrorBudgetBurnSlow
AF_EOF