Skip to content

Commit

Permalink
Fixes cc-archive#487(image index availability check)
Browse files Browse the repository at this point in the history
  • Loading branch information
madewithkode committed May 12, 2020
1 parent 88c81eb commit e4a9838
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Before you start writing code, make sure there is an issue open. Pull requests w

If you want to get started contributing code to this project but don't know exactly what to work on, we compiled a good list of issues labeled as [Good first issues](https://github.com/creativecommons/cccatalog-frontend/labels/good%20first%20issue) which are small in scope and not so complex to solve. There is also issues labeld as [Help wanted](https://github.com/creativecommons/cccatalog-frontend/labels/help%20wanted) which can be a bit more complex but are good examples of thigns we are currently accepting help from the community.

Any code modifications will have to be accompanied by the appropriate unit tests. This will be checked and verified during code review. Once the Pull Reques is opened, our CI server will run the unit test suite and run a code linter to verify that the code follows the coding guidelines.
Any code modifications will have to be accompanied by the appropriate unit tests. This will be checked and verified during code review. Once the Pull Request is opened, our CI server will run the unit test suite and run a code linter to verify that the code follows the coding guidelines.

If you want to run the unit tests and linter on your machine, run the following commands:

Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cccatalog-api contributors (sorted alphabetically by last name)

* **[Liza Daley](https://github.com/lizadaly)**
* Built CC Search prototype, bits of which live on in this repository to this day
* **[Princewill Onyenanu](https://github.com/madewithkode)**
* Implemented Elasticsearch `image` index availability check on `/healthcheck` view
* **[Alden Page](https://github.com/aldenstpage)**
* Author and maintainer of current implementation
* **[Paulo Rosário](https://github.com/paulofilip3)**
Expand Down
19 changes: 15 additions & 4 deletions cccatalog-api/cccatalog/api/views/site_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rest_framework.reverse import reverse
from rest_framework.views import APIView
from rest_framework import serializers
from cccatalog.api.controllers.search_controller import get_providers
from cccatalog.api.controllers.search_controller import get_providers, es
from cccatalog.api.serializers.oauth2_serializers import\
OAuth2RegistrationSerializer, OAuth2RegistrationSuccessful, OAuth2KeyInfo
from drf_yasg.utils import swagger_auto_schema
Expand All @@ -17,17 +17,22 @@
from cccatalog.api.utils.oauth2_helper import get_token_info
from cccatalog.settings import THUMBNAIL_PROXY_URL, THUMBNAIL_WIDTH_PX
from django.core.cache import cache
from django.views.decorators.cache import cache_page
from django.utils.decorators import method_decorator
from django.http import HttpResponse

IDENTIFIER = 'provider_identifier'
NAME = 'provider_name'
FILTER = 'filter_content'
URL = 'domain_name'
HEALTH_CACHE_TTL = 10


@method_decorator(cache_page(10), name='get')
class HealthCheck(APIView):
"""
Returns a `200 OK` response if the server is running.
Returns a `200 OK` response if the server is running and `image`
index exists and a `500 Internal Server Error` if either of the condition fails.
This endpoint is used in production to ensure that the server should receive
traffic. If no response is provided, the server is deregistered from the
Expand All @@ -36,8 +41,14 @@ class HealthCheck(APIView):
swagger_schema = None

def get(self, request, format=None):
return Response('', status=200)

es_conn = es
image_index_exists = es_conn.indices.exists(index=["image"])
if image_index_exists:
return Response('', status=200)
else:
log.error('The health check failed because the cluster image index is either unhealthy or non-existent')
return Response('', status=500)


class AboutImageResponse(serializers.Serializer):
""" The full image search response. """
Expand Down
1 change: 1 addition & 0 deletions cccatalog-api/cccatalog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
}
}


# Produce CC-hosted thumbnails dynamically through a proxy.
PROXY_THUMBS = bool(os.environ.get('PROXY_THUMBS', True))
THUMBNAIL_PROXY_URL = os.environ.get(
Expand Down
1 change: 1 addition & 0 deletions cccatalog-api/cccatalog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from drf_yasg import openapi
import rest_framework.permissions


description = """
*This is the documentation for version 1.0 of the Creative Commons API.
Visit https://api.creativecommons.engineering/v0/ to view the legacy
Expand Down

0 comments on commit e4a9838

Please sign in to comment.