Skip to content
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

feat(jobs): Add job to migrate analytics data from influx to postgres #230

Merged
merged 8 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/flagsmith/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: flagsmith
description: Flagsmith
type: application
version: 0.65.0
version: 0.66.0
appVersion: 2.159.0
dependencies:
- name: postgresql
Expand Down
8 changes: 3 additions & 5 deletions charts/flagsmith/ci/e2e-test-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ frontend:
SLACK_TOKEN: "${SLACK_TOKEN}"

api:
analytics:
enabled: true
extraEnv:
EMAIL_BACKEND: 'django.core.mail.backends.console.EmailBackend'
EMAIL_BACKEND: "django.core.mail.backends.console.EmailBackend"
FE_E2E_TEST_USER_EMAIL: [email protected]
influxdb2:
# Needed to set this for the tests to not fail. Possibly related to
# https://github.com/Flagsmith/flagsmith/issues/340
enabled: false
11 changes: 0 additions & 11 deletions charts/flagsmith/ci/influxdb-test-values.yaml

This file was deleted.

11 changes: 11 additions & 0 deletions charts/flagsmith/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ generate a large random value, store it in a secret, and set the following value
See https://docs.flagsmith.com/deployment/locally-api#creating-a-secret-key
{{- end }}

{{- if .Values.influxdb2.enabled }}

######################################
##### Warning: influxdb2 #####
######################################

InfluxDB2 is deprecated and will be removed in the next major version.
Please set values under the `influxdbExternal` key
or migrate your analytics data to PostgreSQL by enabling `jobs.migrateAnalytics`.
{{- end }}

--------------------------------------
9 changes: 9 additions & 0 deletions charts/flagsmith/templates/_api_environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
name: {{ template "flagsmith.influxdb.fullname" . }}-external-auth
key: admin-token
{{- end }}
{{- else if .Values.UsePostgresForAnalytics.enabled }}
{{- if not .Values.taskProcessor.enabled }}
{{ fail "To use PostgreSQL for analytics, `taskProcessor.enabled` should be set to `true`" }}
{{- end}}
- name: USE_POSTGRES_FOR_ANALYTICS
value: 'true'
{{- else }}
- name: DISABLE_ANALYTICS_FEATURES
value: 'true'
{{- end }}
- name: DJANGO_ALLOWED_HOSTS
value: '*'
Expand Down
39 changes: 39 additions & 0 deletions charts/flagsmith/templates/jobs-migrate-analytics-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- if .Values.jobs.migrateAnalyticsData.enabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "flagsmith.fullname" . }}-migrate-analytics-data-{{ .Release.Revision }}-{{ randAlphaNum 5 | lower }}
{{- $annotations := include "flagsmith.annotations" .Values.common }}
{{- with $annotations }}
annotations:
{{- . | nindent 4 }}
{{- end }}
labels:
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: job-migrate-analytics-data
spec:
template:
spec:
restartPolicy: Never
{{- if .Values.jobs.migrateDb.serviceAccountName }}
serviceAccountName: {{ .Values.jobs.migrateDb.serviceAccountName }}
{{- end }}
{{- if .Values.jobs.migrateDb.shareProcessNamespace }}
{{- end }}
shareProcessNamespace: true
containers:
- name: migrate-analytics-data
image: {{ .Values.api.image.repository }}:{{ .Values.api.image.tag | default (printf "%s" .Chart.AppVersion) }}
command: ["python","manage.py", "migrate_analytics"]
{{- if .Values.jobs.migrateAnalyticsData.args }}
args: {{ toYaml .Values.jobs.migrateAnalyticsData.args | nindent 8 }}
{{- end }}
env: {{ include (print $.Template.BasePath "/_api_environment.yaml") . | nindent 8 }}
{{- with .Values.jobs.migrateDb.extraContainers }}
{{- toYaml . | nindent 6 }}
{{- end }}
volumes:
{{- with .Values.jobs.migrateDb.extraVolumes }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end -}}
8 changes: 8 additions & 0 deletions charts/flagsmith/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ influxdbExternal:
name: null
key: null

UsePostgresForAnalytics:
enabled: false

# This is included primarily for easy testing of statsd integration from the application.
graphite:
enabled: false
Expand Down Expand Up @@ -426,6 +429,11 @@ jobs:
extraVolumes: []
command: []
args: []
migrateAnalyticsData:
enabled: false
args: []
extraContainers: []
extraVolumes: []

# These tests just make non-destructive requests to the services in
# the cluster. Enabling this and running helm test is safe.
Expand Down
Loading