Skip to content

Commit

Permalink
add opentelemetry-demo chart (#280)
Browse files Browse the repository at this point in the history
* add opentelemetry-demo chart

* fix lint

* add README.and rename to opentelemetry-demo-webstore

* Reduce the complexity of using otelcol's config by default (future flexible configuration of otelcol by value.yaml)

* rename to opentelemetry-demo-webstore

* clean up code

* Apply suggestions from code review

Co-authored-by: Tyler Helmuth <[email protected]>

* add @dmitryax and @tigrannajaryan as opentelemetry-demo-webstore maintainers

* double check jaeger/otelcol ports

* Update charts/opentelemetry-demo-webstore/Chart.yaml

Co-authored-by: Tigran Najaryan <[email protected]>

* 1. rename _pod.tpl
2. rename _deployment.yaml
3. otelcol configmap logic improve, add sha256sum!

* add tyler helmuth as maintainers

* fixed load generator not working

* fixed some service not send trace

* rename opentelemetry-demo-webstore to opentelemetry-demo

* improve notes.txt

* remove depends_on in value.yaml
change _deployment.yaml to _deployment.tpl

* style fix

* change value.yaml compoents name to camelCase

* add schema.json

* Update charts/opentelemetry-demo-webstore/templates/NOTES.txt

Co-authored-by: Dmitrii Anoshin <[email protected]>

* rename

* Update charts/opentelemetry-demo/values.schema.json

Co-authored-by: Tyler Helmuth <[email protected]>

* move logic to _objects.tpl

Co-authored-by: Tyler Helmuth <[email protected]>
Co-authored-by: Tigran Najaryan <[email protected]>
Co-authored-by: Dmitrii Anoshin <[email protected]>
  • Loading branch information
4 people authored Jul 26, 2022
1 parent 5ae91bc commit 8fa530f
Show file tree
Hide file tree
Showing 12 changed files with 769 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/opentelemetry-demo/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
14 changes: 14 additions & 0 deletions charts/opentelemetry-demo/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v2
type: application
name: opentelemetry-demo
version: 0.1.0
description: opentelemetry demo helm chart
home: https://opentelemetry.io/
sources:
- https://github.com/open-telemetry/opentelemetry-demo
maintainers:
- name: dmitryax
- name: tylerhelmuth
- name: wph95
icon: https://opentelemetry.io/img/logos/opentelemetry-logo-nav.png
appVersion: "0.2.0-alpha"
22 changes: 22 additions & 0 deletions charts/opentelemetry-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# OpenTelemetry Demo Helm Chart

The helm chart installs [OpenTelemetry Demo](https://github.com/open-telemetry/opentelemetry-demo)
in kubernetes cluster.

## Prerequisites

- Helm 3.0+

## Installing the Chart

Add OpenTelemetry Helm repository:

```console
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
```

To install the chart with the release name my-otel-demo, run the following command:

```console
helm install my-otel-demo open-telemetry/opentelemetry-demo
```
22 changes: 22 additions & 0 deletions charts/opentelemetry-demo/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
=======================================================================================


██████╗ ████████╗███████╗██╗ ██████╗ ███████╗███╗ ███╗ ██████╗
██╔═══██╗╚══██╔══╝██╔════╝██║ ██╔══██╗██╔════╝████╗ ████║██╔═══██╗
██║ ██║ ██║ █████╗ ██║ ██║ ██║█████╗ ██╔████╔██║██║ ██║
██║ ██║ ██║ ██╔══╝ ██║ ██║ ██║██╔══╝ ██║╚██╔╝██║██║ ██║
╚██████╔╝ ██║ ███████╗███████╗ ██████╔╝███████╗██║ ╚═╝ ██║╚██████╔╝
╚═════╝ ╚═╝ ╚══════╝╚══════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝


- Frontend UI: http://localhost:8080
by running these commands:
kubectl port-forward svc/{{ include "otel-demo.name" . }}-frontend 8080:8080


{{- if $.Values.observability.jaeger.enabled }}

- Jaeger UI: http://localhost:16686
by running these commands:
kubectl port-forward svc/{{ include "otel-demo.name" . }}-jaeger 16686:16686
{{- end }}
36 changes: 36 additions & 0 deletions charts/opentelemetry-demo/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "otel-demo.name" -}}
{{- default .Release.Name | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Common labels
*/}}
{{- define "otel-demo.labels" -}}
helm.sh/chart: {{ include "otel-demo.chart" . }}
{{ include "otel-demo.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "otel-demo.selectorLabels" -}}
app.kubernetes.io/name: {{ include "otel-demo.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .name }}
app.kubernetes.io/component: {{ .name}}
{{- end}}
{{- end }}
96 changes: 96 additions & 0 deletions charts/opentelemetry-demo/templates/_objects.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{{- define "otel.demo.deployment" }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "otel-demo.name" . }}-{{ .name }}
labels:
{{- include "otel-demo.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "otel-demo.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "otel-demo.selectorLabels" . | nindent 8 }}
spec:
{{- if .imageConfig.pullSecrets }}
imagePullSecrets:
{{- toYaml .imageConfig.pullSecrets | nindent 8}}
{{- end }}
{{- with .serviceAccountName }}
serviceAccountName: {{ .serviceAccountName}}
{{- end }}
containers:
- name: {{ .name }}
image: {{ .image | default (printf "%s:v%s-%s" .imageConfig.repository .Chart.AppVersion (.name | replace "-" "" | lower)) }}
{{- if or .ports .servicePort}}
ports:
{{- include "otel-demo.pod.ports" . | nindent 10 }}
{{- end }}
env:
{{- include "otel-demo.pod.env" . | nindent 10 }}

{{- end }}

{{- define "otel.demo.service" }}
{{- if or .ports .servicePort}}
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "otel-demo.name" . }}-{{ .name }}
labels:
{{- include "otel-demo.labels" . | nindent 4 }}
spec:
ports:
{{- if .ports }}
{{- range $port := .ports }}
- port: {{ $port.value }}
name: {{ $port.name}}
targetPort: {{ $port.value }}
{{- end }}
{{- end }}

{{- if .servicePort }}
- port: {{.servicePort}}
name: service
targetPort: {{ .servicePort }}
{{- end }}
selector:
{{- include "otel-demo.selectorLabels" . | nindent 4 }}
{{- end}}
{{- end}}

{{- define "otel-demo.otelcol.config" -}}
receivers:
otlp:
protocols:
grpc:
http:
exporters:
{{- if .Values.observability.jaeger.enabled }}
jaeger:
endpoint: "${JAEGER_ADDR}"
tls:
insecure: true
{{- end}}
logging:

processors:
batch:

service:
pipelines:
traces:
receivers:
- otlp
processors:
- batch
exporters:
- logging
{{- if .Values.observability.jaeger.enabled }}
- jaeger
{{- end}}
{{- end }}
91 changes: 91 additions & 0 deletions charts/opentelemetry-demo/templates/_pod.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{{/*
Component Depends Config
*/}}
{{- define "otel-demo.pod.dependsConfig" -}}
cart-service:
- redis
checkout-service:
- cart-service
- currency-service
- email-service
- payment-service
- product-catalog-service
- shipping-service
frontend:
- ad-service
- cart-service
- checkout-service
- currency-service
- product-catalog-service
- recommendation-service
- shipping-service
loadgenerator:
- frontend
recommendation-service:
- product-catalog-service
{{- end}}


{{/*
Get Services Port Mapping
*/}}
{{- define "otel-demo.pod.serviceMapping" -}}
{{ $servicePortMap := default dict }}
{{- range $name, $config := .Values.components }}
{{- if $config.servicePort }}
{{ $name | kebabcase }}: {{ $config.servicePort }}
{{- else if $config.ports }}
{{ $name | kebabcase}}: {{ (get (index $config.ports 0 ) "value") }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Get Pod Env
*/}}
{{- define "otel-demo.pod.env" -}}
{{- $prefix := include "otel-demo.name" $ }}

{{- if .env }}
{{- toYaml .env }}
{{- end }}

{{- if .observability.otelcol.enabled }}
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://{{ include "otel-demo.name" . }}-otelcol:4317
- name: OTEL_RESOURCE_ATTRIBUTES
value: service.name={{ .name | kebabcase }}
{{- end }}

{{- if .servicePort}}
- name: {{ printf "%s_PORT" .name | snakecase | upper }}
value: {{.servicePort | quote}}
{{- end }}

# {{ $.depends }}
# {{ .name }}
{{- if hasKey $.depends .name }}
{{- range $depend := get $.depends .name }}
- name: {{ printf "%s_ADDR" $depend | snakecase | upper }}
value: {{ printf "%s-%s:%0.f" $prefix ($depend | kebabcase) (get $.serviceMapping $depend )}}
{{- end }}
{{- end }}

{{- end }}

{{/*
Get Pod ports
*/}}
{{- define "otel-demo.pod.ports" -}}
{{- if .ports }}
{{- range $port := .ports }}
- containerPort: {{ $port.value }}
name: {{ $port.name}}
{{- end }}
{{- end }}

{{- if .servicePort }}
- containerPort: {{.servicePort}}
name: service
{{- end }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/opentelemetry-demo/templates/component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{ $serviceMapping := include "otel-demo.pod.serviceMapping" . | fromYaml}}
{{ $depends := include "otel-demo.pod.dependsConfig" . | fromYaml }}
{{- range $name, $config := .Values.components }}
{{- $config := set . "name" ($name | kebabcase) }}
{{- $config := set . "Release" $.Release }}
{{- $config := set . "Chart" $.Chart }}
{{- $config := set . "imageConfig" $.Values.image }}
{{- $config := set . "serviceAccount" $.Values.serviceAccount }}
{{- $config := set . "observability" $.Values.observability }}
{{- $config := set . "serviceMapping" $serviceMapping }}
{{- $config := set . "depends" $depends }}

{{- if $config.enabled -}}
{{- include "otel.demo.deployment" $config -}}
{{- include "otel.demo.service" $config -}}
{{ end }}

{{- end }}
62 changes: 62 additions & 0 deletions charts/opentelemetry-demo/templates/jaeger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{- $config := set . "name" "jaeger" }}
{{- if $.Values.observability.jaeger.enabled -}}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "otel-demo.name" . }}-{{ .name }}
labels:
{{- include "otel-demo.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "otel-demo.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "otel-demo.selectorLabels" . | nindent 8 }}
spec:
containers:
- env:
- name: COLLECTOR_ZIPKIN_HTTP_PORT
value: "9411"
image: jaegertracing/all-in-one
name: jaeger
ports:
- containerPort: 5775
protocol: UDP
- containerPort: 6831
protocol: UDP
- containerPort: 6832
protocol: UDP
- containerPort: 5778
protocol: TCP
- containerPort: 16686
protocol: TCP
- containerPort: 14268
protocol: TCP
- containerPort: 9411
protocol: TCP
- containerPort: 14250
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "otel-demo.name" . }}-{{ .name }}
labels:
{{- include "otel-demo.labels" . | nindent 4 }}
spec:
ports:
- name: frontend
port: 16686
protocol: TCP
targetPort: 16686
- name: collector
port: 14250
protocol: TCP
targetPort: 14250
selector:
{{- include "otel-demo.selectorLabels" . | nindent 4 }}
{{- end }}
Loading

0 comments on commit 8fa530f

Please sign in to comment.