Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a /status endpoint that tells us about this NameRes instance #119

Merged
merged 1 commit into from
Dec 2, 2023
Merged
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
52 changes: 52 additions & 0 deletions api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
allow_headers=["*"],
)

# ENDPOINT /
# If someone tries accessing /, we should redirect them to the Swagger interface.
@app.get("/", include_in_schema=False)
async def docs_redirect():
Expand All @@ -44,6 +45,57 @@ async def docs_redirect():
return RedirectResponse(url='/docs')


@app.get("/status",
summary="Get status and counts for this NameRes instance.",
description="This endpoint will return status information and a list of counts from the underlying Solr "
"instance for this NameRes instance."
)
async def status_get() -> Dict:
""" Return status and count information from the underyling Solr instance. """
return await status()


async def status() -> Dict:
""" Return a dictionary containing status and count information for the underlying Solr instance. """
query_url = f"http://{SOLR_HOST}:{SOLR_PORT}/solr/admin/cores"
async with httpx.AsyncClient(timeout=None) as client:
response = await client.get(query_url, params={
'action': 'STATUS'
})
if response.status_code >= 300:
LOGGER.error("Solr error on accessing /solr/admin/cores?action=STATUS: %s", response.text)
response.raise_for_status()
result = response.json()

# We should have a status for name_lookup_shard1_replica_n1.
if 'status' in result and 'name_lookup_shard1_replica_n1' in result['status']:
core = result['status']['name_lookup_shard1_replica_n1']

index = {}
if 'index' in core:
index = core['index']

return {
'status': 'ok',
'message': 'Reporting results from primary core.',
'startTime': core['startTime'],
'numDocs': index.get('numDocs', ''),
'maxDoc': index.get('maxDoc', ''),
'deletedDocs': index.get('deletedDocs', ''),
'version': index.get('version', ''),
'segmentCount': index.get('segmentCount', ''),
'lastModified': index.get('lastModified', ''),
'size': index.get('size', ''),
}
else:
return {
'status': 'error',
'message': 'Expected core not found.'
}


# ENDPOINT /reverse_lookup

class Request(BaseModel):
"""Reverse-lookup request body."""
curies: List[str]
Expand Down
Loading