apiVersion: v1
kind: ConfigMap
metadata:
  name: loki-alerting-rules
  labels:
    app: loki
    chart: loki-2.1.1
    release: loki
    heritage: Helm
data:
  loki-alerting-rules.yaml: |-
    groups:
      - name: GrafanaLogAlerts
        rules:
        - alert: HighPercentageError
          expr: |
            sum(rate({app="grafana", namespace="monitoring"} |= "error" [5m])) by (job)
              /
            sum(rate({app="grafana", namespace="monitoring"}[5m])) by (job)
              > 0.1
          for: 10m
          labels:
              severity: "warning"
          annotations:
              summary: "High percentage of errors in the logs"
        - alert: HighFailedLoginsGrafana
          expr: | 
            rate({app="grafana"} |= "Invalid username or password" [5m]) 
            > 0.2
          for: 10m
          labels:
            severity: "warning"
          annotations:
            summary: "High number of failed logins to Grafana"
      - name: CiSearchLogAlerts
        rules:
        - alert: CiSearchFullPersistentVolume
          expr: |
            rate({app="search"} |= "failed to write job" [5m])
            > 0.1
          for: 10m
          labels:
            severity: "critical"
          annotations:
            summary: "CI Search persistent volume is full"
