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: reintroduce "Extend Redis functionality" #1492

Merged
merged 19 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6307a8f
feat: extend Redis functionality
frank-m Jun 20, 2023
32b4476
fix: resolve cherry-pick conflict
nadecancode Sep 29, 2024
6727be1
fix: address linting
nadecancode Sep 29, 2024
06885da
fix: make relay respect externalRedis.existingSecret
nadecancode Sep 29, 2024
b894352
style: space between `quote` and pipe
nadecancode Sep 29, 2024
274d1ea
fix: correct redis url in relay config
nadecancode Sep 29, 2024
0938565
fix: don't generate redis secret reference if password and existingSe…
nadecancode Sep 29, 2024
70d0f48
fix: don't generate redis secret reference if password and existingSe…
nadecancode Sep 29, 2024
13aff46
fix: respect subchart's secret path to be consistent with generated s…
nadecancode Sep 29, 2024
6b7ed50
fix: don't render password if plain text password is empty
nadecancode Sep 29, 2024
2ecaaed
fix: improve password rendering
nadecancode Sep 30, 2024
7adbcc3
fix: respect original snuba redis database value
nadecancode Sep 30, 2024
c5fd21e
fix: correct more password rendering
nadecancode Sep 30, 2024
bbd6dbd
fix: `sentry.redis.password` should not return any value if neither p…
nadecancode Sep 30, 2024
105929a
fix: Fix `SENTRY_SSL` being rendered as non-python value
nadecancode Sep 30, 2024
e20c274
fix: remove the need to specify brokerUrl in values if using Redis
nadecancode Sep 30, 2024
0db2375
fix: remove the brokerUrl reference
nadecancode Sep 30, 2024
0cf4e59
fix: move redis variables to correct location
nadecancode Sep 30, 2024
4b8647e
fix: remove comments
nadecancode Sep 30, 2024
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
96 changes: 93 additions & 3 deletions charts/sentry/templates/_helper.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,37 @@ Set redis port
Set redis password
*/}}
{{- define "sentry.redis.password" -}}
{{- if and (.Values.redis.enabled) (.Values.redis.auth.enabled) -}}
{{ .Values.redis.auth.password }}
{{- else if .Values.externalRedis.password -}}
{{ .Values.externalRedis.password }}
{{- else }}
{{- end -}}
{{- end -}}

{{/*
Set redis db
*/}}
{{- define "sentry.redis.db" -}}
{{- if .Values.redis.enabled -}}
{{ .Values.redis.password }}
{{ default 0 .Values.redis.db }}
{{- else -}}
{{ .Values.externalRedis.password }}
{{ default 0 .Values.externalRedis.db }}
{{- end -}}
{{- end -}}

{{/*
Set redis ssl
*/}}
{{- define "sentry.redis.ssl" -}}
{{- if .Values.redis.enabled -}}
{{ default false .Values.redis.ssl }}
{{- else -}}
{{ default false .Values.externalRedis.ssl }}
{{- end -}}
{{- end -}}


{{/*
Create the name of the service account to use
*/}}
Expand Down Expand Up @@ -454,6 +478,27 @@ Common Snuba environment variables
value: /etc/snuba/settings.py
- name: DEFAULT_BROKERS
value: {{ include "sentry.kafka.bootstrap_servers_string" . | quote }}
{{- if and (.Values.redis.enabled) (.Values.redis.auth.enabled) }}
{{- if .Values.redis.auth.password }}
- name: REDIS_PASSWORD
value: {{ .Values.redis.auth.password | quote }}
{{- else if .Values.redis.auth.existingSecret }}
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ default (include "sentry.redis.fullname" .) .Values.redis.auth.existingSecret }}
key: {{ default "redis-password" .Values.redis.auth.existingSecretPasswordKey }}
{{- end }}
{{- else if .Values.externalRedis.password }}
- name: REDIS_PASSWORD
value: {{ .Values.externalRedis.password | quote }}
{{- else if .Values.externalRedis.existingSecret }}
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.externalRedis.existingSecret }}
key: {{ default "redis-password" .Values.externalRedis.existingSecretKey }}
{{- end }}
{{- if .Values.externalClickhouse.existingSecret }}
- name: CLICKHOUSE_PASSWORD
valueFrom:
Expand All @@ -467,6 +512,8 @@ Common Snuba environment variables
- name: UWSGI_HTTP_SOCKET
value: "[::]:1218"
{{- end }}
- name: REDIS_PORT
value: {{ default "6379" (include "sentry.redis.port" . | quote ) -}}
{{- end -}}

{{- define "vroom.env" -}}
Expand All @@ -484,6 +531,10 @@ Common Snuba environment variables
Common Sentry environment variables
*/}}
{{- define "sentry.env" -}}
{{- $redisHost := include "sentry.redis.host" . -}}
{{- $redisPort := include "sentry.redis.port" . -}}
{{- $redisDb := include "sentry.redis.db" . -}}
{{- $redisProto := ternary "rediss" "redis" (eq (include "sentry.redis.ssl" .) "true") -}}
- name: SNUBA
value: http://{{ template "sentry.fullname" . }}-snuba:{{ template "snuba.port" . }}
- name: VROOM
Expand Down Expand Up @@ -568,6 +619,45 @@ Common Sentry environment variables
secretKeyRef:
name: {{ .Values.filestore.s3.existingSecret }}
key: {{ default "s3-secret-access-key" .Values.filestore.s3.secretAccessKeyRef }}
key: {{ default "postgresql-password" .Values.externalPostgresql.existingSecretKey }}
{{- end }}
{{- if .Values.redis.enabled }}
{{- if .Values.redis.password }}
- name: REDIS_PASSWORD
value: {{ .Values.redis.password | quote }}
{{- else if .Values.redis.existingSecret }}
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ default (include "sentry.redis.fullname" .) .Values.redis.existingSecret }}
key: {{ default "redis-password" .Values.redis.existingSecretKey }}
{{- end }}
{{- else if .Values.externalRedis.password }}
- name: REDIS_PASSWORD
value: {{ .Values.externalRedis.password | quote }}
{{- else if .Values.externalRedis.existingSecret }}
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.externalRedis.existingSecret }}
key: {{ default "redis-password" .Values.externalRedis.existingSecretKey }}
{{- end }}
{{- if and (.Values.redis.enabled) (.Values.redis.auth.existingSecret) }}
- name: HELM_CHARTS_SENTRY_REDIS_PASSWORD_CONTROLLED
valueFrom:
secretKeyRef:
name: {{ .Values.redis.auth.existingSecret }}
key: {{ default "redis-password" .Values.redis.auth.existingSecretPasswordKey }}
- name: BROKER_URL
value: "{{ $redisProto }}://:$(HELM_CHARTS_SENTRY_REDIS_PASSWORD_CONTROLLED)@{{ $redisHost }}:{{ $redisPort }}/{{ $redisDb }}"
{{- else if (.Values.externalRedis.existingSecret) }}
- name: HELM_CHARTS_SENTRY_REDIS_PASSWORD_CONTROLLED
valueFrom:
secretKeyRef:
name: {{ .Values.externalRedis.existingSecret }}
key: {{ default "redis-password" .Values.externalRedis.existingSecretKey }}
- name: BROKER_URL
value: "{{ $redisProto }}://:$(HELM_CHARTS_SENTRY_REDIS_PASSWORD_CONTROLLED)@{{ $redisHost }}:{{ $redisPort }}/{{ $redisDb }}"
{{- end }}
{{- if and (eq .Values.filestore.backend "gcs") .Values.filestore.gcs.secretName }}
- name: GOOGLE_APPLICATION_CREDENTIALS
Expand Down Expand Up @@ -620,7 +710,7 @@ Common Sentry environment variables
valueFrom:
secretKeyRef:
name: {{ .Values.discord.existingSecret }}
key: {{ default "bot-token" .Values.discord.existingSecretBotToken }}
key: {{ default "bot-token" .Values.discord.existingSecretBotToken }}
{{- end }}
{{- if and .Values.github.existingSecret }}
- name: GITHUB_APP_PRIVATE_KEY
Expand Down
8 changes: 6 additions & 2 deletions charts/sentry/templates/relay/_helper-sentry-relay.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{{- $redisHost := include "sentry.redis.host" . -}}
{{- $redisPort := include "sentry.redis.port" . -}}
{{- $redisPass := include "sentry.redis.password" . -}}
{{- $redisDb := include "sentry.redis.db" . -}}
{{- $redisProto := ternary "rediss" "redis" (eq (include "sentry.redis.ssl" .) "true") -}}
config.yml: |-
relay:
{{- if .Values.relay.mode }}
Expand Down Expand Up @@ -63,9 +65,11 @@ config.yml: |-
{{- end }}

{{- if $redisPass }}
redis: "redis://:{{ $redisPass }}@{{ $redisHost }}:{{ $redisPort }}"
{{- if and (not .Values.externalRedis.existingSecret) (not .Values.redis.auth.existingSecret)}}
redis: "{{ $redisProto }}://:{{ $redisPass }}@{{ $redisHost }}:{{ $redisPort }}/{{ $redisDb }}"
{{- end }}
{{- else }}
redis: "redis://{{ $redisHost }}:{{ $redisPort }}"
redis: "{{ $redisProto }}://{{ $redisHost }}:{{ $redisPort }}/{{ $redisDb }}"
{{- end }}
topics:
metrics_sessions: ingest-metrics
Expand Down
24 changes: 24 additions & 0 deletions charts/sentry/templates/relay/deployment-relay.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{{- if .Values.relay.enabled }}
{{- $redisHost := include "sentry.redis.host" . -}}
{{- $redisPort := include "sentry.redis.port" . -}}
{{- $redisDb := include "sentry.redis.db" . -}}
{{- $redisPass := include "sentry.redis.password" . -}}
{{- $redisProto := ternary "rediss" "redis" (eq (include "sentry.redis.ssl" .) "true") -}}

apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -86,6 +92,15 @@ spec:
env:
- name: RELAY_PORT
value: '{{ template "relay.port" }}'
{{- if and (not $redisPass) (.Values.externalRedis.existingSecret) }}
- name: HELM_CHARTS_RELAY_REDIS_PASSWORD_CONTROLLED
valueFrom:
secretKeyRef:
name: {{ .Values.externalRedis.existingSecret }}
key: {{ default "redis-password" .Values.externalRedis.existingSecretKey }}
- name: RELAY_REDIS_URL
value: {{ $redisProto }}://$(HELM_CHARTS_RELAY_REDIS_PASSWORD_CONTROLLED)@{{ $redisHost }}:{{ $redisPort }}/{{ $redisDb }}
{{- end }}
{{- if .Values.relay.init.env }}
{{ toYaml .Values.relay.init.env | indent 12 }}
{{- end }}
Expand Down Expand Up @@ -119,6 +134,15 @@ spec:
env:
- name: RELAY_PORT
value: '{{ template "relay.port" }}'
{{- if and (not $redisPass) (.Values.externalRedis.existingSecret) }}
- name: HELM_CHARTS_RELAY_REDIS_PASSWORD_CONTROLLED
valueFrom:
secretKeyRef:
name: {{ .Values.externalRedis.existingSecret }}
key: {{ default "redis-password" .Values.externalRedis.existingSecretKey }}
- name: RELAY_REDIS_URL
value: {{ $redisProto }}://$(HELM_CHARTS_RELAY_REDIS_PASSWORD_CONTROLLED)@{{ $redisHost }}:{{ $redisPort }}/{{ $redisDb }}
{{- end }}
{{- if .Values.relay.env }}
{{ toYaml .Values.relay.env | indent 8 }}
{{- end }}
Expand Down
40 changes: 28 additions & 12 deletions charts/sentry/templates/sentry/_helper-sentry.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{{- $redisHost := include "sentry.redis.host" . -}}
{{- $redisPort := include "sentry.redis.port" . -}}
{{- $redisPass := include "sentry.redis.password" . -}}
{{- $redisDb := include "sentry.redis.db" . -}}
{{- $redisProto := ternary "rediss" "redis" (eq (include "sentry.redis.ssl" .) "true") -}}
config.yml: |-
{{- if .Values.system.adminEmail }}
system.admin-email: {{ .Values.system.adminEmail | quote }}
Expand Down Expand Up @@ -73,15 +75,7 @@ config.yml: |-
#########
# Redis #
#########
redis.clusters:
default:
hosts:
0:
host: {{ $redisHost | quote }}
port: {{ $redisPort }}
{{- if $redisPass }}
password: {{ $redisPass | quote }}
{{- end }}
# This is configured in the sentry.conf.py as that has support for environment variables.

################
# File storage #
Expand Down Expand Up @@ -171,6 +165,28 @@ sentry.conf.py: |-

SENTRY_OPTIONS["system.event-retention-days"] = int(env('SENTRY_EVENT_RETENTION_DAYS') or {{ .Values.sentry.cleanup.days | quote }})

#########
# Redis #
#########

# Generic Redis configuration used as defaults for various things including:
# Buffers, Quotas, TSDB
SENTRY_OPTIONS["redis.clusters"] = {
"default": {
"hosts": {
0: {
"host": {{ $redisHost | quote }},
"password": os.environ.get("REDIS_PASSWORD", {{ $redisPass | quote }}),
"port": {{ $redisPort | quote }},
{{- if .Values.externalRedis.ssl }}
"ssl": {{ .Values.externalRedis.ssl | quote }},
{{- end }}
"db": {{ $redisDb | quote }}
}
}
}
}

#########
# Queue #
#########
Expand All @@ -182,9 +198,9 @@ sentry.conf.py: |-
{{- if or (.Values.rabbitmq.enabled) (.Values.rabbitmq.host) }}
BROKER_URL = os.environ.get("BROKER_URL", "amqp://{{ .Values.rabbitmq.auth.username }}:{{ .Values.rabbitmq.auth.password }}@{{ template "sentry.rabbitmq.host" . }}:5672/{{ .Values.rabbitmq.vhost }}")
{{- else if $redisPass }}
BROKER_URL = os.environ.get("BROKER_URL", "redis://:{{ $redisPass }}@{{ $redisHost }}:{{ $redisPort }}/0")
{{- else }}
BROKER_URL = os.environ.get("BROKER_URL", "redis://{{ $redisHost }}:{{ $redisPort }}/0")
BROKER_URL = os.environ.get("BROKER_URL", "{{ $redisProto }}://:{{ $redisPass }}@{{ $redisHost }}:{{ $redisPort }}/{{ $redisDb }}")
{{- else if and (not .Values.externalRedis.existingSecret) (not .Values.redis.auth.existingSecret)}}
BROKER_URL = os.environ.get("BROKER_URL", "{{ $redisProto }}://{{ $redisHost }}:{{ $redisPort }}/{{ $redisDb }}")
{{- end }}

#########
Expand Down
16 changes: 14 additions & 2 deletions charts/sentry/templates/snuba/_helper-snuba.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{- define "sentry.snuba.config" -}}
{{- $redisPass := include "sentry.redis.password" . -}}
{{- $redisSsl := include "sentry.redis.ssl" . -}}
settings.py: |
import os

Expand Down Expand Up @@ -62,10 +63,21 @@ settings.py: |
# Redis Options
REDIS_HOST = {{ include "sentry.redis.host" . | quote }}
REDIS_PORT = {{ include "sentry.redis.port" . }}
{{- if $redisPass }}
{{- if or (not ($redisPass)) (.Values.externalRedis.existingSecret) (.Values.redis.auth.existingSecret) }}
REDIS_PASSWORD = env("REDIS_PASSWORD", "")
{{- else if $redisPass }}
REDIS_PASSWORD = {{ $redisPass | quote }}
{{- end }}
REDIS_DB = int(env("REDIS_DB", 1))

{{- if .Values.redis.enabled }}
REDIS_DB = int(env("REDIS_DB", {{ default 1 .Values.redis.db }}))
{{- else }}
REDIS_DB = int(env("REDIS_DB", {{ default 1 .Values.externalRedis.db }}))
{{- end }}

{{- if eq $redisSsl "true" }}
REDIS_SSL = True
{{- end }}

{{- if .Values.metrics.enabled }}
DOGSTATSD_HOST = "{{ template "sentry.fullname" . }}-metrics"
Expand Down
15 changes: 12 additions & 3 deletions charts/sentry/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2070,10 +2070,12 @@ redis:
auth:
enabled: false
sentinel: false
## Just omit the password field if your redis cluster doesn't use password
# password: redis
# existingSecret: secret-name
## set existingSecretPasswordKey if key name inside existingSecret is different from redis-password'
# existingSecretPasswordKey: secret-key-name
nameOverride: sentry-redis
usePassword: false
## Just omit the password field if your redis cluster doesn't use password
# password: redis
master:
persistence:
enabled: true
Expand All @@ -2091,6 +2093,13 @@ externalRedis:
port: 6379
## Just omit the password field if your redis cluster doesn't use password
# password: redis
# existingSecret: secret-name
## set existingSecretKey if key name inside existingSecret is different from redis-password'
# existingSecretKey: secret-key-name
## Integer database number to use for redis (This is an integer)
# db: 0
## Use ssl for the connection to Redis (True/False)
# ssl: false

postgresql:
enabled: true
Expand Down