{{/* Default memory limiter configuration for OpenTelemetry Collector based on k8s resource limits. */}} {{- define "opentelemetry-collector.memoryLimiter" -}} # check_interval is the time between measurements of memory usage. check_interval: 5s # By default limit_mib is set to 80% of ".Values.resources.limits.memory" limit_percentage: 80 # By default spike_limit_mib is set to 25% of ".Values.resources.limits.memory" spike_limit_percentage: 25 {{- end }} {{/* Merge user supplied config into memory limiter config. */}} {{- define "opentelemetry-collector.baseConfig" -}} {{- $processorsConfig := get .Values.config "processors" }} {{- if not $processorsConfig.memory_limiter }} {{- $_ := set $processorsConfig "memory_limiter" (include "opentelemetry-collector.memoryLimiter" . | fromYaml) }} {{- end }} {{- .Values.config | toYaml }} {{- end }} {{/* Build config file for daemonset OpenTelemetry Collector */}} {{- define "opentelemetry-collector.daemonsetConfig" -}} {{- $values := deepCopy .Values }} {{- $data := dict "Values" $values | mustMergeOverwrite (deepCopy .) }} {{- $config := include "opentelemetry-collector.baseConfig" $data | fromYaml }} {{- if eq (include "opentelemetry-collector.logsCollectionEnabled" .) "true" }} {{- $config = (include "opentelemetry-collector.applyLogsCollectionConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} {{- if .Values.presets.hostMetrics.enabled }} {{- $config = (include "opentelemetry-collector.applyHostMetricsConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} {{- if .Values.presets.kubeletMetrics.enabled }} {{- $config = (include "opentelemetry-collector.applyKubeletMetricsConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} {{- if .Values.presets.kubernetesAttributes.enabled }} {{- $config = (include "opentelemetry-collector.applyKubernetesAttributesConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} {{- if .Values.presets.clusterMetrics.enabled }} {{- $config = (include "opentelemetry-collector.applyClusterMetricsConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} {{- tpl (toYaml $config) . }} {{- end }} {{/* Build config file for deployment OpenTelemetry Collector */}} {{- define "opentelemetry-collector.deploymentConfig" -}} {{- $values := deepCopy .Values }} {{- $data := dict "Values" $values | mustMergeOverwrite (deepCopy .) }} {{- $config := include "opentelemetry-collector.baseConfig" $data | fromYaml }} {{- if eq (include "opentelemetry-collector.logsCollectionEnabled" .) "true" }} {{- $config = (include "opentelemetry-collector.applyLogsCollectionConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} {{- if .Values.presets.hostMetrics.enabled }} {{- $config = (include "opentelemetry-collector.applyHostMetricsConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} {{- if .Values.presets.kubeletMetrics.enabled }} {{- $config = (include "opentelemetry-collector.applyKubeletMetricsConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} {{- if .Values.presets.kubernetesAttributes.enabled }} {{- $config = (include "opentelemetry-collector.applyKubernetesAttributesConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} {{- if .Values.presets.clusterMetrics.enabled }} {{- $config = (include "opentelemetry-collector.applyClusterMetricsConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} {{- tpl (toYaml $config) . }} {{- end }} {{- define "opentelemetry-collector.applyHostMetricsConfig" -}} {{- $config := mustMergeOverwrite (include "opentelemetry-collector.hostMetricsConfig" .Values | fromYaml) .config }} {{- $_ := set $config.service.pipelines.metrics "receivers" (append $config.service.pipelines.metrics.receivers "hostmetrics" | uniq) }} {{- $config | toYaml }} {{- end }} {{- define "opentelemetry-collector.hostMetricsConfig" -}} receivers: hostmetrics: root_path: /hostfs collection_interval: 10s scrapers: cpu: load: memory: disk: filesystem: exclude_mount_points: mount_points: - /dev/* - /proc/* - /sys/* - /run/k3s/containerd/* - /var/lib/docker/* - /var/lib/kubelet/* - /snap/* match_type: regexp exclude_fs_types: fs_types: - autofs - binfmt_misc - bpf - cgroup2 - configfs - debugfs - devpts - devtmpfs - fusectl - hugetlbfs - iso9660 - mqueue - nsfs - overlay - proc - procfs - pstore - rpc_pipefs - securityfs - selinuxfs - squashfs - sysfs - tracefs match_type: strict network: {{- end }} {{- define "opentelemetry-collector.applyClusterMetricsConfig" -}} {{- $config := mustMergeOverwrite (include "opentelemetry-collector.clusterMetricsConfig" .Values | fromYaml) .config }} {{- $_ := set $config.service.pipelines.metrics "receivers" (append $config.service.pipelines.metrics.receivers "k8s_cluster" | uniq) }} {{- $config | toYaml }} {{- end }} {{- define "opentelemetry-collector.clusterMetricsConfig" -}} receivers: k8s_cluster: collection_interval: 10s {{- end }} {{- define "opentelemetry-collector.applyKubeletMetricsConfig" -}} {{- $config := mustMergeOverwrite (include "opentelemetry-collector.kubeletMetricsConfig" .Values | fromYaml) .config }} {{- $_ := set $config.service.pipelines.metrics "receivers" (append $config.service.pipelines.metrics.receivers "kubeletstats" | uniq) }} {{- $config | toYaml }} {{- end }} {{- define "opentelemetry-collector.kubeletMetricsConfig" -}} receivers: kubeletstats: collection_interval: 20s auth_type: "serviceAccount" endpoint: "${K8S_NODE_NAME}:10250" {{- end }} {{- define "opentelemetry-collector.applyLogsCollectionConfig" -}} {{- $config := mustMergeOverwrite (include "opentelemetry-collector.logsCollectionConfig" .Values | fromYaml) .config }} {{- $_ := set $config.service.pipelines.logs "receivers" (append $config.service.pipelines.logs.receivers "filelog" | uniq) }} {{- if .Values.Values.presets.logsCollection.storeCheckpoints}} {{- $_ := set $config.service "extensions" (append $config.service.extensions "file_storage" | uniq) }} {{- end }} {{- $config | toYaml }} {{- end }} {{- define "opentelemetry-collector.logsCollectionConfig" -}} {{- if .Values.presets.logsCollection.storeCheckpoints }} extensions: file_storage: directory: /var/lib/otelcol {{- end }} receivers: filelog: include: [ /var/log/pods/*/*/*.log ] {{- if .Values.presets.logsCollection.includeCollectorLogs }} exclude: [] {{- else }} # Exclude collector container's logs. The file format is /var/log/pods/__//.log exclude: [ /var/log/pods/{{ .Release.Namespace }}_{{ include "opentelemetry-collector.lowercase_chartname" . }}*_*/{{ include "opentelemetry-collector.name" . }}/*.log ] {{- end }} start_at: end {{- if .Values.presets.logsCollection.storeCheckpoints}} storage: file_storage {{- end }} include_file_path: true include_file_name: false operators: # Find out which format is used by kubernetes - type: router id: get-format routes: - output: parser-docker expr: 'body matches "^\\{"' - output: parser-crio expr: 'body matches "^[^ Z]+ "' - output: parser-containerd expr: 'body matches "^[^ Z]+Z"' # Parse CRI-O format - type: regex_parser id: parser-crio regex: '^(?P