Skip to content

Commit

Permalink
Showing 4 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -40,6 +40,10 @@ dynamic = ["version"]

[project.optional-dependencies]
postgres = ["psycopg2"]
server = [
"fastapi",
"safir >= 3.4.0"
]
test = [
"pytest >= 3.2",
"pytest-openfiles >= 0.5.0",
21 changes: 21 additions & 0 deletions python/lsst/daf/butler/remote_butler/server/_server.py
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
SerializedDatasetRef,
SerializedDatasetType,
)
from safir.metadata import Metadata, get_metadata

from ._config import get_config_from_env
from ._factory import Factory
@@ -97,6 +98,26 @@ def unpack_dataId(butler: Butler, data_id: SerializedDataCoordinate | None) -> D
return DataCoordinate.from_simple(data_id, registry=butler.registry)


@app.get(
"/",
description=(
"Return metadata about the running application. Can also be used as"
" a health check. This route is not exposed outside the cluster and"
" therefore cannot be used by external clients."
),
include_in_schema=False,
response_model=Metadata,
response_model_exclude_none=True,
summary="Application metadata",
)
async def get_index() -> Metadata:
"""GET ``/`` (the app's internal root).
By convention, this endpoint returns only the application's metadata.
"""
return get_metadata(package_name="lsst.daf.butler", application_name="butler")


@app.get("/butler/v1/universe", response_model=dict[str, Any])
def get_dimension_universe(factory: Factory = Depends(factory_dependency)) -> dict[str, Any]:
"""Allow remote client to get dimensions definition."""
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -21,3 +21,4 @@ pyarrow >= 0.16
responses >= 0.12.0
urllib3 >= 1.25.10
fastapi
safir >= 3.4.0
5 changes: 5 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -93,6 +93,11 @@ def tearDownClass(cls):
del app.dependency_overrides[factory_dependency]
removeTestTempDir(cls.root)

def test_health_check(self):
response = self.client.get("/")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["name"], "butler")

def test_simple(self):
response = self.client.get("/butler/v1/universe")
self.assertEqual(response.status_code, 200)

0 comments on commit bd1e706

Please sign in to comment.