groups:
  - name: ccip_alerts
    interval: 30s
    rules:
      # CCIP message failure rate
      - alert: CCIPHighFailureRate
        expr: rate(ccip_messages_failed_total[5m]) / rate(ccip_messages_sent_total[5m]) > 0.05
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "CCIP has high message failure rate"
          description: "CCIP message failure rate is {{ $value | humanizePercentage }} (threshold: 5%)"

      # CCIP message latency
      - alert: CCIPHighLatency
        expr: histogram_quantile(0.95, rate(ccip_message_latency_seconds_bucket[5m])) > 300
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "CCIP message latency is high"
          description: "P95 CCIP message latency is {{ $value }}s (threshold: 300s)"

      # CCIP router unavailable
      - alert: CCIPRouterUnavailable
        expr: up{job="ccip-router"} == 0
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "CCIP Router is unavailable"
          description: "CCIP Router {{ $labels.instance }} is down"

      # CCIP low success rate
      - alert: CCIPLowSuccessRate
        expr: rate(ccip_messages_success_total[5m]) / rate(ccip_messages_sent_total[5m]) < 0.95
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "CCIP message success rate is low"
          description: "CCIP success rate is {{ $value | humanizePercentage }} (threshold: 95%)"

      # CCIP fee balance low
      - alert: CCIPLowLinkBalance
        expr: ccip_link_balance < 10
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "CCIP LINK balance is low"
          description: "CCIP contract has only {{ $value }} LINK remaining (threshold: 10 LINK)"

      # CCIP fee balance critical
      - alert: CCIPCriticalLinkBalance
        expr: ccip_link_balance < 5
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "CCIP LINK balance is critically low"
          description: "CCIP contract has only {{ $value }} LINK remaining (threshold: 5 LINK)"

      # CCIP message queue backlog
      - alert: CCIPMessageBacklog
        expr: ccip_messages_pending_total > 100
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "CCIP message backlog detected"
          description: "{{ $value }} messages are pending in CCIP queue"

      # CCIP fee calculation errors
      - alert: CCIPFeeCalculationErrors
        expr: rate(ccip_fee_calculation_errors_total[5m]) > 0.1
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "CCIP fee calculation errors detected"
          description: "CCIP fee calculation error rate is {{ $value }} errors/second"

