Skip to content

Commit

Permalink
Merge pull request #37 from unicef/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
shubhamgoel02 authored Sep 18, 2024
2 parents e19d07e + 3539d77 commit 4d0450f
Show file tree
Hide file tree
Showing 40 changed files with 1,952 additions and 376 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ rabbitmq

postgres_data/
docker/docker-compose.dev.yml
proco/assets/*.db
15 changes: 6 additions & 9 deletions config/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json
import os
import sys
import warnings

Expand Down Expand Up @@ -33,6 +31,7 @@

AUTH_USER_MODEL = 'custom_auth.ApplicationUser'

ENABLED_BACKEND_PROMETHEUS_METRICS = env.bool('ENABLED_BACKEND_PROMETHEUS_METRICS', default=True)
# Application definition
# --------------------------------------------------------------------------

Expand Down Expand Up @@ -87,7 +86,6 @@
# --------------------------------------------------------------------------

MIDDLEWARE = [
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'django.middleware.gzip.GZipMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -101,9 +99,12 @@
# 'drf_secure_token.middleware.UpdateTokenMiddleware',
'admin_reorder.middleware.ModelAdminReorder',
'proco.utils.middleware.CustomCorsMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware',
]

if ENABLED_BACKEND_PROMETHEUS_METRICS:
MIDDLEWARE.insert(0, 'django_prometheus.middleware.PrometheusBeforeMiddleware')
MIDDLEWARE.insert(len(MIDDLEWARE), 'django_prometheus.middleware.PrometheusAfterMiddleware')

# Custom authentication backend
AUTHENTICATION_BACKENDS = ['proco.custom_auth.backends.RemoteAndModelBackend']

Expand Down Expand Up @@ -433,9 +434,6 @@

INVALIDATE_CACHE_HARD = env('INVALIDATE_CACHE_HARD', default='false')

with open(os.path.join(BASE_DIR, 'proco', 'core', 'resources', 'filters.json')) as filters_json_file:
FILTERS_DATA = json.load(filters_json_file)

# DATABASE_ROUTERS = ["proco.utils.read_db_router.StandbyRouter"]

GIGAMAPS_LOG_LEVEL = env('GIGAMAPS_LOG_LEVEL', default='INFO')
Expand All @@ -457,8 +455,7 @@
},
'formatters': {
'verbose': {
'format': '%(hostname)s %(hostip)s %(asctime)s %(levelname)s %(pathname)s %(process)d '
'%(processName)s %(thread)d: %(message)s'
'format': '%(hostname)s %(hostip)s %(asctime)s %(levelname)s %(pathname)s: %(message)s'
},
},
'handlers': {
Expand Down
7 changes: 6 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def trigger_error(request):
path('test/', TestView.as_view()),
path('health/', PingAPIView.as_view()),
path('sentry-debug/', trigger_error),
path('', include('django_prometheus.urls')),
]

if settings.DEBUG:
Expand All @@ -56,3 +55,9 @@ def trigger_error(request):
urlpatterns += [
path('__debug__/', include(debug_toolbar.urls)),
]


if settings.ENABLED_BACKEND_PROMETHEUS_METRICS:
urlpatterns += [
path('', include('django_prometheus.urls')),
]
8 changes: 8 additions & 0 deletions hello.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import requests

from flask import Flask

app = Flask(__name__)
Expand All @@ -6,3 +9,8 @@
@app.route('/')
def hello_world():
return 'Hello, World!'

@app.route("/metrics")
def metrics():
response = requests.get('http://localhost:{port}/metrics'.format(port=os.environ.get('FLOWER_PORT', 6543)))
return response.text
Loading

0 comments on commit 4d0450f

Please sign in to comment.