Skip to content

Commit 1b88e90

Browse files
authored
Introduce patches with external kafka (#3521)
* Introduce patches with external kafka * Fix pre-commit hooks * Patch relay config file * Documentation for patches stuff * Provide more helpful information for Docker Compose Override file * Fix grep command * ref: rename to 'optional-modifications' * chore(pre-commit): exclude .patch extension * chore(pre-commit): escape backslash * chore(pre-commit): put exclude field on hooks * chore(pre-commit): put exclude field on top level Based on https://pre-commit.com/#top_level-exclude * chore(pre-commit): move to even more top level
1 parent 0730d8c commit 1b88e90

File tree

7 files changed

+261
-1
lines changed

7 files changed

+261
-1
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
exclude: '\.patch$'
12
repos:
23
- repo: local
34
hooks:
@@ -11,7 +12,6 @@ repos:
1112
args: [-w, -d]
1213
files: .*\.sh
1314
stages: [commit, merge-commit, push, manual]
14-
1515
- repo: https://github.com/pre-commit/pre-commit-hooks
1616
rev: v4.3.0
1717
hooks:

optional-modifications/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Optional Modifications
2+
3+
Other than the default self-hosted Sentry installation, sometimes users
4+
can leverage their existing infrastructure to help them with limited
5+
resources. "Patches", or you might call this like a "plugin system", is
6+
a collection of patch files (see [man patch(1)](https://man7.org/linux/man-pages/man1/patch.1.html))
7+
that can be used with to modify the existing configuration to achieve
8+
the desired goal.
9+
10+
> [!WARNING]
11+
> Beware that this is very experimental and might not work as expected.
12+
>
13+
> **Use it at your own risk!**
14+
15+
## How to use patches
16+
17+
The patches are designed mostly to help modify the existing
18+
configuration files. You will need to run the `install.sh` script
19+
afterwards.
20+
21+
They should be run from the root directory. For example, the
22+
`external-kafka` patches should be run as:
23+
24+
```bash
25+
patch < optional-modifications/patches/external-kafka/.env.patch
26+
patch < optional-modifications/patches/external-kafka/config.example.yml.patch
27+
patch < optional-modifications/patches/external-kafka/sentry.conf.example.py.patch
28+
patch < optional-modifications/patches/external-kafka/docker-compose.yml.patch
29+
```
30+
31+
Some patches might require additional steps to be taken, like providing
32+
credentials or additional TLS certificates.
33+
34+
## Official support
35+
36+
Sentry employees are not obliged to provide dedicated support for
37+
patches, but they can help by providing information to move us forward.
38+
We encourage the community to contribute for any bug fixes or
39+
improvements.
40+
41+
See the [support policy for self-hosted Sentry](https://develop.sentry.dev/self-hosted/support/) for more information.

optional-modifications/_lib.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
test "${DEBUG:-}" && set -x
5+
6+
function patch_file() {
7+
target="$1"
8+
content="$2"
9+
if [[ -f "$target" ]]; then
10+
echo "🙈 Patching $target ..."
11+
patch -p1 <"$content"
12+
else
13+
echo "🙊 Skipping $target ..."
14+
fi
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--- .env 2025-02-04 07:31:54.868049984 +0700
2+
+++ .env.external-kafka 2025-05-15 08:33:15.442361105 +0700
3+
@@ -22,3 +22,19 @@
4+
POSTGRES_MAX_CONNECTIONS=100
5+
# Set SETUP_JS_SDK_ASSETS to 1 to enable the setup of JS SDK assets
6+
# SETUP_JS_SDK_ASSETS=1
7+
+
8+
+################################################################################
9+
+## Additional External Kafka options
10+
+################################################################################
11+
+KAFKA_BOOTSTRAP_SERVERS=kafka-node1:9092,kafka-node2:9092,kafka-node3:9092
12+
+# Valid options are PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL
13+
+KAFKA_SECURITY_PROTOCOL=PLAINTEXT
14+
+# Valid options are PLAIN, SCRAM-SHA-256, SCRAM-SHA-512. Other mechanism might be unavailable.
15+
+# KAFKA_SASL_MECHANISM=PLAIN
16+
+# KAFKA_SASL_USERNAME=username
17+
+# KAFKA_SASL_PASSWORD=password
18+
+# Put your certificates on the \`certificates/kafka\` directory.
19+
+# The certificates will be mounted as read-only volumes.
20+
+# KAFKA_SSL_CA_LOCATION=/kafka-certificates/ca.pem
21+
+# KAFKA_SSL_CERTIFICATE_LOCATION=/kafka-certificates/client.pem
22+
+# KAFKA_SSL_KEY_LOCATION=/kafka-certificates/client.key
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--- relay/config.example.yml 2025-05-15 08:27:40.426876887 +0700
2+
+++ relay/config.example.external-kafka.yml 2025-05-15 08:34:21.113311217 +0700
3+
@@ -7,8 +7,15 @@
4+
processing:
5+
enabled: true
6+
kafka_config:
7+
- - {name: "bootstrap.servers", value: "kafka:9092"}
8+
+ - {name: "bootstrap.servers", value: "kafka-node1:9092,kafka-node2:9092,kafka-node3:9092"}
9+
- {name: "message.max.bytes", value: 50000000} # 50MB
10+
+ - {name: "security.protocol", value: "PLAINTEXT"}
11+
+ - {name: "sasl.mechanism", value: "PLAIN"} # Remove or comment this line if SASL is not used.
12+
+ - {name: "sasl.username", value: "username"} # Remove or comment this line if SASL is not used.
13+
+ - {name: "sasl.password", value: "password"} # Remove or comment this line if SASL is not used.
14+
+ - {name: "ssl.ca.location", value: "/kafka-certificates/ca.pem"} # Remove or comment this line if SSL is not used.
15+
+ - {name: "ssl.certificate.location", value: "/kafka-certificates/client.pem"} # Remove or comment this line if SSL is not used.
16+
+ - {name: "ssl.key.location", value: "/kafka-certificates/client.key"} # Remove or comment this line if SSL is not used.
17+
redis: redis://redis:6379
18+
geoip_path: "/geoip/GeoLite2-City.mmdb"
19+
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
--- docker-compose.yml 2025-03-17 13:32:15.120328412 +0700
2+
+++ docker-compose.external-kafka.yml 2025-05-15 08:39:05.509951068 +0700
3+
@@ -26,8 +26,6 @@
4+
depends_on:
5+
redis:
6+
<<: *depends_on-healthy
7+
- kafka:
8+
- <<: *depends_on-healthy
9+
postgres:
10+
<<: *depends_on-healthy
11+
memcached:
12+
@@ -59,6 +57,14 @@
13+
SENTRY_EVENT_RETENTION_DAYS:
14+
SENTRY_MAIL_HOST:
15+
SENTRY_MAX_EXTERNAL_SOURCEMAP_SIZE:
16+
+ KAFKA_BOOTSTRAP_SERVERS: ${KAFKA_BOOTSTRAP_SERVERS:-kafka:9092}
17+
+ KAFKA_SECURITY_PROTOCOL: ${KAFKA_SECURITY_PROTOCOL:-PLAINTEXT}
18+
+ KAFKA_SSL_CA_LOCATION: ${KAFKA_SSL_CA_LOCATION:-}
19+
+ KAFKA_SSL_CERTIFICATE_LOCATION: ${KAFKA_SSL_CERTIFICATE_LOCATION:-}
20+
+ KAFKA_SSL_KEY_LOCATION: ${KAFKA_SSL_KEY_LOCATION:-}
21+
+ KAFKA_SASL_MECHANISM: ${KAFKA_SASL_MECHANISM:-}
22+
+ KAFKA_SASL_USERNAME: ${KAFKA_SASL_USERNAME:-}
23+
+ KAFKA_SASL_PASSWORD: ${KAFKA_SASL_PASSWORD:-}
24+
volumes:
25+
- "sentry-data:/data"
26+
- "./sentry:/etc/sentry"
27+
@@ -69,15 +75,20 @@
28+
depends_on:
29+
clickhouse:
30+
<<: *depends_on-healthy
31+
- kafka:
32+
- <<: *depends_on-healthy
33+
redis:
34+
<<: *depends_on-healthy
35+
image: "$SNUBA_IMAGE"
36+
environment:
37+
SNUBA_SETTINGS: self_hosted
38+
CLICKHOUSE_HOST: clickhouse
39+
- DEFAULT_BROKERS: "kafka:9092"
40+
+ DEFAULT_BROKERS: ${KAFKA_BOOTSTRAP_SERVERS:-kafka:9092}
41+
+ KAFKA_SECURITY_PROTOCOL: ${KAFKA_SECURITY_PROTOCOL:-PLAINTEXT}
42+
+ KAFKA_SSL_CA_PATH: ${KAFKA_SSL_CA_LOCATION:-}
43+
+ KAFKA_SSL_CERT_PATH: ${KAFKA_SSL_CERTIFICATE_LOCATION:-}
44+
+ KAFKA_SSL_KEY_PATH: ${KAFKA_SSL_KEY_LOCATION:-}
45+
+ KAFKA_SASL_MECHANISM: ${KAFKA_SASL_MECHANISM:-}
46+
+ KAFKA_SASL_USERNAME: ${KAFKA_SASL_USERNAME:-}
47+
+ KAFKA_SASL_PASSWORD: ${KAFKA_SASL_PASSWORD:-}
48+
REDIS_HOST: redis
49+
UWSGI_MAX_REQUESTS: "10000"
50+
UWSGI_DISABLE_LOGGING: "true"
51+
@@ -140,43 +151,7 @@
52+
POSTGRES_HOST_AUTH_METHOD: "trust"
53+
volumes:
54+
- "sentry-postgres:/var/lib/postgresql/data"
55+
- kafka:
56+
- <<: *restart_policy
57+
- image: "confluentinc/cp-kafka:7.6.1"
58+
- environment:
59+
- # https://docs.confluent.io/platform/current/installation/docker/config-reference.html#cp-kakfa-example
60+
- KAFKA_PROCESS_ROLES: "broker,controller"
61+
- KAFKA_CONTROLLER_QUORUM_VOTERS: "[email protected]:29093"
62+
- KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
63+
- KAFKA_NODE_ID: "1001"
64+
- CLUSTER_ID: "MkU3OEVBNTcwNTJENDM2Qk"
65+
- KAFKA_LISTENERS: "PLAINTEXT://0.0.0.0:29092,INTERNAL://0.0.0.0:9093,EXTERNAL://0.0.0.0:9092,CONTROLLER://0.0.0.0:29093"
66+
- KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://127.0.0.1:29092,INTERNAL://kafka:9093,EXTERNAL://kafka:9092"
67+
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "PLAINTEXT:PLAINTEXT,INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,CONTROLLER:PLAINTEXT"
68+
- KAFKA_INTER_BROKER_LISTENER_NAME: "PLAINTEXT"
69+
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
70+
- KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS: "1"
71+
- KAFKA_LOG_RETENTION_HOURS: "24"
72+
- KAFKA_MESSAGE_MAX_BYTES: "50000000" #50MB or bust
73+
- KAFKA_MAX_REQUEST_SIZE: "50000000" #50MB on requests apparently too
74+
- CONFLUENT_SUPPORT_METRICS_ENABLE: "false"
75+
- KAFKA_LOG4J_LOGGERS: "kafka.cluster=WARN,kafka.controller=WARN,kafka.coordinator=WARN,kafka.log=WARN,kafka.server=WARN,state.change.logger=WARN"
76+
- KAFKA_LOG4J_ROOT_LOGLEVEL: "WARN"
77+
- KAFKA_TOOLS_LOG4J_LOGLEVEL: "WARN"
78+
- ulimits:
79+
- nofile:
80+
- soft: 4096
81+
- hard: 4096
82+
- volumes:
83+
- - "sentry-kafka:/var/lib/kafka/data"
84+
- - "sentry-kafka-log:/var/lib/kafka/log"
85+
- - "sentry-secrets:/etc/kafka/secrets"
86+
- healthcheck:
87+
- <<: *healthcheck_defaults
88+
- test: ["CMD-SHELL", "nc -z localhost 9092"]
89+
- interval: 10s
90+
- timeout: 10s
91+
- retries: 30
92+
+ kafka: !reset null
93+
clickhouse:
94+
<<: *restart_policy
95+
image: clickhouse-self-hosted-local
96+
@@ -475,9 +450,8 @@
97+
read_only: true
98+
source: ./geoip
99+
target: /geoip
100+
+ - ./certificates/kafka:/kafka-certificates:ro
101+
depends_on:
102+
- kafka:
103+
- <<: *depends_on-healthy
104+
redis:
105+
<<: *depends_on-healthy
106+
web:
107+
@@ -486,15 +460,21 @@
108+
<<: *restart_policy
109+
image: "$VROOM_IMAGE"
110+
environment:
111+
- SENTRY_KAFKA_BROKERS_PROFILING: "kafka:9092"
112+
- SENTRY_KAFKA_BROKERS_OCCURRENCES: "kafka:9092"
113+
+ SENTRY_KAFKA_BROKERS_PROFILING: ${KAFKA_BOOTSTRAP_SERVERS:-kafka:9092}
114+
+ SENTRY_KAFKA_BROKERS_OCCURRENCES: ${KAFKA_BOOTSTRAP_SERVERS:-kafka:9092}
115+
+ SENTRY_KAFKA_BROKERS_SPANS: ${KAFKA_BOOTSTRAP_SERVERS:-kafka:9092}
116+
+ SENTRY_KAFKA_SECURITY_PROTOCOL: ${KAFKA_SECURITY_PROTOCOL:-PLAINTEXT}
117+
+ SENTRY_KAFKA_SSL_CA_PATH: ${KAFKA_SSL_CA_LOCATION:-}
118+
+ SENTRY_KAFKA_SSL_CERT_PATH: ${KAFKA_SSL_CERTIFICATE_LOCATION:-}
119+
+ SENTRY_KAFKA_SSL_KEY_PATH: ${KAFKA_SSL_KEY_LOCATION:-}
120+
+ SENTRY_KAFKA_SASL_MECHANISM: ${KAFKA_SASL_MECHANISM:-}
121+
+ SENTRY_KAFKA_SASL_USERNAME: ${KAFKA_SASL_USERNAME:-}
122+
+ SENTRY_KAFKA_SASL_PASSWORD: ${KAFKA_SASL_PASSWORD:-}
123+
SENTRY_BUCKET_PROFILES: file://localhost//var/lib/sentry-profiles
124+
SENTRY_SNUBA_HOST: "http://snuba-api:1218"
125+
volumes:
126+
- sentry-vroom:/var/lib/sentry-profiles
127+
- depends_on:
128+
- kafka:
129+
- <<: *depends_on-healthy
130+
+ - ./certificates/kafka:/kafka-certificates:ro
131+
profiles:
132+
- feature-complete
133+
vroom-cleanup:
134+
@@ -523,8 +503,6 @@
135+
external: true
136+
sentry-redis:
137+
external: true
138+
- sentry-kafka:
139+
- external: true
140+
sentry-clickhouse:
141+
external: true
142+
sentry-symbolicator:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--- sentry/sentry.conf.example.py 2025-05-15 08:27:40.427876868 +0700
2+
+++ sentry/sentry.conf.example.external-kafka.py 2025-05-15 08:32:44.845127931 +0700
3+
@@ -132,9 +132,17 @@
4+
SENTRY_CACHE = "sentry.cache.redis.RedisCache"
5+
6+
DEFAULT_KAFKA_OPTIONS = {
7+
- "bootstrap.servers": "kafka:9092",
8+
+ "bootstrap.servers": env("KAFKA_BOOTSTRAP_SERVERS", "kafka:9092"),
9+
"message.max.bytes": 50000000,
10+
"socket.timeout.ms": 1000,
11+
+ "security.protocol": env("KAFKA_SECURITY_PROTOCOL", "PLAINTEXT"), # Valid options are PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL
12+
+ # If you don't use any of these options below, you can remove them or set them to `None`.
13+
+ "sasl.mechanism": env("KAFKA_SASL_MECHANISM", None), # Valid options are PLAIN, SCRAM-SHA-256, SCRAM-SHA-512. Other mechanism might be unavailable.
14+
+ "sasl.username": env("KAFKA_SASL_USERNAME", None),
15+
+ "sasl.password": env("KAFKA_SASL_PASSWORD", None),
16+
+ "ssl.ca.location": env("KAFKA_SSL_CA_LOCATION", None), # Remove this line if SSL is not used.
17+
+ "ssl.certificate.location": env("KAFKA_SSL_CERTIFICATE_LOCATION", None), # Remove this line if SSL is not used.
18+
+ "ssl.key.location": env("KAFKA_SSL_KEY_LOCATION", None), # Remove this line if SSL is not used.
19+
}
20+
21+
SENTRY_EVENTSTREAM = "sentry.eventstream.kafka.KafkaEventStream"

0 commit comments

Comments
 (0)