Skip to content

Commit

Permalink
Add instrumentation to chart (#1114)
Browse files Browse the repository at this point in the history
* Add instrumentation to chart

* bump version

* feedback iteration

* optional
  • Loading branch information
jaronoff97 authored Apr 10, 2024
1 parent 5009834 commit abe4c7d
Show file tree
Hide file tree
Showing 7 changed files with 545 additions and 27 deletions.
4 changes: 2 additions & 2 deletions charts/opentelemetry-kube-stack/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: opentelemetry-kube-stack
version: 0.0.2
version: 0.0.3
description: |
OpenTelemetry Quickstart chart for Kubernetes.
Installs an operator and collector for an easy way to get started with Kubernetes observability.
Expand All @@ -13,4 +13,4 @@ maintainers:
- name: dmitryax
- name: TylerHelmuth
icon: https://raw.githubusercontent.com/cncf/artwork/a718fa97fffec1b9fd14147682e9e3ac0c8817cb/projects/opentelemetry/icon/color/opentelemetry-icon-color.png
appVersion: 0.96.0
appVersion: 0.97.0
51 changes: 43 additions & 8 deletions charts/opentelemetry-kube-stack/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,53 @@ Allow the release namespace to be overridden
{{- end -}}
{{- end -}}

{{/*
Print a map of key values in a YAML block. This is useful for labels and annotations.
*/}}
{{- define "opentelemetry-kube-stack.renderkv" -}}
{{- with . }}
{{- range $key, $value := . }}
{{- printf "%s: %s" $key $value }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Render a deduped list of environment variables and 'extraEnvs'
*/}}
{{- define "opentelemetry-kube-stack.renderenvs" -}}
{{- $envMap := dict }}
{{- range $item := .extraEnvs }}
{{- $_ := set $envMap $item.name $item.value }}
{{- end }}
{{- range $item := .env }}
{{- $_ := set $envMap $item.name $item.value }}
{{- end }}
{{- range $key, $value := $envMap }}
- name: {{ $key }}
value: {{ $value }}
{{- end }}
{{- end }}

{{/*
Create the name of the instrumentation to use
*/}}
{{- define "opentelemetry-kube-stack.instrumentation" -}}
{{- default .Release.Name .Values.instrumentation.name }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "opentelemetry-collector.chart" -}}
{{- define "opentelemetry-kube-stack.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "opentelemetry-kube-stack.labels" -}}
helm.sh/chart: {{ include "opentelemetry-collector.chart" . }}
helm.sh/chart: {{ include "opentelemetry-kube-stack.chart" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand All @@ -50,7 +85,7 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/*
Expand the name of the chart.
*/}}
{{- define "opentelemetry-collector.name" -}}
{{- define "opentelemetry-kube-stack.collectorName" -}}
{{- default .Chart.Name .collector.name | trunc 63 | trimSuffix "-" }}
{{- end }}

Expand All @@ -59,7 +94,7 @@ 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 "opentelemetry-collector.fullname" -}}
{{- define "opentelemetry-kube-stack.collectorFullname" -}}
{{- if .fullnameOverride }}
{{- .fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
Expand All @@ -75,15 +110,15 @@ If release name contains chart name it will be used as a full name.
{{/*
Create the name of the clusterRole to use
*/}}
{{- define "opentelemetry-collector.clusterRoleName" -}}
{{- define "opentelemetry-kube-stack.clusterRoleName" -}}
{{- default (printf "%s-collector" .Release.Name) .Values.clusterRole.name }}
{{- end }}

{{/*
Create the name of the clusterRoleBinding to use
*/}}
{{- define "opentelemetry-collector.clusterRoleBindingName" -}}
{{- default (include "opentelemetry-collector.fullname" .) .Values.clusterRole.clusterRoleBinding.name }}
{{- define "opentelemetry-kube-stack.clusterRoleBindingName" -}}
{{- default (include "opentelemetry-kube-stack.fullname" .) .Values.clusterRole.clusterRoleBinding.name }}
{{- end }}

{{/*
Expand All @@ -93,7 +128,7 @@ This allows a user to supply a scrape_configs_file. This file is templated and l
If a user has already supplied a prometheus receiver config, the file's config is appended. Finally,
the config is written as YAML.
*/}}
{{- define "opentelemetry-collector.config" -}}
{{- define "opentelemetry-kube-stack.config" -}}
{{- if .collector.scrape_configs_file }}
{{- $loaded_file := (.Files.Get .collector.scrape_configs_file) }}
{{- $loaded_config := (fromYamlArray (tpl $loaded_file .)) }}
Expand Down
2 changes: 1 addition & 1 deletion charts/opentelemetry-kube-stack/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "opentelemetry-collector.clusterRoleName" . }}
name: {{ include "opentelemetry-kube-stack.clusterRoleName" . }}
rules:
- apiGroups: [""]
resources:
Expand Down
19 changes: 4 additions & 15 deletions charts/opentelemetry-kube-stack/templates/collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- if $collector.enabled -}}
{{- $collector := (mergeOverwrite (deepCopy $.Values.defaultCRConfig) $collector) }}
{{- $merged := (dict "Template" $.Template "Files" $.Files "Chart" $.Chart "clusterRole" $.Values.clusterRole "collector" $collector "Release" $.Release "fullnameOverride" $.Values.fullnameOverride) }}
{{- $fullname := (include "opentelemetry-collector.fullname" $merged) }}
{{- $fullname := (include "opentelemetry-kube-stack.collectorFullname" $merged) }}
---
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
Expand All @@ -11,16 +11,10 @@ metadata:
namespace: {{ include "opentelemetry-kube-stack.namespace" $ }}
labels:
{{- include "opentelemetry-kube-stack.labels" $ | nindent 4 }}
{{- with $collector.labels }}
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $ | quote) | nindent 4 }}
{{- end }}
{{- end }}
{{- include "opentelemetry-kube-stack.renderkv" $collector.labels | nindent 4 }}
{{- with $collector.annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $ | quote) | nindent 4 }}
{{- end }}
{{- include "opentelemetry-kube-stack.renderkv" . | nindent 4 }}
{{- end }}
spec:
managementState: {{ $collector.managementState }}
Expand Down Expand Up @@ -117,9 +111,6 @@ spec:
{{- toYaml . | nindent 4 }}
{{- end }}
env:
{{- with $.Values.extraEnvs }}
{{- toYaml . | nindent 2 }}
{{- end }}
- name: OTEL_K8S_NODE_NAME
valueFrom:
fieldRef:
Expand Down Expand Up @@ -147,9 +138,7 @@ spec:
- name: OTEL_RESOURCE_ATTRIBUTES
value: "k8s.cluster.name={{ $.Values.clusterName }}"
{{- end }}
{{- with $collector.env }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- include "opentelemetry-kube-stack.renderenvs" (dict "extraEnvs" $.Values.extraEnvs "env" $collector.env) | nindent 4 }}
{{- with $collector.envFrom }}
envFrom:
{{- toYaml . | nindent 4 }}
Expand Down
57 changes: 57 additions & 0 deletions charts/opentelemetry-kube-stack/templates/instrumentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{- if .Values.instrumentation.enabled }}
---
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
name: {{ include "opentelemetry-kube-stack.instrumentation" . }}
labels:
{{- include "opentelemetry-kube-stack.labels" $ | nindent 4 }}
{{- include "opentelemetry-kube-stack.renderkv" .Values.instrumentation.labels | nindent 4 }}
{{- with .Values.instrumentation.annotations }}
annotations:
{{- include "opentelemetry-kube-stack.renderkv" . | nindent 4 }}
{{- end }}
spec:
exporter:
endpoint: {{ .Values.instrumentation.exporter.endpoint }}
propagators:
{{- toYaml .Values.instrumentation.propagators | nindent 4 }}
{{- with .Values.instrumentation.sampler }}
sampler:
{{- toYaml . | nindent 4 }}
{{- end }}
env:
{{- include "opentelemetry-kube-stack.renderenvs" (dict "extraEnvs" $.Values.extraEnvs "env" .Values.instrumentation.env) | nindent 4 }}
{{- with .Values.instrumentation.resource }}
resource:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.instrumentation.java }}
java:
{{- toYaml . | nindent 4}}
{{- end }}
{{- with .Values.instrumentation.nodejs }}
nodejs:
{{- toYaml . | nindent 4}}
{{- end }}
{{- with .Values.instrumentation.python }}
python:
{{- toYaml . | nindent 4}}
{{- end }}
{{- with .Values.instrumentation.dotnet }}
dotnet:
{{- toYaml . | nindent 4}}
{{- end }}
{{- with .Values.instrumentation.go }}
go:
{{- toYaml . | nindent 4}}
{{- end }}
{{- with .Values.instrumentation.apacheHttpd }}
apacheHtpd:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.instrumentation.nginx }}
nginx:
{{- toYaml . | nindent 4}}
{{- end }}
{{- end }}
Loading

0 comments on commit abe4c7d

Please sign in to comment.