Skip to content

Commit

Permalink
Add telemetry support
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanartecona committed Mar 8, 2024
1 parent 35e1348 commit 6c9566f
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 0 deletions.
66 changes: 66 additions & 0 deletions charts/retool/ci/telemetry-enabled-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# ================================================
# === boilerplate to get a bootable deployment ===
# ================================================
config:
encryptionKey: '000000000'
jwtSecret: '000000000'

licenseKey: "EXPIRED-LICENSE-KEY-TRIAL"

image:
tag: 'latest'

resources:
requests:
cpu: 500m
memory: 1024Mi
limits:
cpu: 1000m
memory: 4096Mi

workflows:
resources:
requests:
cpu: 500m
memory: 1024Mi
limits:
cpu: 1000m
memory: 2048Mi

env:
NUM_WORKERS: '1'
# NODE_DEBUG: 'module'

ingress:
kubernetes.io/ingress.class: nginx
hosts:
- host: retool.example.com
paths:
- path: /

livenessProbe:
timeoutSeconds: 60
periodSeconds: 2
failureThreshold: 60
readinessProbe:
timeoutSeconds: 30
periodSeconds: 5

replicaCount: 1

persistentVolumeClaim:
size: '3Gi'
# ================================================

# === New telemetry stuff ===
telemetry:
enabled: true
image:
repository: 'tryretool/telemetry'
# tag:
sendToRetool:
enabled: true
customVectorConfig:
foo: bar
customGrafanaAgentConfig: |
// wee woo custom text
1 change: 1 addition & 0 deletions charts/retool/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{{- end }}

{{- if and .Values.postgresql.enabled (and (not .Values.postgresql.auth.postgresPassword) (eq .Values.postgresql.auth.username "postgres")) }}

***************************************************************************
Warning: Using in-cluster postgresql setup. `.Values.postgresql.auth.username username` is set to the default admin username "postgres", but the admin password field `.Values.postgresql.auth.postgresPassword` is not set, so a random password is generated and used. This wouldn't affect your usage, but if you choose to uninstall and reinstall this helm chart, please make sure you remove the existing PersistentVolumeClaim backing the in-cluster postgresql by running:
kubectl --namespace {{ .Release.Namespace }} delete pvc/data-{{ include "retool.fullname" . }}-postgresql-0
Expand Down
74 changes: 74 additions & 0 deletions charts/retool/templates/_telemetry_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{{/*
Reusable name for telemetry-related chart resources.
*/}}
{{- define "retool.telemetry.fullname" -}}
{{- $name := default "telemetry" .Values.telemetry.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Labels to include on telemetry pods.
*/}}
{{- define "retool.telemetry.labels" -}}
helm.sh/chart: {{ include "retool.chart" . }}
{{ include "retool.telemetry.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.Version | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Labels to use as selector for telemetry pods and deployment. Note these become
immutable once deployed, so changes here will require recreating the deployment.
*/}}
{{- define "retool.telemetry.selectorLabels" -}}
app.kubernetes.io/name: {{ default "telemetry" .Values.telemetry.nameOverride }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}


{{/*
The name of the service account to use.
*/}}
{{- define "retool.telemetry.serviceAccountName" -}}
{{- if .Values.telemetry.serviceAccount.create }}
{{- default (include "retool.telemetry.fullname" .) .Values.telemetry.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.telemetry.serviceAccount.name }}
{{- end }}
{{- end }}


{{/*
The labels to use for scoping log collection to only the pods in the same
release, as a single comma-separated string. The label(s) below should be
present on all relevant pods, or else logs won't be collected. */}}
{{- define "retool.telemetry.logSourcePodLabels" -}}
app.kubernetes.io/instance={{ .Release.Name }}
{{- end }}
{{/*
Env vars to include on retool pods to collect telemetry via telemetry pod.
*/}}
{{- define "retool.telemetry.includeEnvVars" -}}
{{- if .Values.telemetry.enabled }}
- name: RTEL_ENABLED
value: 'true'
- name: RTEL_SERVICE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.labels['telemetry.retool.com/service-name']
- name: K8S_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: K8S_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: STATSD_HOST
value: {{ printf "%s.%s" (include "retool.telemetry.fullname" .) .Release.Namespace | quote }}
- name: STATSD_PORT
value: "9125"
{{- end }}
{{- end }}
4 changes: 4 additions & 0 deletions charts/retool/templates/deployment_backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ spec:
- name: CODE_EXECUTOR_INGRESS_DOMAIN
value: http://{{ template "retool.codeExecutor.name" . }}
{{- end }}

{{- include "retool.telemetry.includeEnvVars" . | nindent 10 }}

{{- if and (not .Values.externalSecrets.enabled) (not .Values.externalSecrets.externalSecretsOperator.enabled) }}
- name: LICENSE_KEY
valueFrom:
Expand Down Expand Up @@ -245,6 +248,7 @@ spec:
port: {{ .Values.service.internalPort }}
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
Expand Down
3 changes: 3 additions & 0 deletions charts/retool/templates/deployment_code_executor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ spec:
value: production
- name: NODE_OPTIONS
value: {{(.Values.codeExecutor.config).nodeOptions | default "--max_old_space_size=1024" }}

{{- include "retool.telemetry.includeEnvVars" . | nindent 10 }}

{{- range $key, $value := .Values.env }}
- name: "{{ $key }}"
value: "{{ $value }}"
Expand Down
3 changes: 3 additions & 0 deletions charts/retool/templates/deployment_jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ spec:
value: {{ template "retool.postgresql.user" . }}
- name: POSTGRES_SSL_ENABLED
value: {{ template "retool.postgresql.ssl_enabled" . }}

{{- include "retool.telemetry.includeEnvVars" . | nindent 10 }}

{{- if and (not .Values.externalSecrets.enabled) (not .Values.externalSecrets.externalSecretsOperator.enabled) }}
- name: LICENSE_KEY
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions charts/retool/templates/deployment_workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ spec:
{{- end }}
{{- end }}
{{- end }}

{{- include "retool.telemetry.includeEnvVars" . | nindent 10 }}

- name: CLIENT_ID
value: {{ default "" .Values.config.auth.google.clientId }}
- name: COOKIE_INSECURE
Expand Down
3 changes: 3 additions & 0 deletions charts/retool/templates/deployment_workflows_worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ spec:
- name: CODE_EXECUTOR_INGRESS_DOMAIN
value: http://{{ template "retool.codeExecutor.name" . }}
{{- end }}

{{- include "retool.telemetry.includeEnvVars" . | nindent 10 }}

{{- if and (((.Values.workflows.config).otelCollector).enabled) (((.Values.workflows.config).otelCollector).endpoint) }}
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ ((.Values.workflows.config).otelCollector).endpoint }}
Expand Down
22 changes: 22 additions & 0 deletions charts/retool/templates/telemetry_configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- if .Values.telemetry.enabled }}

{{- if or .Values.telemetry.customVectorConfig .Values.telemetry.customGrafanaAgentConfig }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "retool.fullname" . }}-telemetry
labels:
{{- include "retool.telemetry.labels" . | nindent 4 }}
data:
{{- if .Values.telemetry.customVectorConfig }}
vector-custom.yaml: |
{{- tpl (toYaml .Values.telemetry.customVectorConfig) . | nindent 4 }}
{{- end }}
{{- if .Values.telemetry.customGrafanaAgentConfig }}
grafana-agent-custom.river: |
{{- .Values.telemetry.customGrafanaAgentConfig | nindent 4 }}
{{- end }}

{{- end }}

{{- end }}
158 changes: 158 additions & 0 deletions charts/retool/templates/telemetry_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{{- if .Values.telemetry.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "retool.fullname" . }}-telemetry
labels:
{{- include "retool.telemetry.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "retool.telemetry.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "retool.telemetry.selectorLabels" . | nindent 8 }}
annotations:
{{- if or .Values.telemetry.customVectorConfig .Values.telemetry.customGrafanaAgentConfig }}
checksum/custom-config: {{ include (print $.Template.BasePath "/telemetry_configmap.yaml") . | sha256sum | quote }}
{{- end }}
spec:
serviceAccountName: {{ include "retool.telemetry.serviceAccountName" . }}
containers:
- name: telemetry
image: '{{ .Values.telemetry.image.repository }}:{{ .Values.telemetry.image.tag | default .Values.image.tag }}'
imagePullPolicy: {{ .Values.telemetry.image.pullPolicy }}
command: ['retool-telemetry']
resources:
{{ toYaml .Values.telemetry.resources | nindent 10 }}
env:
- name: VECTOR_SELF_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: VECTOR_SELF_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: VECTOR_SELF_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: PROCFS_ROOT
value: "/host/proc"
- name: SYSFS_ROOT
value: "/host/sys"
{{- if and (not .Values.externalSecrets.enabled) (not .Values.externalSecrets.externalSecretsOperator.enabled) }}
- name: LICENSE_KEY
valueFrom:
secretKeyRef:
{{- if .Values.config.licenseKeySecretName }}
name: {{ .Values.config.licenseKeySecretName }}
key: {{ .Values.config.licenseKeySecretKey | default "license-key" }}
{{- else }}
name: {{ template "retool.fullname" . }}
key: license-key
{{- end }}
{{- end }}
- name: RTEL_DEPLOYMENT_MODE
value: 'kubernetes-helm'
- name: RTEL_HELM_RELEASE_NAME
value: {{ .Release.Name | quote }}
- name: RTEL_KUBE_POD_PREFIX
value: {{ include "retool.fullname" . | quote }}
- name: RTEL_KUBE_NAMESPACE
value: {{ .Release.Namespace | quote }}
- name: RTEL_KUBE_LABEL_SELECTOR
value: {{ include "retool.telemetry.logSourcePodLabels" . | quote }}
- name: RTEL_SEND_TO_RETOOL
value: {{ .Values.telemetry.sendToRetool.enabled | quote }}
{{- if .Values.externalSecrets.enabled }}
envFrom:
- secretRef:
name: {{ .Values.externalSecrets.name }}
{{- end }}
{{- if .Values.externalSecrets.externalSecretsOperator.enabled }}
envFrom:
{{- range .Values.externalSecrets.externalSecretsOperator.secretRef }}
- secretRef:
name: {{ .name }}
{{- end }}
{{- end }}
volumeMounts:
- name: vector-data
mountPath: {{ .Values.telemetry.customVectorConfig | dig "data_dir" "/vector-data" | quote }}
- name: grafana-agent-data
mountPath: /grafana-agent-data
{{- if .Values.telemetry.customVectorConfig }}
- name: custom-config
mountPath: "/etc/vector-custom/vector-custom.yaml"
subPath: "vector-custom.yaml"
readOnly: true
{{- end }}
{{- if .Values.telemetry.customGrafanaAgentConfig }}
- name: custom-config
mountPath: "/etc/grafana-agent-custom/grafana-agent-custom.river"
subPath: "grafana-agent-custom.river"
readOnly: true
{{- end }}
- name: var-log
mountPath: "/var/log/"
readOnly: true
- name: var-lib
mountPath: "/var/lib"
readOnly: true
- name: procfs
mountPath: "/host/proc"
readOnly: true
- name: sysfs
mountPath: "/host/sys"
readOnly: true
ports:
- containerPort: 9125
# hostPort: 9125
name: statsd-udp
protocol: UDP
volumes:
- name: vector-data
emptyDir:
sizeLimit: 100Mi
- name: grafana-agent-data
emptyDir:
sizeLimit: 100Mi
{{- if or .Values.telemetry.customVectorConfig .Values.telemetry.customGrafanaAgentConfig }}
- name: custom-config
configMap:
name: {{ include "retool.fullname" . }}-telemetry
{{- end }}
- name: var-log
hostPath:
path: "/var/log/"
- name: var-lib
hostPath:
path: "/var/lib/"
- name: procfs
hostPath:
path: "/proc"
- name: sysfs
hostPath:
path: "/sys"

---
apiVersion: v1
kind: Service
metadata:
name: {{ include "retool.telemetry.fullname" . }}
labels:
{{- include "retool.telemetry.labels" . | nindent 4 }}
spec:
ports:
- name: statsd-udp
port: 9125
protocol: UDP
selector:
{{- include "retool.telemetry.selectorLabels" . | nindent 4 }}
type: ClusterIP


{{- end }}
Loading

0 comments on commit 6c9566f

Please sign in to comment.