groups:
  - name: oracle_alerts
    interval: 30s
    rules:
      # Oracle data source health
      - alert: OracleDataSourceDown
        expr: up{job="oracle-data-source"} == 0
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "Oracle data source is down"
          description: "Oracle data source {{ $labels.instance }} is unavailable"

      # Oracle update frequency
      - alert: OracleUpdateStale
        expr: time() - oracle_last_update_timestamp > 300
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Oracle update is stale"
          description: "Oracle {{ $labels.feed }} has not been updated in {{ $value }} seconds"

      # Oracle update frequency too high
      - alert: OracleUpdateFrequencyTooHigh
        expr: rate(oracle_updates_total[5m]) > 1
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Oracle update frequency is too high"
          description: "Oracle {{ $labels.feed }} is being updated {{ $value }} times per second"

      # Oracle price deviation
      - alert: OraclePriceDeviation
        expr: abs(oracle_price - oracle_previous_price) / oracle_previous_price > 0.05
        for: 1m
        labels:
          severity: warning
        annotations:
          summary: "Oracle price deviation detected"
          description: "Oracle {{ $labels.feed }} price changed by {{ $value | humanizePercentage }}"

      # Oracle price deviation critical
      - alert: OraclePriceDeviationCritical
        expr: abs(oracle_price - oracle_previous_price) / oracle_previous_price > 0.10
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "Critical oracle price deviation"
          description: "Oracle {{ $labels.feed }} price changed by {{ $value | humanizePercentage }}"

      # Oracle health check
      - alert: OracleHealthCheckFailed
        expr: oracle_health_check == 0
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "Oracle health check failed"
          description: "Oracle service {{ $labels.instance }} health check is failing"

      # Oracle transmitter unavailable
      - alert: OracleTransmitterUnavailable
        expr: up{job="oracle-transmitter"} == 0
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "Oracle transmitter is unavailable"
          description: "Oracle transmitter {{ $labels.instance }} is down"

      # Oracle aggregator errors
      - alert: OracleAggregatorErrors
        expr: rate(oracle_aggregator_errors_total[5m]) > 0.1
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Oracle aggregator errors detected"
          description: "Oracle aggregator error rate is {{ $value }} errors/second"

      # Oracle round ID mismatch
      - alert: OracleRoundIdMismatch
        expr: oracle_round_id - oracle_expected_round_id > 1
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Oracle round ID mismatch"
          description: "Oracle {{ $labels.feed }} round ID is {{ $value }} ahead of expected"

