Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rnacentral/apiv1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@
cache_page(CACHE_TIMEOUT)(views.RelationshipsView.as_view()),
name="rna-relationships",
),
# internal health check for RNA-KG API
re_path(
r"^internal/rna-kg-health/?$",
views.RnaKgHealthCheckView.as_view(),
name="rna-kg-health-check",
),
]

urlpatterns = format_suffix_patterns(
Expand Down
63 changes: 62 additions & 1 deletion rnacentral/apiv1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,10 +1231,71 @@ def get(self, request, pk, taxid, **kwargs):
"message": "No gene information available for this sequence"
})

class RnaKgHealthCheckView(APIView):
"""
Internal endpoint for monitoring RNA-KG API availability.
Used by UptimeRobot to check if the RNA Knowledge Graph API is operational.
"""

permission_classes = (AllowAny,)

def get(self, request):
import time

rna_kg_base_url = "https://rna-kg.biodata.di.unimi.it/api/v1/node/id"
# Test URS (hsa-mir-708-5b)
test_params = {
'node_id': 'URS000019D79B_9606',
'node_id_scheme': 'RNAcentral'
}

start_time = time.time()

try:
response = requests.get(rna_kg_base_url, params=test_params, timeout=10)
response_time_ms = int((time.time() - start_time) * 1000)

if response.status_code == 200:
return Response({
'status': 'ok',
'service': 'RNA-KG API',
'response_time_ms': response_time_ms,
'api_url': 'https://rna-kg.biodata.di.unimi.it/api/v1/'
})
else:
return Response({
'status': 'error',
'service': 'RNA-KG API',
'response_time_ms': response_time_ms,
'error': f'API returned status code {response.status_code}',
'api_url': 'https://rna-kg.biodata.di.unimi.it/api/v1/'
}, status=status.HTTP_503_SERVICE_UNAVAILABLE)

except requests.exceptions.Timeout:
response_time_ms = int((time.time() - start_time) * 1000)
return Response({
'status': 'error',
'service': 'RNA-KG API',
'response_time_ms': response_time_ms,
'error': 'Request timed out',
'api_url': 'https://rna-kg.biodata.di.unimi.it/api/v1/'
}, status=status.HTTP_503_SERVICE_UNAVAILABLE)

except requests.exceptions.RequestException as e:
response_time_ms = int((time.time() - start_time) * 1000)
return Response({
'status': 'error',
'service': 'RNA-KG API',
'response_time_ms': response_time_ms,
'error': str(e),
'api_url': 'https://rna-kg.biodata.di.unimi.it/api/v1/'
}, status=status.HTTP_503_SERVICE_UNAVAILABLE)


class RelationshipsView(generics.ListAPIView):
"""
API endpoint for retrieving molecular relationships from RNA Knowledge Graph.

[API documentation](/api)
"""

Expand Down