apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-config
  namespace: the-order
data:
  prometheus.yml: |
    global:
      scrape_interval: 15s
      evaluation_interval: 15s
      external_labels:
        cluster: 'the-order'
        environment: 'production'

    scrape_configs:
      - job_name: 'prometheus'
        static_configs:
          - targets: ['localhost:9090']

      - job_name: 'identity-service'
        kubernetes_sd_configs:
          - role: pod
            namespaces:
              names:
                - the-order
        relabel_configs:
          - source_labels: [__meta_kubernetes_pod_label_app]
            regex: identity-service
            action: keep
          - source_labels: [__meta_kubernetes_pod_ip]
            action: replace
            target_label: __address__
            replacement: $1:4002

      - job_name: 'intake-service'
        kubernetes_sd_configs:
          - role: pod
            namespaces:
              names:
                - the-order
        relabel_configs:
          - source_labels: [__meta_kubernetes_pod_label_app]
            regex: intake-service
            action: keep
          - source_labels: [__meta_kubernetes_pod_ip]
            action: replace
            target_label: __address__
            replacement: $1:4001

      - job_name: 'finance-service'
        kubernetes_sd_configs:
          - role: pod
            namespaces:
              names:
                - the-order
        relabel_configs:
          - source_labels: [__meta_kubernetes_pod_label_app]
            regex: finance-service
            action: keep
          - source_labels: [__meta_kubernetes_pod_ip]
            action: replace
            target_label: __address__
            replacement: $1:4003

      - job_name: 'dataroom-service'
        kubernetes_sd_configs:
          - role: pod
            namespaces:
              names:
                - the-order
        relabel_configs:
          - source_labels: [__meta_kubernetes_pod_label_app]
            regex: dataroom-service
            action: keep
          - source_labels: [__meta_kubernetes_pod_ip]
            action: replace
            target_label: __address__
            replacement: $1:4004

      - job_name: 'legal-documents-service'
        kubernetes_sd_configs:
          - role: pod
            namespaces:
              names:
                - the-order
        relabel_configs:
          - source_labels: [__meta_kubernetes_pod_label_app]
            regex: legal-documents-service
            action: keep
          - source_labels: [__meta_kubernetes_pod_ip]
            action: replace
            target_label: __address__
            replacement: $1:4005

    rule_files:
      - '/etc/prometheus/alert-rules.yml'

