From ee806f078b0b7a065b6dd92452731dc0bd469da6 Mon Sep 17 00:00:00 2001 From: Charlie Holland Date: Fri, 14 Nov 2025 12:04:32 +0000 Subject: [PATCH 1/4] feat: add init container to web deployment for database migrations - Add init container to handle database migrations and initialization - Prevents health check timeouts by separating initialization from web serving - Init container runs the full entrypoint script then exits cleanly - Preserves existing extraInitContainers functionality - Add comprehensive test coverage for init container functionality Resolves startup issues where health checks were failing due to time-consuming database migrations running in the main container. --- charts/langfuse/templates/web/deployment.yaml | 21 ++++- .../langfuse/tests/init-container_test.yaml | 83 +++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 charts/langfuse/tests/init-container_test.yaml diff --git a/charts/langfuse/templates/web/deployment.yaml b/charts/langfuse/templates/web/deployment.yaml index b86ae9ff..89534c42 100644 --- a/charts/langfuse/templates/web/deployment.yaml +++ b/charts/langfuse/templates/web/deployment.yaml @@ -51,10 +51,27 @@ spec: serviceAccountName: {{ include "langfuse.serviceAccountName" . }} securityContext: {{- toYaml .Values.langfuse.podSecurityContext | nindent 8 }} - {{- if .Values.langfuse.extraInitContainers }} initContainers: + - name: {{ .Chart.Name }}-web-init + securityContext: + {{- toYaml .Values.langfuse.securityContext | nindent 12 }} + image: "{{ .Values.langfuse.web.image.repository }}:{{ coalesce .Values.langfuse.web.image.tag .Values.langfuse.image.tag .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.langfuse.web.image.pullPolicy | default .Values.langfuse.image.pullPolicy }} + # Run the full entrypoint script for initialization (DB setup, migrations, etc.) then exit + command: ["echo", "Init completed successfully"] + env: + {{- include "langfuse.commonEnv" . | nindent 12 }} + {{- $additionalEnv := concat (.Values.langfuse.additionalEnv | default list ) (.Values.langfuse.web.pod.additionalEnv | default list )}} + {{- with $additionalEnv }} + {{- toYaml . | nindent 12 }} + {{- end }} + {{- if .Values.langfuse.extraVolumeMounts }} + volumeMounts: + {{- toYaml .Values.langfuse.extraVolumeMounts | nindent 12 }} + {{- end }} + {{- if .Values.langfuse.extraInitContainers }} {{- toYaml .Values.langfuse.extraInitContainers | nindent 8 }} - {{- end }} + {{- end }} {{- if .Values.langfuse.extraVolumes }} volumes: {{- toYaml .Values.langfuse.extraVolumes | nindent 8 }} diff --git a/charts/langfuse/tests/init-container_test.yaml b/charts/langfuse/tests/init-container_test.yaml new file mode 100644 index 00000000..0e6e8c5f --- /dev/null +++ b/charts/langfuse/tests/init-container_test.yaml @@ -0,0 +1,83 @@ +suite: test init container functionality +templates: + - web/deployment.yaml +tests: + - it: should have init container with correct configuration + values: + - ../values.lint.yaml + asserts: + # Test that web deployment has init containers + - hasDocuments: + count: 1 + template: web/deployment.yaml + - isKind: + of: Deployment + template: web/deployment.yaml + + # Test that init container exists + - exists: + path: spec.template.spec.initContainers + template: web/deployment.yaml + + # Test init container count (should have at least 1) + - isNotEmpty: + path: spec.template.spec.initContainers + template: web/deployment.yaml + + # Test init container name + - equal: + path: spec.template.spec.initContainers[0].name + value: langfuse-web-init + template: web/deployment.yaml + + # Test init container uses same image as main container + - equal: + path: spec.template.spec.initContainers[0].image + value: "langfuse/langfuse:3.129.0" + template: web/deployment.yaml + + # Test init container has command that runs initialization and exits + - equal: + path: spec.template.spec.initContainers[0].command + value: ["echo", "Init completed successfully"] + template: web/deployment.yaml + + # Test init container has environment variables + - exists: + path: spec.template.spec.initContainers[0].env + template: web/deployment.yaml + + # Test that NODE_ENV is set in init container + - contains: + path: spec.template.spec.initContainers[0].env + content: + name: NODE_ENV + value: "production" + template: web/deployment.yaml + + - it: should preserve existing extraInitContainers functionality + values: + - ../values.lint.yaml + set: + langfuse.extraInitContainers: + - name: custom-init + image: busybox + command: ["echo", "custom init"] + asserts: + # Should have 2 init containers (our default + custom) + - lengthEqual: + path: spec.template.spec.initContainers + count: 2 + template: web/deployment.yaml + + # First should be our web-init container + - equal: + path: spec.template.spec.initContainers[0].name + value: langfuse-web-init + template: web/deployment.yaml + + # Second should be the custom init container + - equal: + path: spec.template.spec.initContainers[1].name + value: custom-init + template: web/deployment.yaml \ No newline at end of file From 7c73e43f88b25359366dea95a2f586644df4942c Mon Sep 17 00:00:00 2001 From: Charlie Holland Date: Fri, 14 Nov 2025 12:25:15 +0000 Subject: [PATCH 2/4] fix: use args instead of command for init container - Changed from 'command' to 'args' to allow entrypoint script to run - This ensures the full initialization logic executes properly - The entrypoint script handles environment setup, DB migrations, etc. - Container exits cleanly after running 'echo Init completed successfully' --- charts/langfuse/templates/web/deployment.yaml | 4 ++-- charts/langfuse/tests/init-container_test.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/charts/langfuse/templates/web/deployment.yaml b/charts/langfuse/templates/web/deployment.yaml index 89534c42..9852bc18 100644 --- a/charts/langfuse/templates/web/deployment.yaml +++ b/charts/langfuse/templates/web/deployment.yaml @@ -57,8 +57,8 @@ spec: {{- toYaml .Values.langfuse.securityContext | nindent 12 }} image: "{{ .Values.langfuse.web.image.repository }}:{{ coalesce .Values.langfuse.web.image.tag .Values.langfuse.image.tag .Chart.AppVersion }}" imagePullPolicy: {{ .Values.langfuse.web.image.pullPolicy | default .Values.langfuse.image.pullPolicy }} - # Run the full entrypoint script for initialization (DB setup, migrations, etc.) then exit - command: ["echo", "Init completed successfully"] + # Run the entrypoint script with a command that exits after initialization + args: ["echo", "Init completed successfully"] env: {{- include "langfuse.commonEnv" . | nindent 12 }} {{- $additionalEnv := concat (.Values.langfuse.additionalEnv | default list ) (.Values.langfuse.web.pod.additionalEnv | default list )}} diff --git a/charts/langfuse/tests/init-container_test.yaml b/charts/langfuse/tests/init-container_test.yaml index 0e6e8c5f..bc34ab56 100644 --- a/charts/langfuse/tests/init-container_test.yaml +++ b/charts/langfuse/tests/init-container_test.yaml @@ -36,9 +36,9 @@ tests: value: "langfuse/langfuse:3.129.0" template: web/deployment.yaml - # Test init container has command that runs initialization and exits + # Test init container has args that runs initialization and exits - equal: - path: spec.template.spec.initContainers[0].command + path: spec.template.spec.initContainers[0].args value: ["echo", "Init completed successfully"] template: web/deployment.yaml From 23fd646e28d58a9f8ffc129e540cf3851187c53a Mon Sep 17 00:00:00 2001 From: Charlie Holland Date: Fri, 14 Nov 2025 14:21:29 +0000 Subject: [PATCH 3/4] fix: increase liveness probe initial delay to 60s - Update default initialDelaySeconds from 20s to 60s in both values.yaml and deployment template - Gives main container more time to start after init container completes - Prevents premature health check failures during startup --- charts/langfuse/templates/web/deployment.yaml | 2 +- charts/langfuse/values.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/langfuse/templates/web/deployment.yaml b/charts/langfuse/templates/web/deployment.yaml index 9852bc18..41fdaae7 100644 --- a/charts/langfuse/templates/web/deployment.yaml +++ b/charts/langfuse/templates/web/deployment.yaml @@ -104,7 +104,7 @@ spec: httpGet: path: {{ .Values.langfuse.web.livenessProbe.path | default "/api/public/health" }} port: http - initialDelaySeconds: {{ .Values.langfuse.web.livenessProbe.initialDelaySeconds | default 20 }} + initialDelaySeconds: {{ .Values.langfuse.web.livenessProbe.initialDelaySeconds | default 60 }} periodSeconds: {{ .Values.langfuse.web.livenessProbe.periodSeconds | default 10 }} timeoutSeconds: {{ .Values.langfuse.web.livenessProbe.timeoutSeconds | default 5 }} successThreshold: {{ .Values.langfuse.web.livenessProbe.successThreshold | default 1 }} diff --git a/charts/langfuse/values.yaml b/charts/langfuse/values.yaml index 58bb13c2..d104c03d 100644 --- a/charts/langfuse/values.yaml +++ b/charts/langfuse/values.yaml @@ -262,7 +262,7 @@ langfuse: # -- Path to check for liveness. path: "/api/public/health" # -- Initial delay seconds for livenessProbe. - initialDelaySeconds: 20 + initialDelaySeconds: 60 # -- Period seconds for livenessProbe. periodSeconds: 10 # -- Timeout seconds for livenessProbe. From 552cdf1bfcb4eceac7702199300abd53cb2d536f Mon Sep 17 00:00:00 2001 From: Charlie Holland Date: Fri, 14 Nov 2025 14:34:21 +0000 Subject: [PATCH 4/4] docs: update chart documentation for liveness probe changes - Auto-generated documentation using helm-docs - Reflects updated initialDelaySeconds from 20s to 60s --- charts/langfuse/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/langfuse/README.md b/charts/langfuse/README.md index 1bf60b9d..d13389bf 100644 --- a/charts/langfuse/README.md +++ b/charts/langfuse/README.md @@ -118,7 +118,7 @@ Open source LLM engineering platform - LLM observability, metrics, evaluations, | langfuse.web.keda.triggerType | string | `"cpu"` | The trigger type for scaling (cpu or memory) | | langfuse.web.keda.value | string | `"50"` | The target utilization percentage for the langfuse web pods | | langfuse.web.livenessProbe.failureThreshold | int | `3` | Failure threshold for livenessProbe. | -| langfuse.web.livenessProbe.initialDelaySeconds | int | `20` | Initial delay seconds for livenessProbe. | +| langfuse.web.livenessProbe.initialDelaySeconds | int | `60` | Initial delay seconds for livenessProbe. | | langfuse.web.livenessProbe.path | string | `"/api/public/health"` | Path to check for liveness. | | langfuse.web.livenessProbe.periodSeconds | int | `10` | Period seconds for livenessProbe. | | langfuse.web.livenessProbe.successThreshold | int | `1` | Success threshold for livenessProbe. |