-
Notifications
You must be signed in to change notification settings - Fork 8
feat (chart): add Langfuse retention management with ClickHouse TTL and hard delete #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
infrastructure/rag/templates/langfuse-retention-cronjob.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| {{- if and .Values.features.langfuse.enabled .Values.langfuseRetention.enabled }} | ||
| {{- $retentionImage := printf "%s:%s" .Values.langfuseRetention.image.repository .Values.langfuseRetention.image.tag -}} | ||
| apiVersion: batch/v1 | ||
| kind: CronJob | ||
| metadata: | ||
| name: {{ printf "%s-langfuse-retention" .Release.Name | trunc 63 | trimSuffix "-" }} | ||
| labels: | ||
| app.kubernetes.io/name: rag | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| spec: | ||
| schedule: {{ .Values.langfuseRetention.schedule | quote }} | ||
| concurrencyPolicy: Forbid | ||
| successfulJobsHistoryLimit: 1 | ||
| failedJobsHistoryLimit: 3 | ||
| jobTemplate: | ||
| spec: | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app.kubernetes.io/name: rag | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| spec: | ||
| restartPolicy: OnFailure | ||
|
a-klos marked this conversation as resolved.
|
||
| containers: | ||
| - name: apply-clickhouse-ttl | ||
| image: {{ $retentionImage | quote }} | ||
|
a-klos marked this conversation as resolved.
|
||
| imagePullPolicy: {{ .Values.langfuseRetention.image.pullPolicy | quote }} | ||
| command: | ||
| - /bin/bash | ||
| - -ec | ||
| args: | ||
| - | | ||
| set -euo pipefail | ||
|
|
||
| PASSWORD="${CLICKHOUSE_PASSWORD:-}" | ||
| if [ -z "${PASSWORD}" ]; then | ||
| PASSWORD="${CLICKHOUSE_PASSWORD_LITERAL:-}" | ||
| fi | ||
|
|
||
| if [ -z "${PASSWORD}" ]; then | ||
| echo "No ClickHouse password found. Check langfuse.clickhouse.auth settings and secret." | ||
| exit 1 | ||
| fi | ||
|
|
||
| ON_CLUSTER_CLAUSE="" | ||
| if [ "${CLICKHOUSE_ON_CLUSTER}" = "true" ]; then | ||
| ON_CLUSTER_CLAUSE=" ON CLUSTER ${CLICKHOUSE_CLUSTER_NAME}" | ||
| fi | ||
|
|
||
| TABLE_ROWS="$(cat <<'EOF_TABLES' | ||
| {{- range .Values.langfuseRetention.clickhouse.tables }} | ||
| {{ .name }} {{ .timestampColumn }} | ||
| {{- end }} | ||
| EOF_TABLES | ||
| )" | ||
|
|
||
| while IFS=$'\t' read -r table ts_col; do | ||
| [ -z "${table}" ] && continue | ||
|
|
||
| echo "Applying TTL=${RETENTION_DAYS}d to ${CLICKHOUSE_DATABASE}.${table} (${ts_col})" | ||
| clickhouse-client \ | ||
| --host "${CLICKHOUSE_HOST}" \ | ||
| --port "${CLICKHOUSE_PORT}" \ | ||
| --user "${CLICKHOUSE_USER}" \ | ||
| --password "${PASSWORD}" \ | ||
|
a-klos marked this conversation as resolved.
Outdated
|
||
| --query "ALTER TABLE ${CLICKHOUSE_DATABASE}.${table}${ON_CLUSTER_CLAUSE} MODIFY TTL toDateTime(${ts_col}) + toIntervalDay(${RETENTION_DAYS})" | ||
|
a-klos marked this conversation as resolved.
Outdated
a-klos marked this conversation as resolved.
Outdated
a-klos marked this conversation as resolved.
Outdated
|
||
| done <<< "${TABLE_ROWS}" | ||
|
a-klos marked this conversation as resolved.
|
||
| env: | ||
| {{ include "rag.langfuseRetentionClickhouseEnv" . | nindent 16 }} | ||
| {{- end }} | ||
|
a-klos marked this conversation as resolved.
|
||
74 changes: 74 additions & 0 deletions
74
infrastructure/rag/templates/langfuse-retention-hard-delete-cronjob.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| {{- if and .Values.features.langfuse.enabled .Values.langfuseRetention.hardDelete.enabled }} | ||
|
a-klos marked this conversation as resolved.
|
||
| {{- $retentionImage := printf "%s:%s" .Values.langfuseRetention.image.repository .Values.langfuseRetention.image.tag -}} | ||
| apiVersion: batch/v1 | ||
| kind: CronJob | ||
| metadata: | ||
| name: {{ printf "%s-langfuse-retention-delete" .Release.Name | trunc 63 | trimSuffix "-" }} | ||
| labels: | ||
| app.kubernetes.io/name: rag | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| spec: | ||
| schedule: {{ .Values.langfuseRetention.hardDelete.schedule | quote }} | ||
| concurrencyPolicy: Forbid | ||
| successfulJobsHistoryLimit: 1 | ||
| failedJobsHistoryLimit: 3 | ||
| jobTemplate: | ||
| spec: | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app.kubernetes.io/name: rag | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| spec: | ||
| restartPolicy: OnFailure | ||
|
a-klos marked this conversation as resolved.
|
||
| containers: | ||
| - name: delete-expired-rows | ||
| image: {{ $retentionImage | quote }} | ||
|
a-klos marked this conversation as resolved.
|
||
| imagePullPolicy: {{ .Values.langfuseRetention.image.pullPolicy | quote }} | ||
| command: | ||
| - /bin/bash | ||
| - -ec | ||
| args: | ||
| - | | ||
| set -euo pipefail | ||
|
|
||
| PASSWORD="${CLICKHOUSE_PASSWORD:-}" | ||
| if [ -z "${PASSWORD}" ]; then | ||
| PASSWORD="${CLICKHOUSE_PASSWORD_LITERAL:-}" | ||
| fi | ||
|
|
||
| if [ -z "${PASSWORD}" ]; then | ||
| echo "No ClickHouse password found. Check langfuse.clickhouse.auth settings and secret." | ||
| exit 1 | ||
| fi | ||
|
|
||
| ON_CLUSTER_CLAUSE="" | ||
| if [ "${CLICKHOUSE_ON_CLUSTER}" = "true" ]; then | ||
| ON_CLUSTER_CLAUSE=" ON CLUSTER ${CLICKHOUSE_CLUSTER_NAME}" | ||
| fi | ||
|
|
||
| TABLE_ROWS="$(cat <<'EOF_TABLES' | ||
| {{- range .Values.langfuseRetention.clickhouse.tables }} | ||
| {{ .name }} {{ .timestampColumn }} | ||
| {{- end }} | ||
| EOF_TABLES | ||
| )" | ||
|
|
||
| CUTOFF_UNIX="$(( $(date -u +%s) - RETENTION_DAYS * 86400 ))" | ||
|
|
||
| while IFS=$'\t' read -r table ts_col; do | ||
| [ -z "${table}" ] && continue | ||
|
|
||
| echo "Deleting rows older than ${RETENTION_DAYS}d from ${CLICKHOUSE_DATABASE}.${table} (${ts_col})" | ||
| clickhouse-client \ | ||
| --host "${CLICKHOUSE_HOST}" \ | ||
| --port "${CLICKHOUSE_PORT}" \ | ||
| --user "${CLICKHOUSE_USER}" \ | ||
| --password "${PASSWORD}" \ | ||
|
a-klos marked this conversation as resolved.
Outdated
|
||
| --query "ALTER TABLE ${CLICKHOUSE_DATABASE}.${table}${ON_CLUSTER_CLAUSE} DELETE WHERE toDateTime(${ts_col}) < toDateTime(${CUTOFF_UNIX}) SETTINGS mutations_sync = ${MUTATION_SYNC}" | ||
|
a-klos marked this conversation as resolved.
Outdated
a-klos marked this conversation as resolved.
Outdated
a-klos marked this conversation as resolved.
Outdated
|
||
| done <<< "${TABLE_ROWS}" | ||
| env: | ||
| - name: MUTATION_SYNC | ||
| value: {{ .Values.langfuseRetention.hardDelete.mutationSync | quote }} | ||
| {{ include "rag.langfuseRetentionClickhouseEnv" . | nindent 16 }} | ||
|
a-klos marked this conversation as resolved.
|
||
| {{- end }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.