Skip to content

Commit

Permalink
feat: recovery support multi hosts and ports of external kafka cluster (
Browse files Browse the repository at this point in the history
  • Loading branch information
MemberIT authored Nov 5, 2024
1 parent ddbc927 commit 889bd0d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
16 changes: 9 additions & 7 deletions charts/sentry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Note: this table is incomplete, so have a look at the values.yaml in case you mi
| externalClickhouse.singleNode | bool | `true` | |
| externalClickhouse.tcpPort | int | `9000` | |
| externalClickhouse.username | string | `"default"` | |
| externalKafka.cluster | list | `[]` | Multi hosts and ports of external Kafka |
| externalKafka.host | string | `"kafka-confluent"` | Hostname or IP address of external Kafka |
| externalKafka.port | int | `9092` | Port for external Kafka |
| externalKafka.compression.type | string | `""` | Compression type for Kafka messages ('gzip', 'snappy', 'lz4', 'zstd') |
Expand Down Expand Up @@ -1249,13 +1250,14 @@ or you can feed in a cluster of Kafka instances like below:

```yaml
externalKafka:
## List of Hostnames or ip addresses of external kafka
- host: "233.5.100.28"
port: 9092
- host: "233.5.100.29"
port: 9092
- host: "233.5.100.30"
port: 9092
cluster:
## List of Hostnames or ip addresses and ports of external kafka
- host: "233.5.100.28"
port: 9092
- host: "kafka-confluent-2"
port: 9093
- host: "kafka-confluent-3"
port: 9094
```

## External Postgres configuration
Expand Down
6 changes: 6 additions & 0 deletions charts/sentry/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* When running upgrades, make sure to give back the `system.secretKey` value.

kubectl -n {{ .Release.Namespace }} get configmap {{ template "sentry.fullname" . }}-sentry -o json | grep -m1 -Po '(?<=system.secret-key: )[^\\]*'

{{ if not (.Values.kafka.enabled) }}
* Sentry use external kafka:

{{ template "sentry.kafka.bootstrap_servers_string" . }}
{{ end -}}
16 changes: 8 additions & 8 deletions charts/sentry/templates/_helper.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ Set Kafka Confluent host
{{- define "sentry.kafka.host" -}}
{{- if .Values.kafka.enabled -}}
{{- template "sentry.kafka.fullname" . -}}
{{- else if and (.Values.externalKafka) (not (kindIs "slice" .Values.externalKafka)) -}}
{{- else if and (.Values.externalKafka) (not (.Values.externalKafka.cluster)) -}}
{{ required "A valid .Values.externalKafka.host is required" .Values.externalKafka.host }}
{{- end -}}
{{- end -}}
Expand All @@ -429,7 +429,7 @@ Set Kafka Confluent port
{{- define "sentry.kafka.port" -}}
{{- if and (.Values.kafka.enabled) (.Values.kafka.service.ports.client) -}}
{{- .Values.kafka.service.ports.client }}
{{- else if and (.Values.externalKafka) (not (kindIs "slice" .Values.externalKafka)) -}}
{{- else if and (.Values.externalKafka) (not (.Values.externalKafka.cluster)) -}}
{{ required "A valid .Values.externalKafka.port is required" .Values.externalKafka.port }}
{{- end -}}
{{- end -}}
Expand All @@ -440,7 +440,7 @@ Set Kafka Confluent Controller port
{{- define "sentry.kafka.controller_port" -}}
{{- if and (.Values.kafka.enabled) (.Values.kafka.service.ports.controller ) -}}
{{- .Values.kafka.service.ports.controller }}
{{- else if and (.Values.externalKafka) (not (kindIs "slice" .Values.externalKafka)) -}}
{{- else if and (.Values.externalKafka) (not (.Values.externalKafka.cluster)) -}}
{{ required "A valid .Values.externalKafka.port is required" .Values.externalKafka.port }}
{{- end -}}
{{- end -}}
Expand All @@ -449,20 +449,20 @@ Set Kafka Confluent Controller port
Set Kafka bootstrap servers string
*/}}
{{- define "sentry.kafka.bootstrap_servers_string" -}}
{{- if or (.Values.kafka.enabled) (not (kindIs "slice" .Values.externalKafka)) -}}
{{- if or (.Values.kafka.enabled) (not (.Values.externalKafka.cluster)) -}}
{{ printf "%s:%s" (include "sentry.kafka.host" .) (include "sentry.kafka.port" .) }}
{{- else -}}
{{- range $index, $elem := .Values.externalKafka -}}
{{- range $index, $elem := .Values.externalKafka.cluster -}}
{{- if $index -}},{{- end -}}{{ printf "%s:%s" $elem.host (toString $elem.port) }}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
SASL auth setings for Kafka:
* https://github.com/getsentry/snuba/blob/24.7.1/snuba/settings/__init__.py#L219-L229
* https://github.com/getsentry/sentry/blob/24.7.1/src/sentry/utils/kafka_config.py#L9-L34
* https://github.com/getsentry/sentry/blob/24.7.1/src/sentry/conf/server.py#L2827-L2836
* https://github.com/getsentry/snuba/blob/24.9.0/snuba/settings/__init__.py#L220-L230
* https://github.com/getsentry/sentry/blob/24.9.0/src/sentry/utils/kafka_config.py#L9-L34
* https://github.com/getsentry/sentry/blob/24.9.0/src/sentry/conf/server.py#L2844-L2853
*/}}

{{/*
Expand Down
4 changes: 2 additions & 2 deletions charts/sentry/templates/hooks/sentry-db-check.job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ spec:
done
echo "Kraft controllers are up"
{{- end }}
{{- else if (not (kindIs "slice" .Values.externalKafka)) }}
{{- else if (not (.Values.externalKafka.cluster)) }}
KAFKA_HOST={{ .Values.externalKafka.host }}
if ! nc -z "$KAFKA_HOST" {{ $kafkaPort }}; then
KAFKA_STATUS=0
echo "$KAFKA_HOST is not available yet"
fi
{{- else }}
{{- range $elem := .Values.externalKafka }}
{{- range $elem := .Values.externalKafka.cluster }}
KAFKA_HOST={{ $elem.host }}
if ! nc -z "$KAFKA_HOST" {{ $elem.port }}; then
KAFKA_STATUS=0
Expand Down
13 changes: 11 additions & 2 deletions charts/sentry/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2179,10 +2179,19 @@ kafka:
## This value is only used when kafka.enabled is set to false
##
externalKafka:
## Hostname or ip address of external kafka
## Multi hosts and ports of external kafka
##
# cluster:
# - host: "233.5.100.28"
# port: 9092
# - host: "kafka-confluent-2"
# port: 9093
# - host: "kafka-confluent-3"
# port: 9094
## Or Hostname (ip address) of external kafka
# host: "kafka-confluent"
port: 9092
## and port of external kafka
# port: 9092
compression:
type: # 'gzip', 'snappy', 'lz4', 'zstd'
message:
Expand Down

0 comments on commit 889bd0d

Please sign in to comment.