From f2d21b399bce5e5fae324f4781706f0a1299bf83 Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Sat, 21 Sep 2024 23:31:40 -0400 Subject: [PATCH] add otel agent to help deploy --- charts/ctrlplane/Chart.lock | 7 +- charts/ctrlplane/Chart.yaml | 5 +- charts/ctrlplane/charts/otel/.helmignore | 23 +++ charts/ctrlplane/charts/otel/Chart.yaml | 7 + charts/ctrlplane/charts/otel/README.md | 7 + .../charts/otel/templates/_config.tpl | 99 ++++++++++ .../charts/otel/templates/_helpers.tpl | 102 ++++++++++ .../charts/otel/templates/_receivers.tpl | 178 ++++++++++++++++++ .../charts/otel/templates/clusterrole.yaml | 54 ++++++ .../otel/templates/clusterrolebinding.yaml | 23 +++ .../charts/otel/templates/configmap.yaml | 18 ++ .../charts/otel/templates/deployment.yaml | 91 +++++++++ .../charts/otel/templates/service.yaml | 35 ++++ .../charts/otel/templates/serviceaccount.yaml | 15 ++ charts/ctrlplane/charts/otel/trace_test.py | 29 +++ charts/ctrlplane/charts/otel/values.yaml | 66 +++++++ .../webservice/templates/deployment.yaml | 2 + 17 files changed, 758 insertions(+), 3 deletions(-) create mode 100644 charts/ctrlplane/charts/otel/.helmignore create mode 100644 charts/ctrlplane/charts/otel/Chart.yaml create mode 100644 charts/ctrlplane/charts/otel/README.md create mode 100644 charts/ctrlplane/charts/otel/templates/_config.tpl create mode 100644 charts/ctrlplane/charts/otel/templates/_helpers.tpl create mode 100644 charts/ctrlplane/charts/otel/templates/_receivers.tpl create mode 100644 charts/ctrlplane/charts/otel/templates/clusterrole.yaml create mode 100644 charts/ctrlplane/charts/otel/templates/clusterrolebinding.yaml create mode 100644 charts/ctrlplane/charts/otel/templates/configmap.yaml create mode 100644 charts/ctrlplane/charts/otel/templates/deployment.yaml create mode 100644 charts/ctrlplane/charts/otel/templates/service.yaml create mode 100644 charts/ctrlplane/charts/otel/templates/serviceaccount.yaml create mode 100644 charts/ctrlplane/charts/otel/trace_test.py create mode 100644 charts/ctrlplane/charts/otel/values.yaml diff --git a/charts/ctrlplane/Chart.lock b/charts/ctrlplane/Chart.lock index 28b7095..8267d47 100644 --- a/charts/ctrlplane/Chart.lock +++ b/charts/ctrlplane/Chart.lock @@ -11,5 +11,8 @@ dependencies: - name: event-worker repository: file://charts/event-worker version: 0.1.6 -digest: sha256:6ae2f2e02680d3694444d67aba248dfd3a0352678d7c58d2bce30c8bfdf7be1f -generated: "2024-08-28T21:15:56.001463-05:00" +- name: otel + repository: file://charts/otel + version: 0.1.0 +digest: sha256:a787c72024ab9ccde1b53b471ea5e8c23583f20649e8ae9bd9c48bcbc3a835f6 +generated: "2024-09-21T23:19:52.598333-04:00" diff --git a/charts/ctrlplane/Chart.yaml b/charts/ctrlplane/Chart.yaml index d7e17fb..52add12 100644 --- a/charts/ctrlplane/Chart.yaml +++ b/charts/ctrlplane/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: ctrlplane description: Ctrlplane Helm chart for Kubernetes type: application -version: 0.1.23 +version: 0.1.24 appVersion: "1.16.0" maintainers: @@ -26,3 +26,6 @@ dependencies: - name: event-worker version: "*.*.*" repository: "file://charts/event-worker" + - name: otel + version: "*.*.*" + repository: "file://charts/otel" diff --git a/charts/ctrlplane/charts/otel/.helmignore b/charts/ctrlplane/charts/otel/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/ctrlplane/charts/otel/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/ctrlplane/charts/otel/Chart.yaml b/charts/ctrlplane/charts/otel/Chart.yaml new file mode 100644 index 0000000..40908d6 --- /dev/null +++ b/charts/ctrlplane/charts/otel/Chart.yaml @@ -0,0 +1,7 @@ +apiVersion: v2 +name: otel +type: application +description: A Helm chart for Kubernetes + +version: 0.1.0 +appVersion: "0.109.0" diff --git a/charts/ctrlplane/charts/otel/README.md b/charts/ctrlplane/charts/otel/README.md new file mode 100644 index 0000000..ad713f6 --- /dev/null +++ b/charts/ctrlplane/charts/otel/README.md @@ -0,0 +1,7 @@ +We had to create a seperate chart, because the offical one does not support + +1. We need to send an otlphttp to the console server. The name of this service + is dynamic. TEL helm chart does not support dynamic pipeline values +2. We could do the above as a config map, and pass it into the agent... however, + otel helm does not support using custom config maps names because they need + to be based on the release name. diff --git a/charts/ctrlplane/charts/otel/templates/_config.tpl b/charts/ctrlplane/charts/otel/templates/_config.tpl new file mode 100644 index 0000000..e42da8b --- /dev/null +++ b/charts/ctrlplane/charts/otel/templates/_config.tpl @@ -0,0 +1,99 @@ +{{- define "otel.config" -}} +{{- $data := deepCopy .Values.config }} +{{- $config := .Values.config }} +{{- if .Values.presets.receivers.hostMetrics }} +{{- $config = mustMergeOverwrite (include "otel.hostMetricsReceiver" . | fromYaml) $config }} +{{- end }} +{{- if .Values.presets.receivers.logsCollection }} +{{- $config = mustMergeOverwrite (include "otel.logsCollectionReceiver" . | fromYaml) $config }} +{{- end }} +{{- if .Values.presets.receivers.kubeletMetrics }} +{{- $config = mustMergeOverwrite (include "otel.kubeletMetricsReceiver" . | fromYaml) $config }} +{{- end }} +{{- if .Values.presets.receivers.kubernetesEvent }} +{{- $config = mustMergeOverwrite (include "otel.kubernetesEventReceiver" . | fromYaml) $config }} +{{- end }} +{{- if .Values.presets.receivers.kubernetesCluster }} +{{- $config = mustMergeOverwrite (include "otel.kubernetesClusterReceiver" . | fromYaml) $config }} +{{- end }} +{{- if .Values.presets.receivers.statsd }} +{{- $config = mustMergeOverwrite (include "otel.statsdReceiver" . | fromYaml) $config }} +{{- end }} +{{- if .Values.presets.receivers.otlp }} +{{- $config = mustMergeOverwrite (include "otel.otlpReceiver" . | fromYaml) $config }} +{{- end }} +{{- $config = mustMergeOverwrite (include "otel.extensions" . | fromYaml) $config }} +{{- $config = mustMergeOverwrite (include "otel.processors" . | fromYaml) $config }} +{{- $config = mustMergeOverwrite (include "otel.service" . | fromYaml) $config }} +{{- $config = mustMergeOverwrite (include "otel.exporter" . | fromYaml) $config }} +{{- tpl (toYaml $config) . }} +{{- end }} + +{{- define "otel.exporter" -}} +exporters: + debug: {} + debug/detailed: + verbosity: detailed + prometheus: + endpoint: 0.0.0.0:9109 +{{- end }} + +{{- define "otel.extensions" -}} +extensions: + health_check: {} + memory_ballast: + size_in_percentage: 40 +{{- end }} + +{{- define "otel.processors" -}} +processors: + batch: {} + memory_limiter: + check_interval: 5s + limit_percentage: 80 + spike_limit_percentage: 25 + k8sattributes: + filter: + node_from_env_var: K8S_NODE_NAME + passthrough: false + pod_association: + - sources: + - from: resource_attribute + name: k8s.pod.ip + - sources: + - from: resource_attribute + name: k8s.pod.uid + - sources: + - from: connection + extract: + metadata: + - "k8s.namespace.name" + - "k8s.deployment.name" + - "k8s.statefulset.name" + - "k8s.daemonset.name" + - "k8s.cronjob.name" + - "k8s.job.name" + - "k8s.node.name" + - "k8s.pod.name" + - "k8s.pod.uid" + - "k8s.pod.start_time" + annotations: + - tag_name: $$1 + key_regex: (.*) + from: pod + labels: + - tag_name: $$1 + key_regex: (.*) + from: pod +{{- end }} + +{{- define "otel.service" -}} +service: + extensions: + - health_check + - memory_ballast + pipelines: {} + telemetry: + metrics: + address: ${env:POD_IP}:8888 +{{- end }} \ No newline at end of file diff --git a/charts/ctrlplane/charts/otel/templates/_helpers.tpl b/charts/ctrlplane/charts/otel/templates/_helpers.tpl new file mode 100644 index 0000000..945fa6e --- /dev/null +++ b/charts/ctrlplane/charts/otel/templates/_helpers.tpl @@ -0,0 +1,102 @@ +{{/* vim: set filetype=mustache: */}} + +{{/* +Expand the name of the chart. +*/}} +{{- define "otel.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "otel.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "otel.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "otel.labels" -}} +helm.sh/chart: {{ include "otel.chart" . }} +{{ include "otel.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +ctrlplane.com/app-name: {{ include "otel.chart" . }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "otel.selectorLabels" -}} +app.kubernetes.io/name: {{ include "otel.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "otel.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "otel.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Returns the extraEnv keys and values to inject into containers. + +Global values will override any chart-specific values. +*/}} +{{- define "otel.extraEnv" -}} +{{- $allExtraEnv := merge (default (dict) .local.extraEnv) .global.extraEnv -}} +{{- range $key, $value := $allExtraEnv }} +- name: {{ $key }} + value: {{ $value | quote }} +{{- end -}} +{{- end -}} + +{{/* +Returns a list of _common_ labels to be shared across all +app deployments and other shared objects. +*/}} +{{- define "otel.commonLabels" -}} +{{- $commonLabels := default (dict) .Values.common.labels -}} +{{- if $commonLabels }} +{{- range $key, $value := $commonLabels }} +{{ $key }}: {{ $value | quote }} +{{- end }} +{{- end -}} +{{- end -}} + +{{/* +Returns a list of _pod_ labels to be shared across all +app deployments. +*/}} +{{- define "otel.podLabels" -}} +{{- range $key, $value := .Values.pod.labels }} +{{ $key }}: {{ $value | quote }} +{{- end }} +{{- end -}} + diff --git a/charts/ctrlplane/charts/otel/templates/_receivers.tpl b/charts/ctrlplane/charts/otel/templates/_receivers.tpl new file mode 100644 index 0000000..cff369c --- /dev/null +++ b/charts/ctrlplane/charts/otel/templates/_receivers.tpl @@ -0,0 +1,178 @@ +{{- define "otel.hostMetricsReceiver" -}} +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 "otel.logsCollectionReceiver" -}} +receivers: + filelog: + include: [ /var/log/pods/*/*/*.log ] + exclude: [] + start_at: 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