# services/monitoring/availability-backfill-v4-job.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: atlas-availability-request-v4-backfill-rules
  namespace: monitoring
data:
  atlas-request-history.yaml: |
    groups:
      - name: atlas.availability.request.backfill
        interval: 1h
        rules:
          - record: atlas:availability:requests_1h
            expr: |
              sum(increase(
                traefik_entrypoint_requests_total{
                  entrypoint="websecure",
                  protocol="http",
                  code=~"[1-5].."
                }[1h]
              ))
            labels:
              definition: request-v4
              scope: atlas
              rollup: hourly
          - record: atlas:availability:failures_1h
            expr: |
              sum(increase(
                traefik_entrypoint_requests_total{
                  entrypoint="websecure",
                  protocol="http",
                  code=~"5.."
                }[1h]
              ))
            labels:
              definition: request-v4
              scope: atlas
              rollup: hourly

---

apiVersion: batch/v1
kind: Job
metadata:
  name: atlas-availability-request-v4-backfill
  namespace: monitoring
spec:
  backoffLimit: 2
  template:
    metadata:
      labels:
        app: atlas-availability-request-v4-backfill
    spec:
      restartPolicy: Never
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/hostname
                    operator: NotIn
                    values:
                      - titan-22
                      - titan-24
      containers:
        - name: vmalert-replay
          image: victoriametrics/vmalert:v1.113.0
          args:
            - -datasource.url=http://victoria-metrics-single-server:8428
            - -remoteWrite.url=http://victoria-metrics-single-server:8428
            - -remoteWrite.flushInterval=1s
            - -rule=/etc/vmalert/backfill/*.yaml
            - -replay.timeFrom=2026-05-01T00:00:00Z
            - -replay.timeTo=2026-08-04T23:00:00Z
            - -replay.maxDatapointsPerQuery=48
            - -replay.rulesDelay=2s
            - -replay.disableProgressBar
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: "1"
              memory: 512Mi
          volumeMounts:
            - name: rules
              mountPath: /etc/vmalert/backfill
              readOnly: true
      volumes:
        - name: rules
          configMap:
            name: atlas-availability-request-v4-backfill-rules
