# What this PR does - Refactor alert receive channel lookup so it is easier to follow - Remove the additional lookup that was taking place for alert receive channels that belong to a deleted organization, these can be treated as deleted for usage purposes even though the alert receive channel itself does not have `deleted_at` populated - Organizations that have been moved will still need to be looked up everytime. This is not optimized in favor of not maintaining a cache of Organizations. These are not frequent requests and can be optimized later if necessary. ## Which issue(s) this PR closes <!-- *Note*: if you have more than one GitHub issue that this PR closes, be sure to preface each issue link with a [closing keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue). This ensures that the issue(s) are auto-closed once the PR has been merged. --> ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes.
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
from django.conf import settings
|
|
from django.core.cache import cache
|
|
from django.http import HttpResponse, JsonResponse
|
|
from django.views.generic import View
|
|
|
|
from apps.integrations.mixins import AlertChannelDefiningMixin
|
|
|
|
|
|
class HealthCheckView(View):
|
|
"""
|
|
This view is used in k8s liveness probe.
|
|
k8s periodically makes requests to this view and
|
|
if the requests fail the container will be restarted
|
|
"""
|
|
|
|
dangerously_bypass_middlewares = True
|
|
|
|
def get(self, request):
|
|
return HttpResponse("Ok")
|
|
|
|
|
|
class ReadinessCheckView(View):
|
|
"""
|
|
This view is used in k8s readiness probe.
|
|
k8s periodically makes requests to this view and
|
|
if the requests fail the container will stop getting the traffic.
|
|
"""
|
|
|
|
dangerously_bypass_middlewares = True
|
|
|
|
def get(self, request):
|
|
return HttpResponse("Ok")
|
|
|
|
|
|
class StartupProbeView(View):
|
|
"""
|
|
This view is used in k8s startup probe.
|
|
k8s makes requests to this view on the startup and
|
|
if the requests fail the container will be restarted
|
|
Caching AlertReceive channels if they are not cached. Also checking initial database connection.
|
|
"""
|
|
|
|
dangerously_bypass_middlewares = True
|
|
|
|
def get(self, request):
|
|
if cache.get(AlertChannelDefiningMixin.CACHE_KEY_DB_FALLBACK) is None:
|
|
AlertChannelDefiningMixin().update_alert_receive_channel_fallback_cache()
|
|
|
|
return HttpResponse("Ok")
|
|
|
|
|
|
class MaintenanceModeStatusView(View):
|
|
def get(self, _request):
|
|
return JsonResponse(
|
|
{
|
|
"currently_undergoing_maintenance_message": settings.CURRENTLY_UNDERGOING_MAINTENANCE_MESSAGE,
|
|
}
|
|
)
|