# Prometheus alerting rules for the shop namespace.
# Every expression references metric families that exist in this category's
# Prometheus and OpenMetrics fixtures.
groups:
  - name: shop-availability
    interval: 30s
    rules:
      - alert: TargetDown
        expr: up == 0
        for: 5m
        labels:
          severity: critical
          team: platform
        annotations:
          summary: "{{ $labels.job }} target {{ $labels.instance }} is down"
          description: >-
            Prometheus has been unable to scrape {{ $labels.instance }} for five
            minutes. Check the pod status before paging the service owner.
          runbook_url: https://runbooks.example.com/shop/target-down

      - alert: HighErrorRate
        expr: |
          sum by (service) (rate(http_requests_total{status=~"5.."}[5m]))
            /
          sum by (service) (rate(http_requests_total[5m]))
            > 0.05
        for: 10m
        labels:
          severity: warning
          team: shop
        annotations:
          summary: "{{ $labels.service }} is serving more than 5% 5xx"
          description: "Current ratio: {{ $value | humanizePercentage }}."

  - name: shop-latency
    interval: 30s
    rules:
      - alert: CheckoutLatencySLOBurn
        expr: |
          histogram_quantile(
            0.99,
            sum by (le, service) (rate(http_request_duration_seconds_bucket{service="checkout-api"}[5m]))
          ) > 1
        for: 15m
        keep_firing_for: 5m
        labels:
          severity: critical
          team: shop
          slo: checkout-latency
        annotations:
          summary: "checkout-api p99 latency is above one second"
          runbook_url: https://runbooks.example.com/shop/checkout-latency

      - alert: BackupTooOld
        expr: time() - node_backup_last_success_timestamp_seconds > 86400
        for: 0m
        labels:
          severity: warning
          team: platform
        annotations:
          summary: "nightly-dump backup has not succeeded in 24 hours"
