apiVersion: v1
data:
  alert_rules.yml: |
    groups:
      - name: alert.rules
        rules:
          - alert: PodsMissing
            expr: app:up:ratio{app!=""} < 0.9
            for: 10m
            labels:
              severity: page
            annotations:
              description: 'Pods missing from {{`{{`}} $labels.app {{`}}`}}: {{`{{`}} $value
            {{`}}`}}'
              help: Alerts when pods are missing.
              summary: Pods missing from {{`{{`}} $labels.app {{`}}`}}
          - alert: NoPodsRunning
            expr: app:up:ratio{app!=""} < 0.1
            for: 2m
            labels:
              severity: page
            annotations:
              description: 'No pods are running for {{`{{`}} $labels.app {{`}}`}}: {{`{{`}}
            $value {{`}}`}}'
              help: Alerts when no pods are running for a service.
              summary: No pods are running for {{`{{`}} $labels.app {{`}}`}}
          - alert: ProdPageLoadLatency
            expr: histogram_quantile(0.9, sum by(le) (rate(src_http_request_duration_seconds_bucket{job="sourcegraph-frontend",route!="raw"}[10m])))
              > 20
            labels:
              severity: page
            annotations:
              description: 'Page load latency > 20s (90th percentile over all routes; current
            value: {{`{{`}}$value{{`}}`}}s)'
              help: Alerts when the page load latency is too high.
              summary: High page load latency
          - alert: GoroutineLeak
            expr: go_goroutines >= 10000
            for: 10m
            annotations:
              description: '{{`{{`}} $labels.app {{`}}`}} has more than 10k goroutines. This
            is probably a regression causing a goroutine leak'
              help: Alerts when a service has excessive running goroutines.
              summary: Excessive number of goroutines
          - alert: FSINodesRemainingLow
            expr: sum by(instance) (container_fs_inodes_total{pod_name!=""}) > 3e+06
            labels:
              severity: page
            annotations:
              description: '{{`{{`}}$labels.instance{{`}}`}} is using {{`{{`}}humanize $value{{`}}`}}
            inodes'
              help: Alerts when a node's remaining FS inodes are low.
              summary: '{{`{{`}}$labels.instance{{`}}`}} remaining fs inodes is low'
          - alert: DiskSpaceLow
            expr: node:k8snode_filesystem_avail_bytes:ratio < 0.1
            annotations:
              help: Alerts when a node has less than 10% available disk space.
              summary: '{{`{{`}}$labels.exported_name{{`}}`}} has less than 10% available
            disk space'
          - alert: DiskSpaceLowCritical
            expr: node:k8snode_filesystem_avail_bytes:ratio{exported_name=~".*prod.*"} < 0.05
            labels:
              severity: page
            annotations:
              help: Alerts when a node has less than 5% available disk space.
              summary: Critical! {{`{{`}}$labels.exported_name{{`}}`}} has less than 5% available
                disk space
          - alert: SearcherErrorRatioTooHigh
            expr: searcher_errors:ratio10m > 0.1
            for: 20m
            annotations:
              help: Alerts when the search service has more than 10% of requests failing.
              summary: Error ratio exceeds 10%
          - alert: PrometheusMetricsBloat
            expr: http_response_size_bytes{handler="prometheus",job!="kubernetes-apiservers",job!="kubernetes-nodes",quantile="0.5"}
              > 20000
            annotations:
              help: Alerts when a service is probably leaking metrics (unbounded attribute).
              summary: '{{`{{`}}$labels.job{{`}}`}} in {{`{{`}}$labels.ns{{`}}`}} is probably
            leaking metrics (unbounded attribute)'
  extra_rules.yml: ""
  node_rules.yml: |
    groups:
      - name: nodes.rules
        rules:
          - record: node:container_cpu_usage_seconds_total:ratio_rate5m
            expr: sum by(instance) (rate(container_cpu_usage_seconds_total{kubernetes_pod_name=""}[5m]))
              / max by(instance) (machine_cpu_cores)
          - record: task:container_memory_usage_bytes:max
            expr: max by(namespace, container_name) (container_memory_usage_bytes{container_name!=""})
          - record: task:container_cpu_usage_seconds_total:sum
            expr: sum by(id, namespace, container_name) (irate(container_cpu_usage_seconds_total{container_name!=""}[1m]))
          - record: node:k8snode_filesystem_avail_bytes:ratio
            expr: min by(exported_name) (k8snode_filesystem_avail_bytes / k8snode_filesystem_size_bytes)
  sourcegraph_rules.yml: |
    groups:
      - name: sourcegraph.rules
        rules:
          - record: app:up:sum
            expr: sum by(app) (up)
          - record: app:up:count
            expr: count by(app) (up)
          - record: app:up:ratio
            expr: app:up:sum / on(app) app:up:count
kind: ConfigMap
metadata:
  labels:
    deploy: sourcegraph
  name: prometheus
