apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-agent-node
  namespace: neon-monitor
data:
  agent.yml: |
    server:
      log_level: info
      http_listen_port: 8080
    integrations:
      agent:
        enabled: true
      node_exporter:
        enabled: true
        wal_truncate_frequency: 15m
        rootfs_path: /host/root
        sysfs_path: /host/sys
        procfs_path: /host/proc
    prometheus:
      global:
        external_labels:
          cluster: {{ .Values.clusterName }}
        scrape_interval: 60s
      wal_directory: /var/lib/agent/data
      configs:
        - host_filter: true
          name: agent
          remote_write:
            - url: http://cortex:9009/api/prom/push
          scrape_configs:
            - job_name: 'istiod'
              kubernetes_sd_configs:
              - role: endpoints
                namespaces:
                  names:
                  - istio-system
              relabel_configs:
              - source_labels:
                  - __meta_kubernetes_service_name
                  - __meta_kubernetes_endpoint_port_name
                action: keep
                regex: istiod;http-monitoring
            - job_name: 'envoy-stats'
              metrics_path: /stats/prometheus
              kubernetes_sd_configs:
              - role: pod

              relabel_configs:
              - source_labels: 
                  - __meta_kubernetes_pod_container_port_name
                action: keep
                regex: '.*-envoy-prom'
            - job_name: kubernetes-pods
              kubernetes_sd_configs:
                - role: pod
              relabel_configs:
                - action: drop
                  regex: "false"
                  source_labels:
                    - __meta_kubernetes_pod_annotation_prometheus_io_scrape
                - action: keep
                  regex: .*-metrics
                  source_labels:
                    - __meta_kubernetes_pod_container_port_name
                - action: replace
                  regex: (https?)
                  replacement: $1
                  source_labels:
                    - __meta_kubernetes_pod_annotation_prometheus_io_scheme
                  target_label: __scheme__
                - action: replace
                  regex: (.+)
                  replacement: $1
                  source_labels:
                    - __meta_kubernetes_pod_annotation_prometheus_io_path
                  target_label: __metrics_path__
                - action: replace
                  regex: (.+?)(\:\d+)?;(\d+)
                  replacement: $1:$3
                  source_labels:
                    - __address__
                    - __meta_kubernetes_pod_annotation_prometheus_io_port
                  target_label: __address__
                - action: drop
                  regex: ""
                  source_labels:
                    - __meta_kubernetes_pod_label_name
                - action: replace
                  replacement: $1
                  separator: /
                  source_labels:
                    - __meta_kubernetes_namespace
                    - __meta_kubernetes_pod_label_name
                  target_label: job
                - action: replace
                  source_labels:
                    - __meta_kubernetes_namespace
                  target_label: namespace
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_name
                  target_label: pod
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_container_name
                  target_label: container
                - action: replace
                  separator: ':'
                  source_labels:
                    - __meta_kubernetes_pod_name
                    - __meta_kubernetes_pod_container_name
                    - __meta_kubernetes_pod_container_port_name
                  target_label: instance
                - action: labelmap
                  regex: __meta_kubernetes_pod_annotation_prometheus_io_param_(.+)
                  replacement: __param_$1
                - action: drop
                  regex: Succeeded|Failed
                  source_labels:
                    - __meta_kubernetes_pod_phase
            - job_name: neon-monitor/kube-state-metrics
              kubernetes_sd_configs:
                - namespaces:
                      names:
                        - neon-monitor
                  role: pod
              relabel_configs:
                - action: keep
                  regex: kube-state-metrics
                  source_labels:
                    - __meta_kubernetes_pod_label_name
                - action: replace
                  separator: ':'
                  source_labels:
                    - __meta_kubernetes_pod_name
                    - __meta_kubernetes_pod_container_name
                    - __meta_kubernetes_pod_container_port_name
                  target_label: instance
            - job_name: neon-monitor/node-exporter
              kubernetes_sd_configs:
                - namespaces:
                      names:
                        - neon-monitor
                  role: pod
              relabel_configs:
                - action: keep
                  regex: node-exporter
                  source_labels:
                    - __meta_kubernetes_pod_label_name
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_node_name
                  target_label: instance
                - action: replace
                  source_labels:
                    - __meta_kubernetes_namespace
                  target_label: namespace
            - bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
              job_name: kube-system/kubelet
              kubernetes_sd_configs:
                - role: node
              relabel_configs:
                - replacement: kubernetes.default.svc.cluster.local:443
                  target_label: __address__
                - replacement: https
                  target_label: __scheme__
                - regex: (.+)
                  replacement: /api/v1/nodes/$1/proxy/metrics
                  source_labels:
                    - __meta_kubernetes_node_name
                  target_label: __metrics_path__
              tls_config:
                  ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
                  insecure_skip_verify: false
            - bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
              job_name: kube-system/cadvisor
              kubernetes_sd_configs:
                - role: node
              metric_relabel_configs:
                - action: drop
                  regex: 'container_([a-z_]+);'
                  source_labels:
                    - __name__
                    - image
                - action: drop
                  regex: container_(network_tcp_usage_total|network_udp_usage_total|tasks_state|cpu_load_average_10s)
                  source_labels:
                    - __name__
              relabel_configs:
                - replacement: kubernetes.default.svc.cluster.local:443
                  target_label: __address__
                - regex: (.+)
                  replacement: /api/v1/nodes/$1/proxy/metrics/cadvisor
                  source_labels:
                    - __meta_kubernetes_node_name
                  target_label: __metrics_path__
              scheme: https
              tls_config:
                  ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
                  insecure_skip_verify: false
            - job_name: "cri-o"
              scrape_interval: 1m
              metrics_path: /metrics
              static_configs:
                - targets: ["${HOST_IP}:9090"]
                  labels:
                    instance: "${HOSTNAME}"
    loki:
      configs:
        - clients:
            - url: http://loki:3100/loki/api/v1/push
          name: default
          scrape_configs:
            - job_name: journal
              journal:
                path: /var/log/journal
                max_age: 12h
                labels:
                  job: systemd-journal
              relabel_configs:
                - source_labels:
                    - '__journal__systemd_unit'
                  target_label: 'unit'
                - source_labels:
                    - '__journal__hostname'
                  target_label: 'hostname'
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_node_name
                  target_label: node_name
                - action: replace
                  source_labels:
                    - __meta_kubernetes_namespace
                  target_label: namespace
                - action: replace
                  replacement: $1
                  separator: /
                  source_labels:
                    - namespace
                    - app
                  target_label: job
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_name
                  target_label: pod
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_container_name
                  target_label: container
                - action: replace
                  replacement: /var/log/pods/*$1/*.log
                  separator: /
                  source_labels:
                    - __meta_kubernetes_pod_uid
                    - __meta_kubernetes_pod_container_name
                  target_label: __path__
            - job_name: kubernetes-pods-name
              kubernetes_sd_configs:
                - role: pod
              pipeline_stages:
                - docker: {}
              relabel_configs:
                - source_labels:
                    - __meta_kubernetes_pod_label_name
                  target_label: __service__
                - source_labels:
                    - __meta_kubernetes_pod_node_name
                  target_label: __host__
                - action: drop
                  regex: ""
                  source_labels:
                    - __service__
                - action: labelmap
                  regex: __meta_kubernetes_pod_label_(.+)
                - action: replace
                  replacement: $1
                  separator: /
                  source_labels:
                    - __meta_kubernetes_namespace
                    - __service__
                  target_label: job
                - action: replace
                  source_labels:
                    - __meta_kubernetes_namespace
                  target_label: namespace
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_name
                  target_label: pod
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_container_name
                  target_label: container
                - replacement: /var/log/pods/*$1/*.log
                  separator: /
                  source_labels:
                    - __meta_kubernetes_pod_uid
                    - __meta_kubernetes_pod_container_name
                  target_label: __path__
            - job_name: kubernetes-pods-app
              kubernetes_sd_configs:
                - role: pod
              pipeline_stages:
                - docker: {}
              relabel_configs:
                - action: drop
                  regex: .+
                  source_labels:
                    - __meta_kubernetes_pod_label_name
                - source_labels:
                    - __meta_kubernetes_pod_label_app
                  target_label: __service__
                - source_labels:
                    - __meta_kubernetes_pod_node_name
                  target_label: __host__
                - action: drop
                  regex: ""
                  source_labels:
                    - __service__
                - action: labelmap
                  regex: __meta_kubernetes_pod_label_(.+)
                - action: replace
                  replacement: $1
                  separator: /
                  source_labels:
                    - __meta_kubernetes_namespace
                    - __service__
                  target_label: job
                - action: replace
                  source_labels:
                    - __meta_kubernetes_namespace
                  target_label: namespace
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_name
                  target_label: pod
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_container_name
                  target_label: container
                - replacement: /var/log/pods/*$1/*.log
                  separator: /
                  source_labels:
                    - __meta_kubernetes_pod_uid
                    - __meta_kubernetes_pod_container_name
                  target_label: __path__
            - job_name: kubernetes-pods-direct-controllers
              kubernetes_sd_configs:
                - role: pod
              pipeline_stages:
                - docker: {}
              relabel_configs:
                - action: drop
                  regex: .+
                  separator: ""
                  source_labels:
                    - __meta_kubernetes_pod_label_name
                    - __meta_kubernetes_pod_label_app
                - action: drop
                  regex: '[0-9a-z-.]+-[0-9a-f]{8,10}'
                  source_labels:
                    - __meta_kubernetes_pod_controller_name
                - source_labels:
                    - __meta_kubernetes_pod_controller_name
                  target_label: __service__
                - source_labels:
                    - __meta_kubernetes_pod_node_name
                  target_label: __host__
                - action: drop
                  regex: ""
                  source_labels:
                    - __service__
                - action: labelmap
                  regex: __meta_kubernetes_pod_label_(.+)
                - action: replace
                  replacement: $1
                  separator: /
                  source_labels:
                    - __meta_kubernetes_namespace
                    - __service__
                  target_label: job
                - action: replace
                  source_labels:
                    - __meta_kubernetes_namespace
                  target_label: namespace
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_name
                  target_label: pod
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_container_name
                  target_label: container
                - replacement: /var/log/pods/*$1/*.log
                  separator: /
                  source_labels:
                    - __meta_kubernetes_pod_uid
                    - __meta_kubernetes_pod_container_name
                  target_label: __path__
            - job_name: kubernetes-pods-indirect-controller
              kubernetes_sd_configs:
                - role: pod
              pipeline_stages:
                - docker: {}
              relabel_configs:
                - action: drop
                  regex: .+
                  separator: ""
                  source_labels:
                    - __meta_kubernetes_pod_label_name
                    - __meta_kubernetes_pod_label_app
                - action: keep
                  regex: '[0-9a-z-.]+-[0-9a-f]{8,10}'
                  source_labels:
                    - __meta_kubernetes_pod_controller_name
                - action: replace
                  regex: ([0-9a-z-.]+)-[0-9a-f]{8,10}
                  source_labels:
                    - __meta_kubernetes_pod_controller_name
                  target_label: __service__
                - source_labels:
                    - __meta_kubernetes_pod_node_name
                  target_label: __host__
                - action: drop
                  regex: ""
                  source_labels:
                    - __service__
                - action: labelmap
                  regex: __meta_kubernetes_pod_label_(.+)
                - action: replace
                  replacement: $1
                  separator: /
                  source_labels:
                    - __meta_kubernetes_namespace
                    - __service__
                  target_label: job
                - action: replace
                  source_labels:
                    - __meta_kubernetes_namespace
                  target_label: namespace
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_name
                  target_label: pod
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_container_name
                  target_label: container
                - replacement: /var/log/pods/*$1/*.log
                  separator: /
                  source_labels:
                    - __meta_kubernetes_pod_uid
                    - __meta_kubernetes_pod_container_name
                  target_label: __path__
            - job_name: kubernetes-pods-static
              kubernetes_sd_configs:
                - role: pod
              pipeline_stages:
                - docker: {}
              relabel_configs:
                - action: drop
                  regex: ""
                  source_labels:
                    - __meta_kubernetes_pod_annotation_kubernetes_io_config_mirror
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_label_component
                  target_label: __service__
                - source_labels:
                    - __meta_kubernetes_pod_node_name
                  target_label: __host__
                - action: drop
                  regex: ""
                  source_labels:
                    - __service__
                - action: labelmap
                  regex: __meta_kubernetes_pod_label_(.+)
                - action: replace
                  replacement: $1
                  separator: /
                  source_labels:
                    - __meta_kubernetes_namespace
                    - __service__
                  target_label: job
                - action: replace
                  source_labels:
                    - __meta_kubernetes_namespace
                  target_label: namespace
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_name
                  target_label: pod
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_container_name
                  target_label: container
                - replacement: /var/log/pods/*$1/*.log
                  separator: /
                  source_labels:
                    - __meta_kubernetes_pod_annotation_kubernetes_io_config_mirror
                    - __meta_kubernetes_pod_container_name
                  target_label: __path__
      positions_directory: /tmp/positions
    tempo:
      configs:
        - batch:
              send_batch_size: 1000
              timeout: 5s
          name: default
          receivers:
              jaeger:
                  protocols:
                      grpc: null
                      thrift_binary: null
                      thrift_compact: null
                      thrift_http: null
                  remote_sampling:
                      insecure: true
                      strategy_file: /etc/agent/strategies.json
              opencensus: null
              otlp:
                  protocols:
                      grpc: null
                      http: null
              zipkin: null
          remote_write:
            - endpoint: http://tempo:3100
              retry_on_failure:
                  enabled: false
          scrape_configs:
            - bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
              job_name: kubernetes-pods
              kubernetes_sd_configs:
                - role: pod
              relabel_configs:
                - action: replace
                  source_labels:
                    - __meta_kubernetes_namespace
                  target_label: namespace
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_name
                  target_label: pod
                - action: replace
                  source_labels:
                    - __meta_kubernetes_pod_container_name
                  target_label: container
              tls_config:
                  ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
                  insecure_skip_verify: false
  strategies.json: '{"default_strategy": {"param": 0.001, "type": "probabilistic"}}'