· 6 years ago · May 25, 2019, 10:24 PM
1#see https://forum.sentry.io/t/enhancement-configs-not-found-on-latest-branches/6800
2
3# This file is just Python, with a touch of Django which means
4# you can inherit and tweak settings to your hearts content.
5
6# For Docker, the following environment variables are supported:
7# SENTRY_POSTGRES_HOST
8# SENTRY_POSTGRES_PORT
9# SENTRY_DB_NAME
10# SENTRY_DB_USER
11# SENTRY_DB_PASSWORD
12# SENTRY_RABBITMQ_HOST
13# SENTRY_RABBITMQ_USERNAME
14# SENTRY_RABBITMQ_PASSWORD
15# SENTRY_RABBITMQ_VHOST
16# SENTRY_REDIS_HOST
17# SENTRY_REDIS_PASSWORD
18# SENTRY_REDIS_PORT
19# SENTRY_REDIS_DB
20# SENTRY_MEMCACHED_HOST
21# SENTRY_MEMCACHED_PORT
22# SENTRY_FILESTORE_DIR
23# SENTRY_SERVER_EMAIL
24# SENTRY_EMAIL_HOST
25# SENTRY_EMAIL_PORT
26# SENTRY_EMAIL_USER
27# SENTRY_EMAIL_PASSWORD
28# SENTRY_EMAIL_USE_TLS
29# SENTRY_ENABLE_EMAIL_REPLIES
30# SENTRY_SMTP_HOSTNAME
31# SENTRY_MAILGUN_API_KEY
32# SENTRY_SINGLE_ORGANIZATION
33# SENTRY_SECRET_KEY
34from sentry.conf.server import * # NOQA
35from sentry.utils.types import Bool
36
37import os
38import os.path
39
40CONF_ROOT = os.path.dirname(__file__)
41env = os.environ.get
42
43postgres = env('SENTRY_POSTGRES_HOST') or (env('POSTGRES_PORT_5432_TCP_ADDR') and 'postgres')
44if postgres:
45 DATABASES = {
46 'default': {
47 'ENGINE': 'sentry.db.postgres',
48 'NAME': (
49 env('SENTRY_DB_NAME')
50 or env('POSTGRES_ENV_POSTGRES_USER')
51 or 'postgres'
52 ),
53 'USER': (
54 env('SENTRY_DB_USER')
55 or env('POSTGRES_ENV_POSTGRES_USER')
56 or 'postgres'
57 ),
58 'PASSWORD': (
59 env('SENTRY_DB_PASSWORD')
60 or env('POSTGRES_ENV_POSTGRES_PASSWORD')
61 or ''
62 ),
63 'HOST': postgres,
64 'PORT': (
65 env('SENTRY_POSTGRES_PORT')
66 or ''
67 ),
68 'OPTIONS': {
69 'autocommit': True,
70 },
71 },
72 }
73
74# You should not change this setting after your database has been created
75# unless you have altered all schemas first
76SENTRY_USE_BIG_INTS = True
77
78# If you're expecting any kind of real traffic on Sentry, we highly recommend
79# configuring the CACHES and Redis settings
80
81###########
82# General #
83###########
84
85# Instruct Sentry that this install intends to be run by a single organization
86# and thus various UI optimizations should be enabled.
87SENTRY_SINGLE_ORGANIZATION = Bool(env('SENTRY_SINGLE_ORGANIZATION', True))
88
89#########
90# Redis #
91#########
92
93# Generic Redis configuration used as defaults for various things including:
94# Buffers, Quotas, TSDB
95
96redis = env('SENTRY_REDIS_HOST') or (env('REDIS_PORT_6379_TCP_ADDR') and 'redis')
97if not redis:
98 raise Exception('Error: REDIS_PORT_6379_TCP_ADDR (or SENTRY_REDIS_HOST) is undefined, did you forget to `--link` a redis container?')
99
100redis_password = env('SENTRY_REDIS_PASSWORD') or ''
101redis_port = env('SENTRY_REDIS_PORT') or '6379'
102redis_db = env('SENTRY_REDIS_DB') or '0'
103
104SENTRY_OPTIONS.update({
105 'redis.clusters': {
106 'default': {
107 'hosts': {
108 0: {
109 'host': redis,
110 'password': redis_password,
111 'port': redis_port,
112 'db': redis_db,
113 },
114 },
115 },
116 },
117})
118
119#########
120# Cache #
121#########
122
123# Sentry currently utilizes two separate mechanisms. While CACHES is not a
124# requirement, it will optimize several high throughput patterns.
125
126memcached = env('SENTRY_MEMCACHED_HOST') or (env('MEMCACHED_PORT_11211_TCP_ADDR') and 'memcached')
127if memcached:
128 memcached_port = (
129 env('SENTRY_MEMCACHED_PORT')
130 or '11211'
131 )
132 CACHES = {
133 'default': {
134 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
135 'LOCATION': [memcached + ':' + memcached_port],
136 'TIMEOUT': 3600,
137 }
138 }
139
140# A primary cache is required for things such as processing events
141SENTRY_CACHE = 'sentry.cache.redis.RedisCache'
142
143#########
144# Queue #
145#########
146
147# See https://docs.getsentry.com/on-premise/server/queue/ for more
148# information on configuring your queue broker and workers. Sentry relies
149# on a Python framework called Celery to manage queues.
150
151rabbitmq = env('SENTRY_RABBITMQ_HOST') or (env('RABBITMQ_PORT_5672_TCP_ADDR') and 'rabbitmq')
152
153if rabbitmq:
154 BROKER_URL = (
155 'amqp://' + (
156 env('SENTRY_RABBITMQ_USERNAME')
157 or env('RABBITMQ_ENV_RABBITMQ_DEFAULT_USER')
158 or 'guest'
159 ) + ':' + (
160 env('SENTRY_RABBITMQ_PASSWORD')
161 or env('RABBITMQ_ENV_RABBITMQ_DEFAULT_PASS')
162 or 'guest'
163 ) + '@' + rabbitmq + '/' + (
164 env('SENTRY_RABBITMQ_VHOST')
165 or env('RABBITMQ_ENV_RABBITMQ_DEFAULT_VHOST')
166 or '/'
167 )
168 )
169else:
170 BROKER_URL = 'redis://:' + redis_password + '@' + redis + ':' + redis_port + '/' + redis_db
171
172
173###############
174# Rate Limits #
175###############
176
177# Rate limits apply to notification handlers and are enforced per-project
178# automatically.
179
180SENTRY_RATELIMITER = 'sentry.ratelimits.redis.RedisRateLimiter'
181
182##################
183# Update Buffers #
184##################
185
186# Buffers (combined with queueing) act as an intermediate layer between the
187# database and the storage API. They will greatly improve efficiency on large
188# numbers of the same events being sent to the API in a short amount of time.
189# (read: if you send any kind of real data to Sentry, you should enable buffers)
190
191SENTRY_BUFFER = 'sentry.buffer.redis.RedisBuffer'
192
193##########
194# Quotas #
195##########
196
197# Quotas allow you to rate limit individual projects or the Sentry install as
198# a whole.
199
200SENTRY_QUOTAS = 'sentry.quotas.redis.RedisQuota'
201
202########
203# TSDB #
204########
205
206# The TSDB is used for building charts as well as making things like per-rate
207# alerts possible.
208
209SENTRY_TSDB = 'sentry.tsdb.redis.RedisTSDB'
210
211###########
212# Digests #
213###########
214
215# The digest backend powers notification summaries.
216
217SENTRY_DIGESTS = 'sentry.digests.backends.redis.RedisBackend'
218
219################
220# File storage #
221################
222
223# Uploaded media uses these `filestore` settings. The available
224# backends are either `filesystem` or `s3`.
225
226SENTRY_OPTIONS['filestore.backend'] = 'filesystem'
227SENTRY_OPTIONS['filestore.options'] = {
228 'location': env('SENTRY_FILESTORE_DIR'),
229}
230
231##############
232# Web Server #
233##############
234
235# If you're using a reverse SSL proxy, you should enable the X-Forwarded-Proto
236# header and set `SENTRY_USE_SSL=1`
237
238if Bool(env('SENTRY_USE_SSL', False)):
239 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
240 SESSION_COOKIE_SECURE = True
241 CSRF_COOKIE_SECURE = True
242
243SENTRY_WEB_HOST = '0.0.0.0'
244SENTRY_WEB_PORT = 9090
245SENTRY_WEB_OPTIONS = {
246 # 'workers': 3, # the number of web workers
247}
248
249###############
250# Mail Server #
251###############
252
253
254email = env('SENTRY_EMAIL_HOST') or (env('SMTP_PORT_25_TCP_ADDR') and 'smtp')
255if email:
256 SENTRY_OPTIONS['mail.backend'] = 'smtp'
257 SENTRY_OPTIONS['mail.host'] = email
258 SENTRY_OPTIONS['mail.password'] = env('SENTRY_EMAIL_PASSWORD') or ''
259 SENTRY_OPTIONS['mail.username'] = env('SENTRY_EMAIL_USER') or ''
260 SENTRY_OPTIONS['mail.port'] = int(env('SENTRY_EMAIL_PORT') or 25)
261 SENTRY_OPTIONS['mail.use-tls'] = Bool(env('SENTRY_EMAIL_USE_TLS', False))
262else:
263 SENTRY_OPTIONS['mail.backend'] = 'dummy'
264
265# The email address to send on behalf of
266SENTRY_OPTIONS['mail.from'] = env('SENTRY_SERVER_EMAIL') or 'root@localhost'
267
268# If you're using mailgun for inbound mail, set your API key and configure a
269# route to forward to /api/hooks/mailgun/inbound/
270SENTRY_OPTIONS['mail.mailgun-api-key'] = env('SENTRY_MAILGUN_API_KEY') or ''
271
272# If you specify a MAILGUN_API_KEY, you definitely want EMAIL_REPLIES
273if SENTRY_OPTIONS['mail.mailgun-api-key']:
274 SENTRY_OPTIONS['mail.enable-replies'] = True
275else:
276 SENTRY_OPTIONS['mail.enable-replies'] = Bool(env('SENTRY_ENABLE_EMAIL_REPLIES', False))
277
278if SENTRY_OPTIONS['mail.enable-replies']:
279 SENTRY_OPTIONS['mail.reply-hostname'] = env('SENTRY_SMTP_HOSTNAME') or ''
280
281# If this value ever becomes compromised, it's important to regenerate your
282# SENTRY_SECRET_KEY. Changing this value will result in all current sessions
283# being invalidated.
284secret_key = env('SENTRY_SECRET_KEY')
285if not secret_key:
286 raise Exception('Error: SENTRY_SECRET_KEY is undefined, run `generate-secret-key` and set to -e SENTRY_SECRET_KEY')
287
288if 'SENTRY_RUNNING_UWSGI' not in os.environ and len(secret_key) < 32:
289 print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
290 print('!! CAUTION !!')
291 print('!! Your SENTRY_SECRET_KEY is potentially insecure. !!')
292 print('!! We recommend at least 32 characters long. !!')
293 print('!! Regenerate with `generate-secret-key`. !!')
294 print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
295
296SENTRY_OPTIONS['system.secret-key'] = secret_key
297#SENTRY_FEATURES['organizations:discover'] = True
298#SENTRY_FEATURES['organizations:events'] = True
299#SENTRY_SEARCH = 'sentry.search.snuba.SnubaSearchBackend'
300#SENTRY_TAGSTORE = 'sentry.tagstore.snuba.SnubaCompatibilityTagStorage'
301#SENTRY_TSDB = 'sentry.tsdb.redissnuba.RedisSnubaTSDB'
302#SENTRY_EVENTSTREAM = 'sentry.eventstream.snuba.SnubaEventStream'