From 534804ab0d4208dcdde6cfd82269448f3a42c04b Mon Sep 17 00:00:00 2001 From: nicktrn <55853254+nicktrn@users.noreply.github.com> Date: Tue, 24 Jun 2025 00:06:21 +0100 Subject: [PATCH] improve clickhouse config improve clickhouse config --- hosting/k8s/helm/templates/clickhouse.yaml | 23 +++++++++--- hosting/k8s/helm/templates/configmap.yaml | 2 +- .../helm/templates/tests/test-clickhouse.yaml | 4 +- hosting/k8s/helm/templates/webapp.yaml | 14 +++++++ .../k8s/helm/values-production-example.yaml | 13 ------- hosting/k8s/helm/values.yaml | 37 +++++++++++-------- 6 files changed, 56 insertions(+), 37 deletions(-) diff --git a/hosting/k8s/helm/templates/clickhouse.yaml b/hosting/k8s/helm/templates/clickhouse.yaml index 8b2fd4d0f..bd9097e54 100644 --- a/hosting/k8s/helm/templates/clickhouse.yaml +++ b/hosting/k8s/helm/templates/clickhouse.yaml @@ -1,4 +1,4 @@ -{{- if .Values.clickhouse.enabled }} +{{- if and .Values.clickhouse.enabled (not .Values.clickhouse.external) }} apiVersion: apps/v1 kind: StatefulSet metadata: @@ -34,8 +34,11 @@ spec: image: "{{ .Values.clickhouse.image.registry }}/{{ .Values.clickhouse.image.repository }}:{{ .Values.clickhouse.image.tag }}" imagePullPolicy: {{ .Values.clickhouse.image.pullPolicy }} ports: + - name: native + containerPort: {{ .Values.clickhouse.service.ports.native }} + protocol: TCP - name: http - containerPort: {{ .Values.clickhouse.service.targetPort }} + containerPort: {{ .Values.clickhouse.service.ports.http }} protocol: TCP env: - name: CLICKHOUSE_ADMIN_USER @@ -52,7 +55,7 @@ spec: - --host - localhost - --port - - "9000" + - {{ .Values.clickhouse.service.ports.native | quote }} - --user - {{ .Values.clickhouse.auth.adminUser }} - --password @@ -70,7 +73,7 @@ spec: - --host - localhost - --port - - "9000" + - {{ .Values.clickhouse.service.ports.native | quote }} - --user - {{ .Values.clickhouse.auth.adminUser }} - --password @@ -128,8 +131,12 @@ spec: type: ClusterIP clusterIP: None ports: + - name: native + port: {{ .Values.clickhouse.service.ports.native }} + targetPort: native + protocol: TCP - name: http - port: {{ .Values.clickhouse.service.port }} + port: {{ .Values.clickhouse.service.ports.http }} targetPort: http protocol: TCP selector: @@ -145,8 +152,12 @@ metadata: spec: type: {{ .Values.clickhouse.service.type }} ports: + - name: native + port: {{ .Values.clickhouse.service.ports.native }} + targetPort: native + protocol: TCP - name: http - port: {{ .Values.clickhouse.service.port }} + port: {{ .Values.clickhouse.service.ports.http }} targetPort: http protocol: TCP selector: diff --git a/hosting/k8s/helm/templates/configmap.yaml b/hosting/k8s/helm/templates/configmap.yaml index 133fef6de..5ae518d70 100644 --- a/hosting/k8s/helm/templates/configmap.yaml +++ b/hosting/k8s/helm/templates/configmap.yaml @@ -1,4 +1,4 @@ -{{- if .Values.clickhouse.enabled }} +{{- if and .Values.clickhouse.enabled (not .Values.clickhouse.external) }} apiVersion: v1 kind: ConfigMap metadata: diff --git a/hosting/k8s/helm/templates/tests/test-clickhouse.yaml b/hosting/k8s/helm/templates/tests/test-clickhouse.yaml index 8f44f4ff4..30cc37f0b 100644 --- a/hosting/k8s/helm/templates/tests/test-clickhouse.yaml +++ b/hosting/k8s/helm/templates/tests/test-clickhouse.yaml @@ -1,4 +1,4 @@ -{{- if .Values.clickhouse.enabled }} +{{- if and .Values.clickhouse.enabled (not .Values.clickhouse.external) }} apiVersion: v1 kind: Pod metadata: @@ -16,6 +16,6 @@ spec: args: - | echo "Testing ClickHouse HTTP interface..." - curl -f "http://{{ .Values.clickhouse.auth.adminUser }}:{{ .Values.clickhouse.auth.adminPassword }}@{{ include "trigger-v4.fullname" . }}-clickhouse:{{ .Values.clickhouse.service.port }}/ping" + curl -f "http://{{ .Values.clickhouse.auth.adminUser }}:{{ .Values.clickhouse.auth.adminPassword }}@{{ include "trigger-v4.fullname" . }}-clickhouse:{{ .Values.clickhouse.service.ports.http }}/ping" echo "ClickHouse test completed successfully" {{- end }} \ No newline at end of file diff --git a/hosting/k8s/helm/templates/webapp.yaml b/hosting/k8s/helm/templates/webapp.yaml index a47873f5b..72f5eb0ed 100644 --- a/hosting/k8s/helm/templates/webapp.yaml +++ b/hosting/k8s/helm/templates/webapp.yaml @@ -187,6 +187,20 @@ spec: value: {{ .Values.webapp.internal.otel.metric.exporterEnabled | quote }} - name: INTERNAL_OTEL_METRIC_EXPORTER_INTERVAL_MS value: {{ .Values.webapp.internal.otel.metric.exporterIntervalMs | quote }} + {{- if .Values.webapp.clickhouse.enabled }} + - name: CLICKHOUSE_URL + value: {{ if .Values.clickhouse.external }}{{ .Values.clickhouse.externalConnection.httpUrl | quote }}{{ else }}"http://{{ .Values.clickhouse.auth.adminUser }}:{{ .Values.clickhouse.auth.adminPassword }}@{{ include "trigger-v4.fullname" . }}-clickhouse:{{ .Values.clickhouse.service.ports.http }}"{{ end }} + - name: CLICKHOUSE_LOG_LEVEL + value: {{ .Values.webapp.clickhouse.logLevel | quote }} + {{- end }} + {{- if .Values.webapp.runReplication.enabled }} + - name: RUN_REPLICATION_ENABLED + value: "1" + - name: RUN_REPLICATION_CLICKHOUSE_URL + value: {{ if .Values.clickhouse.external }}{{ .Values.clickhouse.externalConnection.httpUrl | quote }}{{ else }}"http://{{ .Values.clickhouse.auth.adminUser }}:{{ .Values.clickhouse.auth.adminPassword }}@{{ include "trigger-v4.fullname" . }}-clickhouse:{{ .Values.clickhouse.service.ports.http }}"{{ end }} + - name: RUN_REPLICATION_LOG_LEVEL + value: {{ .Values.webapp.runReplication.logLevel | quote }} + {{- end }} {{- with .Values.webapp.extraEnv }} {{- toYaml . | nindent 12 }} {{- end }} diff --git a/hosting/k8s/helm/values-production-example.yaml b/hosting/k8s/helm/values-production-example.yaml index 2236cf5ae..f286c4220 100644 --- a/hosting/k8s/helm/values-production-example.yaml +++ b/hosting/k8s/helm/values-production-example.yaml @@ -46,19 +46,6 @@ webapp: requests: cpu: 1000m memory: 2Gi - # ClickHouse configuration (experimental) - extraEnv: - [] - # - name: RUN_REPLICATION_CLICKHOUSE_URL - # value: "http://clickhouse:9000" - # - name: RUN_REPLICATION_ENABLED - # value: "1" - # - name: RUN_REPLICATION_LOG_LEVEL - # value: "info" - # - name: CLICKHOUSE_URL - # value: "http://clickhouse:9000" - # - name: CLICKHOUSE_LOG_LEVEL - # value: "info" # Production PostgreSQL (or use external) postgres: diff --git a/hosting/k8s/helm/values.yaml b/hosting/k8s/helm/values.yaml index 8c59f03e5..f757f0764 100644 --- a/hosting/k8s/helm/values.yaml +++ b/hosting/k8s/helm/values.yaml @@ -95,17 +95,6 @@ webapp: # secretKeyRef: # name: my-secret # key: secret-key - # ClickHouse configuration (experimental) - # - name: RUN_REPLICATION_CLICKHOUSE_URL - # value: "http://clickhouse:9000" - # - name: RUN_REPLICATION_ENABLED - # value: "0" - # - name: RUN_REPLICATION_LOG_LEVEL - # value: "info" - # - name: CLICKHOUSE_URL - # value: "http://clickhouse:9000" - # - name: CLICKHOUSE_LOG_LEVEL - # value: "info" # ServiceMonitor for Prometheus monitoring serviceMonitor: @@ -115,6 +104,18 @@ webapp: labels: {} basicAuth: {} + # ClickHouse integration (experimental) + # Usage patterns: + # 1. Internal ClickHouse: Set clickhouse.enabled=true, clickhouse.external=false, webapp.clickhouse.enabled=true + # 2. External ClickHouse: Set clickhouse.enabled=true, clickhouse.external=true, configure externalConnection URLs, webapp.clickhouse.enabled=true + # 3. No ClickHouse: Leave webapp.clickhouse.enabled=false (default) + clickhouse: + enabled: true + logLevel: "info" # one of: log, error, warn, info, debug + runReplication: + enabled: true + logLevel: "info" # one of: log, error, warn, info, debug + # OpenTelemetry configuration internal: otel: @@ -152,13 +153,13 @@ secrets: # If empty, a secret will be created with the values below # The secret must contain the following keys: # - session-secret - # - magic-link-secret + # - magic-link-secret # - encryption-key # - managed-worker-secret # - object-store-access-key-id # - object-store-secret-access-key existingSecret: "" - + # Session secret for user authentication (32 hex chars) sessionSecret: "2818143646516f6fffd707b36f334bbb" # Magic link secret for passwordless login (32 hex chars) @@ -301,6 +302,7 @@ electric: # ClickHouse configuration clickhouse: enabled: true + external: false image: registry: docker.io repository: bitnami/clickhouse @@ -324,9 +326,14 @@ clickhouse: size: 10Gi service: type: ClusterIP - port: 9000 - targetPort: 9000 + ports: + native: 9000 + http: 8123 resources: {} + # External ClickHouse connection (when external: true) + externalConnection: + # HTTP interface URL (port 8123) - used by webapp for replication + httpUrl: "" # Extra environment variables for ClickHouse extraEnv: []