apiVersion: v1
kind: ConfigMap
metadata:
  name: orion-controller-prometheus-config
data:
  prometheus.yml: |
    # my global config
    global:
      scrape_interval:     5s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
      evaluation_interval: 5s # Evaluate rules every 15 seconds. The default is every 1 minute.
      # scrape_timeout is set to the global default (10s).
    
    # Alertmanager configuration
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          # - alertmanager:9093
    
    # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    rule_files:
      # - "first_rules.yml"
      # - "second_rules.yml"
    
    # A scrape configuration containing exactly one endpoint to scrape:
    # Here it's Prometheus itself.
    scrape_configs:
      # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
      - job_name: 'prometheus'
    
        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.

        #static_configs:
        #- targets: 
        #  - '172.31.28.1:9100' # TODO: how to set this?
        #  - '172.31.43.188:9100' # TODO: how to set this?

        #https://stackoverflow.com/questions/52766020/how-to-discover-pods-for-prometheus-to-scrape
        kubernetes_sd_configs:
        - role: pod 
        relabel_configs:
        - source_labels: [__meta_kubernetes_pod_label_app]
          regex: orion-monitor
          action: keep
        - source_labels: [__meta_kubernetes_pod_host_ip, __meta_kubernetes_pod_annotation_prometheus_io_port]
          action: replace
          regex: ([^:]+)(?::\d+)?;(\d+)
          replacement: $1:$2
          target_label: __address__
        - source_labels: [__meta_kubernetes_pod_host_ip]
          target_label: ip

        #relabel_configs:
        #- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        #  action: keep
        #  regex: true
        #- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        #  action: replace
        #  target_label: __metrics_path__
        #  regex: (.+)
        #- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
        #  action: replace
        #  regex: ([^:]+)(?::\d+)?;(\d+)
        #  replacement: $1:$2
        #  target_label: __address__
        #- 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
