apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-config
  namespace: monitoring
  labels:
    name: prometheus-config
data:
  prometheus.rules: |-
    groups:
    - name: demo alert
      rules:
      - alert: High Pod Memory
        expr: sum(container_memory_usage_bytes) > 1
        for: 1m
        labels:
          severity: slack
        annotations:
          summary: High Memory Usage
  prometheus.yml: |-
    global:
      scrape_interval: 15s
      evaluation_interval: 5s
    rule_files:
      - /etc/prometheus/prometheus.rules
    alerting:
      alertmanagers:
      - scheme: http
        static_configs:
        - targets:
          - "{{ .Values.alertmanager.service.name }}.monitoring.svc:{{ .Values.alertmanager.service.port }}"

    scrape_configs:
    - job_name: 'todo-monitoring'
      scrape_interval: 10s
      metrics_path: '/todo/api/prometheus'
      static_configs:
      - targets:
        - "{{ .Values.service.name }}.default.svc.cluster.local:{{ .Values.service.port }}"
        labels:
          app: {{ .Values.service.name }}
    - job_name: 'prometheus-monitoring'
      scrape_interval: 5s
      metrics_path: '/prometheus/metrics'
      static_configs:
      - targets:
        - "{{ .Values.prometheus.service.name }}.monitoring.svc.cluster.local:{{ .Values.prometheus.service.port }}"
    - job_name: 'kube-cluster-monitoring'
      static_configs:
        - targets: ['{{ .Values.kubestate.service.name }}.kube-system.svc.cluster.local:{{ .Values.kubestate.service.port }}']
