apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: story-crater-frontend-rules
  namespace: story-crater-frontend
spec:
  groups:
    - name: story-crater-frontend.rules
      interval: 15s
      rules:
        - alert: StoryCraterFrontendHighErrorRate
          expr: |
            (
              sum(rate(story_crater_frontend_http_requests_total{status=~"5.."}[5m]))
              /
              sum(rate(story_crater_frontend_http_requests_total[5m]))
            ) > 0.05
          for: 10m
          labels:
            severity: warning
          annotations:
            summary: "High error rate on story-crater-frontend"
            description: "5xx error rate exceeded 5% of total requests for 10 minutes. Value: {{ $value | humanizePercentage }}"

        - alert: StoryCraterFrontendWebVitalsLCPRegression
          expr: |
            histogram_quantile(0.75, story_crater_frontend_web_vitals_lcp_ms) > 2500
          for: 10m
          labels:
            severity: warning
          annotations:
            summary: "LCP (Largest Contentful Paint) regression on story-crater-frontend"
            description: "LCP p75 exceeded 2500ms for 10 minutes. Value: {{ $value }}ms"
