apiVersion: v1
data:
  otel-collector-config: |
    service:
      telemetry:
        logs:
          level: info
      extensions: [zpages, health_check]
      pipelines:
        metrics:
          receivers: [prometheus, opencensus, otlp]
          processors: [batch]
          exporters: [prometheus, otlp]
    extensions:
      zpages:
        endpoint: "localhost:56888"
      health_check: {}
    exporters:
      otlp:
        endpoint: "https://otlp.nr-data.net:443"
        headers: 
          api-key: "<api key>"
      prometheus:
        endpoint: "0.0.0.0:9090"
    processors:
      batch:
    receivers:
      otlp:
        protocols:
          grpc:
      opencensus:
        endpoint: 0.0.0.0:9091
      prometheus:
        config:
          global:
            scrape_interval: 15s
          scrape_configs:

          - job_name: 'tsb-operator-management-plane'
            metrics_path: '/metrics'
            kubernetes_sd_configs:
              - role: endpoints
                namespaces:
                  names:
                    - tsb
            relabel_configs:
            - source_labels: [__meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
              action: keep
              regex: tsb-operator-management-plane;http-metrics
            - source_labels: []
              target_label: plane
              replacement: management
            - source_labels: []
              target_label: component
              replacement: tsb-operator-management-plane

          - job_name: 'front-envoy'
            metrics_path: '/metrics'
            kubernetes_sd_configs:
              - role: endpoints
                namespaces:
                  names:
                    - tsb
            relabel_configs:
            - source_labels: [__meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
              action: keep
              regex: envoy-metrics;http-monitoring
            - source_labels: []
              target_label: plane
              replacement: management
            - source_labels: []
              target_label: component
              replacement: front-envoy

          - job_name: 'iam'
            metrics_path: '/metrics'
            kubernetes_sd_configs:
              - role: endpoints
                namespaces:
                  names:
                    - tsb
            relabel_configs:
            - source_labels: [__meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
              action: keep
              regex: iam;http-monitoring
            - source_labels: []
              target_label: plane
              replacement: management
            - source_labels: []
              target_label: component
              replacement: iam

          - job_name: 'central-xcp'
            metrics_path: '/metrics'
            kubernetes_sd_configs:
              - role: pod
                namespaces:
                  names:
                    - tsb
            relabel_configs:
            - source_labels: [__meta_kubernetes_pod_label_platform_tsb_tetrate_io_application, __meta_kubernetes_pod_container_port_number]
              action: keep
              regex: xcp-central;8080
            - source_labels: []
              target_label: plane
              replacement: management
            - source_labels: []
              target_label: component
              replacement: xcp

          - job_name: 'tsb'
            metrics_path: '/metrics'
            kubernetes_sd_configs:
              - role: endpoints
                namespaces:
                  names:
                    - tsb
            relabel_configs:
            - source_labels: [__meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
              action: keep
              regex: tsb;http-monitoring
            - source_labels: []
              target_label: plane
              replacement: management
            - source_labels: []
              target_label: component
              replacement: tsb

          - job_name: 'mpc'
            metrics_path: '/metrics'
            kubernetes_sd_configs:
              - role: endpoints
                namespaces:
                  names:
                    - tsb
            relabel_configs:
            - source_labels: [__meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
              action: keep
              regex: mpc;http-monitoring
            - source_labels: []
              target_label: plane
              replacement: management
            - source_labels: []
              target_label: component
              replacement: mpc

          - job_name: 'oap'
            metrics_path: '/'
            kubernetes_sd_configs:
            - role: endpoints
              namespaces:
                names:
                - tsb
            relabel_configs:
            - source_labels: [__meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
              action: keep
              regex: oap;http-monitoring
            - source_labels: []
              target_label: plane
              replacement: management
            - source_labels: []
              target_label: component
              replacement: oap
            metric_relabel_configs:
            # Dropped due to conflicts with metric of the same name causing errors in Prometheus code.
            - source_labels: [__name__]
              regex: 'process_start_time_seconds'
              action: drop

          - job_name: 'zipkin'
            metrics_path: '/prometheus'
            kubernetes_sd_configs:
            - role: endpoints
              namespaces:
                names:
                - tsb

            relabel_configs:
            - source_labels: [__meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
              action: keep
              regex: zipkin;http-query
            - source_labels: []
              target_label: plane
              replacement: management
            - source_labels: []
              target_label: component
              replacement: zipkin
            - source_labels: [__name__]
              regex: '^status_(\d+)_(.*)$'
              replacement: '${1}'
              target_label: status
            - source_labels: [__name__]
              regex: '^status_(\d+)_(.*)$'
              replacement: '${2}'
              target_label: path
            - source_labels: [__name__]
              regex: '^status_(\d+)_(.*)$'
              replacement: 'http_requests_total'
              target_label: __name__
            metric_relabel_configs:
            # Dropped due to conflicts with metric of the same name causing errors in Prometheus code.
            - source_labels: [__name__]
              regex: 'process_start_time_seconds'
              action: drop

kind: ConfigMap
metadata:
  labels:
    app: opentelemetry
  name: otel-collector-modified
  namespace: tsb
