How to implement alive and readyness with django-health-check

4/27/2020

We are using kuberntes and need two different endpoints one for health and one for alive. For some reasons we chosse https://github.com/KristianOellegaard/django-health-check. Its easy to implement a second view for alive which is loaded, but - this view is empty - I do not understand how I could configure the plugings which should be used for the view.

class AliveCheck(MainView):
# template_name = 'myapp/health_check_dashboard.html'  # customize the used templates

def __init__(self):
    self.plugins.clear()
    self.plugins.append(DiskUsage())

def get(self, request, *args, **kwargs):
    errors = super(MainView, self).run_check()
    return super(MainView, self).get(request, args, kwargs)

Any ideas?

-- EhmKah
django
django-health-check
kubernetes

1 Answer

4/28/2020

We found the following solution for us. Not nice because we access internal properties from super classes - but its working.

class AliveCheck(MainView):

    def __init__(self):
        self.plugins          # force loading of configured plugins
        self._plugins.clear() # remove all configured plugins
        # append the plugins you are interested in 
        self._plugins.append(CacheBackend())
        self._plugins.append(DefaultFileStorageHealthCheck())
        self._plugins.append(DiskUsage())
        self._plugins.append(MemoryUsage())
-- EhmKah
Source: StackOverflow