Commit bf269134 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE

Merge branch 'dedicated_probe' into 'master'

Dedicated probe

See merge request hub/12765-viralhostrangedb!29
parents eb7d2115 9ac7ab7d
......@@ -39,11 +39,11 @@ spec:
mountPath: /code/persistent_volume
livenessProbe:
httpGet:
path: /about/
path: /probe_alive/
port: 8086
readinessProbe:
httpGet:
path: /about/
path: /probe_ready/
port: 8086
resources:
requests:
......
......@@ -167,6 +167,14 @@ ADMINS = [
MAIL_ADMINS_ON_ERROR = config('MAIL_ADMINS_ON_ERROR', default="auto") in ["True", "true", "1"] \
or config('MAIL_ADMINS_ON_ERROR', default="auto") == "auto" \
and not config('USE_SQLITE_AS_DB', default=False, cast=bool)
def skip_probe(record):
if record and record.request and record.request.path == "/probe_ready/":
return False
return True
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
......@@ -176,6 +184,12 @@ LOGGING = {
'style': '{',
},
},
'filters': {
'skip_probes': {
'()': 'django.utils.log.CallbackFilter',
'callback': skip_probe,
}
},
'handlers': {
'console': {
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
......@@ -187,6 +201,7 @@ LOGGING = {
'formatter': 'simple',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
'filters': ['skip_probes'],
}
},
'loggers': {
......
......@@ -350,54 +350,6 @@ class AutomatedMergeOnImportTestCase(TestCase):
self.assertEqual(models.Virus.objects.filter(name="r1").count(), 2)
class MergeTestCase(TestCase):
test_data = "./test_data"
def setUp(self) -> None:
self.user_pwd = "eil2guj4cuSho2Vai3hu"
################################################################################
self.user = get_user_model().objects.create(
username="user",
email="b@a.a",
is_staff=True,
)
self.user.set_password(self.user_pwd)
self.user.save()
################################################################################
self.three_reponse_simple = models.DataSource.objects.create(
owner=self.user,
public=True,
name="three_reponse_simple",
raw_name="three_reponse_simple.xlsx",
kind="FILE",
)
filename = os.path.join(self.test_data, "three_reponse_simple.xlsx")
business_process.import_file(
data_source=self.three_reponse_simple,
file=filename,
)
models.Virus.objects.update(identifier="eee")
models.Host.objects.update(identifier="eee")
################################################################################
self.three_reponse_simple_2 = models.DataSource.objects.create(
owner=self.user,
public=True,
name="three_reponse_simple_2",
raw_name="three_reponse_simple_2.xlsx",
kind="FILE",
)
filename = os.path.join(self.test_data, "three_reponse_simple_2.xlsx")
business_process.import_file(
data_source=self.three_reponse_simple_2,
file=filename,
)
models.Virus.objects.update(identifier="")
models.Host.objects.update(identifier="")
class ResetMappingTestCase(ViewTestCase):
def test_reset_mapping_ok(self):
self.assertTrue(self.four_reponse_simple.is_mapping_done)
......
......@@ -1325,3 +1325,9 @@ class SearchTestCase(ViewTestCase):
url = reverse('viralhostrangedb:search')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
class ProbeTestCase(TestCase):
def test_is_pk(self):
self.assertEqual(200, self.client.get(reverse('viralhostrangedb:probe_ready')).status_code)
self.assertEqual(200, self.client.get(reverse('viralhostrangedb:probe_alive')).status_code)
......@@ -51,6 +51,10 @@ urlpatterns = [
url(r'^response/ds-(?P<ds_pk>\d+)-virus-(?P<virus_pk>\d+)-host-(?P<host_pk>\d+)/update/$',
views.response_update, name='response-update'),
url(r'^search/$', views.search, name='search'),
url(r'^probe_alive/$', views.is_alive, name='probe_alive'),
url(r'^probe_ready/$', views.is_ready, name='probe_ready'),
path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'),
]
......@@ -8,6 +8,7 @@ import pandas as pd
from basetheme_bootstrap.user_preferences import get_user_preferences_for_user
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.staticfiles.templatetags.staticfiles import static
......@@ -1443,3 +1444,26 @@ def search(request):
template_name='viralhostrangedb/search.html',
context=context,
)
def is_ready(request):
from django.db import OperationalError
import django.apps
import django.apps
try:
for model_class in django.apps.apps.get_models():
model_class.objects.first()
return HttpResponse(status=200)
except OperationalError:
pass
return HttpResponse(status=500)
def is_alive(request):
from django.db import OperationalError
try:
get_user_model().objects.exists()
return HttpResponse(status=200)
except OperationalError:
pass
return HttpResponse(status=500)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment