-
Notifications
You must be signed in to change notification settings - Fork 2
/
superset-config.py
80 lines (59 loc) · 2.01 KB
/
superset-config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
def get_env_variable(var_name, default=None):
"""Get the environment variable or raise exception.
Args:
var_name (str): the name of the environment variable to look up
default (str): the default value if no env is found
"""
try:
return os.environ[var_name]
except KeyError:
if default is not None:
return default
raise RuntimeError(
'The environment variable {} was missing, abort...'
.format(var_name)
)
def get_secret(secret_name, default=None):
"""Get secrets mounted by kubernetes.
Args:
secret_name (str): the name of the secret, corresponds to the filename
default (str): the default value if no secret is found
"""
secret = None
try:
with open('/secrets/{0}'.format(secret_name), 'r') as secret_file:
secret = secret_file.read().strip()
except (IOError, FileNotFoundError):
pass
if secret is None:
if default is None:
raise RuntimeError(
'Missing a required secret: {0}.'.format(secret_name)
)
secret = default
return secret
# Postgres
POSTGRES_USER = get_secret('database/username')
POSTGRES_PASSWORD = get_secret('database/password')
POSTGRES_HOST = get_env_variable('DB_HOST')
POSTGRES_PORT = get_env_variable('DB_PORT', 5432)
POSTGRES_DB = get_env_variable('DB_NAME')
SQLALCHEMY_DATABASE_URI = 'postgresql://{0}:{1}@{2}:{3}/{4}'.format(
POSTGRES_USER,
POSTGRES_PASSWORD,
POSTGRES_HOST,
POSTGRES_PORT,
POSTGRES_DB,
)
# Redis
REDIS_HOST = get_env_variable('REDIS_HOST')
REDIS_PORT = get_env_variable('REDIS_PORT', 6379)
# Celery
class CeleryConfig:
BROKER_URL = 'redis://{0}:{1}/0'.format(REDIS_HOST, REDIS_PORT)
CELERY_IMPORTS = ('superset.sql_lab',)
CELERY_RESULT_BACKEND = 'redis://{0}:{1}/1'.format(REDIS_HOST, REDIS_PORT)
CELERY_ANNOTATIONS = {'tasks.add': {'rate_limit': '10/s'}}
CELERY_TASK_PROTOCOL = 1
CELERY_CONFIG = CeleryConfig