Skip to content

Commit a8227ee

Browse files
committed
Merge branch 'main' of https://github.com/drycc/controller into main
2 parents 86e8816 + f80e067 commit a8227ee

File tree

4 files changed

+71
-14
lines changed

4 files changed

+71
-14
lines changed

charts/controller/templates/controller-deployment.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,31 @@ spec:
149149
secretKeyRef:
150150
name: redis-creds
151151
key: password
152+
{{- if eq .Values.global.influxdb_location "off-cluster" }}
153+
- name: "INFLUXDB_URL"
154+
valueFrom:
155+
secretKeyRef:
156+
name: influxdb-creds
157+
key: url
158+
- name: "INFLUXDB_DATABASE"
159+
valueFrom:
160+
secretKeyRef:
161+
name: influxdb-creds
162+
key: database
163+
- name: "INFLUXDB_USER"
164+
valueFrom:
165+
secretKeyRef:
166+
name: influxdb-creds
167+
key: user
168+
- name: "INFLUXDB_PASSWORD"
169+
valueFrom:
170+
secretKeyRef:
171+
name: influxdb-creds
172+
key: password
173+
{{- else }}
174+
- name: "INFLUXDB_URL"
175+
value: http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT_TRANSPORT)
176+
{{- end }}
152177
{{- range $key, $value := .Values.environment }}
153178
- name: {{ $key }}
154179
value: {{ $value | quote }}

rootfs/api/settings/production.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -443,20 +443,6 @@
443443
}
444444
}
445445

446-
DRYCC_REDIS_ADDRS = os.environ.get('DRYCC_REDIS_ADDRS', '127.0.0.1:6379').split(",")
447-
DRYCC_REDIS_PASSWORD = os.environ.get('DRYCC_REDIS_PASSWORD', '')
448-
449-
CACHES = {
450-
"default": {
451-
"BACKEND": "django_redis.cache.RedisCache",
452-
"LOCATION": ['redis://:{}@{}'.format(DRYCC_REDIS_PASSWORD, DRYCC_REDIS_ADDR) \
453-
for DRYCC_REDIS_ADDR in DRYCC_REDIS_ADDRS], # noqa
454-
"OPTIONS": {
455-
"CLIENT_CLASS": "django_redis.client.ShardClient",
456-
}
457-
}
458-
}
459-
460446
APP_URL_REGEX = '[a-z0-9-]+'
461447

462448
# LDAP settings taken from environment variables.
@@ -514,6 +500,22 @@
514500
AUTH_LDAP_FIND_GROUP_PERMS = True
515501
AUTH_LDAP_CACHE_GROUPS = False
516502

503+
# Redis Configuration
504+
DRYCC_REDIS_ADDRS = os.environ.get('DRYCC_REDIS_ADDRS', '127.0.0.1:6379').split(",")
505+
DRYCC_REDIS_PASSWORD = os.environ.get('DRYCC_REDIS_PASSWORD', '')
506+
507+
# Cache Configuration
508+
CACHES = {
509+
"default": {
510+
"BACKEND": "django_redis.cache.RedisCache",
511+
"LOCATION": ['redis://:{}@{}'.format(DRYCC_REDIS_PASSWORD, DRYCC_REDIS_ADDR) \
512+
for DRYCC_REDIS_ADDR in DRYCC_REDIS_ADDRS], # noqa
513+
"OPTIONS": {
514+
"CLIENT_CLASS": "django_redis.client.ShardClient",
515+
}
516+
}
517+
}
518+
517519
# Celery Configuration Options
518520
CELERY_TIMEZONE = "Asia/Shanghai"
519521
CELERY_ENABLE_UTC = True
@@ -525,3 +527,9 @@
525527
CELERY_RESULT_BACKEND = 'redis://:{}@{}'.format(DRYCC_REDIS_PASSWORD, DRYCC_REDIS_ADDRS[0]) # noqa
526528
CELERY_CACHE_BACKEND = 'django-cache'
527529
CELERY_DEFAULT_QUEUE = 'priority.middle'
530+
531+
# Influxdb Configuration Options
532+
INFLUXDB_URL = os.environ.get('DRYCC_INFLUXDB_URL', 'http://localhost:8086')
533+
INFLUXDB_DATABASE = os.environ.get('DRYCC_INFLUXDB_DATABASE', 'drycc')
534+
INFLUXDB_USER = os.environ.get('DRYCC_INFLUXDB_USER', 'root')
535+
INFLUXDB_PASSWORD = os.environ.get('DRYCC_INFLUXDB_PASSWORD', 'root')

rootfs/api/utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
import hashlib
77
import logging
88
import random
9+
import threading
910
from copy import deepcopy
11+
from urllib.parse import urlparse
12+
from django.conf import settings
13+
from influxdb import InfluxDBClient
1014

15+
16+
local = threading.local()
1117
logger = logging.getLogger(__name__)
1218

1319

@@ -160,6 +166,23 @@ def apply_tasks(tasks):
160166
executor.shutdown(wait=True)
161167

162168

169+
def get_influxdb_client():
170+
if not hasattr(local, "influxdb_client"):
171+
addr = urlparse(settings.INFLUXDB_URL).netloc
172+
if ":" in addr:
173+
host, port = addr.rsplit(":")
174+
else:
175+
host, port = addr, 8086
176+
local.influxdb_client = InfluxDBClient(
177+
host,
178+
port,
179+
settings.INFLUXDB_USER,
180+
settings.INFLUXDB_PASSWORD,
181+
settings.INFLUXDB_DATABASE
182+
)
183+
return local.influxdb_client
184+
185+
163186
if __name__ == "__main__":
164187
import doctest
165188
doctest.testmod()

rootfs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ requests==2.24.0
2222
requests-toolbelt==0.9.1
2323
celery==5.0.2
2424
django_redis==4.12.1
25+
influxdb==5.3.1

0 commit comments

Comments
 (0)