rule_files:
  - alerts.yaml
  - rules.yaml

evaluation_interval: 1m

tests:
- interval: 1m
  input_series:
  - series: 'thanos_sidecar_last_heartbeat_success_time_seconds{namespace="production", job="thanos-sidecar", pod="thanos-sidecar-pod-0"}'
    values: '5 10 43 17 11 0 0 0'
  - series: 'thanos_sidecar_last_heartbeat_success_time_seconds{namespace="production", job="thanos-sidecar", pod="thanos-sidecar-pod-1"}'
    values: '4 9 42 15 10 0 0 0'
  promql_expr_test:
    - expr: time()
      eval_time: 1m
      exp_samples:
        - labels: '{}'
          value: 60
    - expr: time()
      eval_time: 2m
      exp_samples:
        - labels: '{}'
          value: 120
    - expr: max(thanos_sidecar_last_heartbeat_success_time_seconds{job="thanos-sidecar"}) by (job, pod)
      eval_time: 2m
      exp_samples:
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-0"}'
          value: 43
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-1"}'
          value: 42
    - expr: max(thanos_sidecar_last_heartbeat_success_time_seconds{job="thanos-sidecar"}) by (job, pod)
      eval_time: 10m
      exp_samples:
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-0"}'
          value: 0
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-1"}'
          value: 0
    - expr: max(thanos_sidecar_last_heartbeat_success_time_seconds{job="thanos-sidecar"}) by (job, pod)
      eval_time: 11m
      exp_samples:
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-0"}'
          value: 0
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-1"}'
          value: 0
    - expr: time() - max(thanos_sidecar_last_heartbeat_success_time_seconds{job="thanos-sidecar"}) by (job, pod)
      eval_time: 10m
      exp_samples:
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-0"}'
          value: 600
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-1"}'
          value: 600
    - expr: time() - max(thanos_sidecar_last_heartbeat_success_time_seconds{job="thanos-sidecar"}) by (job, pod)
      eval_time: 11m
      exp_samples:
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-0"}'
          value: 660
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-1"}'
          value: 660
    - expr: time() - max(thanos_sidecar_last_heartbeat_success_time_seconds{job="thanos-sidecar"}) by (job, pod) >= 600
      eval_time: 12m
      exp_samples:
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-0"}'
          value: 720
        - labels: '{job="thanos-sidecar", pod="thanos-sidecar-pod-1"}'
          value: 720
  alert_rule_test:
  - eval_time: 1m
    alertname: ThanosSidecarUnhealthy
  - eval_time: 2m
    alertname: ThanosSidecarUnhealthy
  - eval_time: 3m
    alertname: ThanosSidecarUnhealthy
  - eval_time: 10m
    alertname: ThanosSidecarUnhealthy
    exp_alerts:
    - exp_labels:
        severity: critical
        job: thanos-sidecar
        pod: thanos-sidecar-pod-0
      exp_annotations:
        description: 'Thanos Sidecar thanos-sidecar thanos-sidecar-pod-0 is unhealthy for 600 seconds.'
        summary: 'Thanos Sidecar is unhealthy.'
    - exp_labels:
        severity: critical
        job: thanos-sidecar
        pod: thanos-sidecar-pod-1
      exp_annotations:
        description: 'Thanos Sidecar thanos-sidecar thanos-sidecar-pod-1 is unhealthy for 600 seconds.'
        summary: 'Thanos Sidecar is unhealthy.'
  - eval_time: 11m
    alertname: ThanosSidecarUnhealthy
    exp_alerts:
    - exp_labels:
        severity: critical
        job: thanos-sidecar
        pod: thanos-sidecar-pod-0
      exp_annotations:
        description: 'Thanos Sidecar thanos-sidecar thanos-sidecar-pod-0 is unhealthy for 660 seconds.'
        summary: 'Thanos Sidecar is unhealthy.'
    - exp_labels:
        severity: critical
        job: thanos-sidecar
        pod: thanos-sidecar-pod-1
      exp_annotations:
        description: 'Thanos Sidecar thanos-sidecar thanos-sidecar-pod-1 is unhealthy for 660 seconds.'
        summary: 'Thanos Sidecar is unhealthy.'
  - eval_time: 12m
    alertname: ThanosSidecarUnhealthy
    exp_alerts:
    - exp_labels:
        severity: critical
        job: thanos-sidecar
        pod: thanos-sidecar-pod-0
      exp_annotations:
        description: 'Thanos Sidecar thanos-sidecar thanos-sidecar-pod-0 is unhealthy for 720 seconds.'
        summary: 'Thanos Sidecar is unhealthy.'
    - exp_labels:
        severity: critical
        job: thanos-sidecar
        pod: thanos-sidecar-pod-1
      exp_annotations:
        description: 'Thanos Sidecar thanos-sidecar thanos-sidecar-pod-1 is unhealthy for 720 seconds.'
        summary: 'Thanos Sidecar is unhealthy.'
