---
kind: ConfigMap
apiVersion: v1
metadata:
  labels:
    app: openfaas
    component: prometheus-config
  name: prometheus-config
  namespace: "openfaas"
data:
  prometheus.yml: |
    global:
      scrape_interval:     15s
      evaluation_interval: 15s
      external_labels:
          monitor: 'faas-monitor'
    rule_files:
        - 'alert.rules.yml'
    scrape_configs:
      - job_name: 'prometheus'
        scrape_interval: 5s
        static_configs:
          - targets: ['localhost:9090']
      - job_name: 'kubernetes-pods'
        scrape_interval: 5s
        honor_labels: false
        kubernetes_sd_configs:
          - role: pod
            namespaces:
              names:
                - openfaas
                - openfaas-fn
        relabel_configs:
        - action: labelmap
          regex: __meta_kubernetes_pod_label_(.+)
        - source_labels: [__meta_kubernetes_namespace]
          action: replace
          target_label: kubernetes_namespace
        - source_labels: [__meta_kubernetes_pod_name]
          action: replace
          target_label: kubernetes_pod_name
        - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
          action: keep
          regex: true
        - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
          action: replace
          regex: ([^:]+)(?::\d+)?;(\d+)
          replacement: $1:$2
          target_label: __address__
        - action: replace
          regex: (.+)
          source_labels:
          - __meta_kubernetes_pod_annotation_prometheus_io_path
          target_label: __metrics_path__
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          - alertmanager:9093
  alert.rules.yml: |
    groups:
      - name: openfaas
        rules:
        - alert: service_down
          expr: up == 0
        - alert: APIHighInvocationRate
          expr: sum(rate(gateway_function_invocation_total{code="200"}[10s])) BY (function_name) > 5
          for: 5s
          labels:
            service: gateway
            severity: major
          annotations:
            description: High invocation total on "{{$labels.function_name}}"
            summary: High invocation total on "{{$labels.function_name}}"
