# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
{{- if .Values.opentelemetry.enabled }}
{{- $configs := list
  "opentelemetry-config-nginx"
  "opentelemetry-config-apisix"
  "opentelemetry-config-istiod-monitor"
  "opentelemetry-config-kubernetes-monitor"
  "opentelemetry-config-mysql-monitor"
  "opentelemetry-config-postgresql-monitor"
  "opentelemetry-config-so11y"
  "opentelemetry-config-vm"
  "opentelemetry-config-elasticsearch-monitor"
  "opentelemetry-config-rabbitmq-monitor"
  "opentelemetry-config-mongodb-monitor"
  "opentelemetry-config-rocketmq-monitor"
  "opentelemetry-config-pulsar-monitor"
  "opentelemetry-config-activemq-monitor"
  "opentelemetry-config-flink-monitor"
}}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: otel-collector-config
data:
  config.yaml: |
    receivers:
      {{- $root := . -}}
      {{- range $idx, $config := $configs -}}
      {{- if not (include $config $root | trim | empty) }}
      prometheus/{{ $idx }}:
        config:
          scrape_configs:
            {{- include $config $root | indent 12 }}
      {{- end }}
      {{- end }}

    exporters:
      {{- $root := . }}
      {{- range $idx, $config := $configs }}
      {{- if not (include $config $root | trim | empty) }}
      otlp/{{ $idx }}:
        endpoint: "{{ include "skywalking.oap.address.grpc" $root }}"
        tls:
          insecure: true
      {{- end }}
      {{- end }}
      logging:
        verbosity: detailed

    extensions:
      # The health_check extension is mandatory for this chart.
      # Without the health_check extension the collector will fail the readiness and liveliness probes.
      # The health_check extension can be modified, but should never be removed.
      health_check: {}

    service:
      pipelines:
      {{- $root := . }}
      {{- range $idx, $config := $configs }}
      {{- if not (include $config $root | trim | empty) }}
        metrics/{{ $idx }}:
          receivers: 
            - prometheus/{{ $idx }}
          exporters: [ otlp/{{ $idx }},logging ]
      {{- end }}
      {{- end }}
      extensions:
        - health_check

{{- end }}
