-
Notifications
You must be signed in to change notification settings - Fork 449
refactor: main into app modules and route registrars #1561
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a9a4ad7
Refactor main into app modules and route registrars
edwinjosechittilappilly ced33e6
Clear additional app/service modules in tests
edwinjosechittilappilly a4ada93
Export ingest flag and simplify test cleanup
edwinjosechittilappilly 5058610
Add lint CI and apply style cleanups
edwinjosechittilappilly 747f441
Require bootstrap import first; add isort section
edwinjosechittilappilly 868b613
Update __init__.py
edwinjosechittilappilly ea880d3
Update __init__.py
edwinjosechittilappilly 6b89eab
update register_all_routes call
edwinjosechittilappilly 048652b
Update opensearch_init.py
edwinjosechittilappilly e9b9932
Cancel and await background tasks on shutdown
edwinjosechittilappilly cddafa6
Handle OpenSearch disk-space errors explicitly
edwinjosechittilappilly ad40fce
Add JWT_SIGNING_KEY setting and use it
edwinjosechittilappilly 29d8c03
Update settings.py
edwinjosechittilappilly de3aab9
Use settings for FastAPI debug and RBAC
edwinjosechittilappilly 9b82dbb
Default FASTAPI_DEBUG to LOG_LEVEL=DEBUG
edwinjosechittilappilly b726699
Move ACCESS_LOG setting to config and use it
edwinjosechittilappilly 8eb46a0
Use recursive globs in lint workflow
edwinjosechittilappilly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| name: Lint Backend | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'src/**/*.py' | ||
| - 'tests/**/*.py' | ||
| - 'pyproject.toml' | ||
| - 'uv.lock' | ||
| - '.github/workflows/lint-backend.yml' | ||
|
|
||
| # Cancel in-flight runs on the same PR when a new push lands. | ||
| concurrency: | ||
| group: lint-backend-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Ruff and mypy on changed files | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # Need the full base ref locally so we can compute the diff | ||
| # against the PR's merge base. | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v3 | ||
| with: | ||
| enable-cache: true | ||
|
|
||
| - name: Set up Python | ||
| run: uv python install 3.13 | ||
|
|
||
| - name: Install dev dependencies | ||
| run: uv sync --group dev | ||
|
|
||
| - name: Compute changed Python files | ||
| id: changed | ||
| run: | | ||
| base="${{ github.event.pull_request.base.sha }}" | ||
| head="${{ github.event.pull_request.head.sha }}" | ||
| # Diff against the merge base so we only see files touched in the PR. | ||
| merge_base=$(git merge-base "$base" "$head") | ||
| mapfile -t files < <(git diff --name-only --diff-filter=ACMR "$merge_base" "$head" -- '*.py') | ||
| if [ "${#files[@]}" -eq 0 ]; then | ||
| echo "No Python files changed." | ||
| echo "files=" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
| printf '%s\n' "${files[@]}" | ||
| # Pass as a single space-separated string to subsequent steps. | ||
| echo "files=${files[*]}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Ruff (auto-fix dry run + format check) | ||
| if: steps.changed.outputs.files != '' | ||
| run: | | ||
| # `--no-fix` reports the same set of issues that `--fix` would | ||
| # apply, so the developer sees what to run locally to clean up. | ||
| uv run ruff check --no-fix --output-format=github ${{ steps.changed.outputs.files }} | ||
| uv run ruff format --check ${{ steps.changed.outputs.files }} | ||
|
|
||
| - name: Mypy | ||
| if: steps.changed.outputs.files != '' | ||
| run: | | ||
| # Run mypy from src/ so module paths resolve, dropping the | ||
| # leading "src/" from each path. Tests files are checked from | ||
| # the repo root. | ||
| src_files=() | ||
| test_files=() | ||
| for f in ${{ steps.changed.outputs.files }}; do | ||
| case "$f" in | ||
| src/*) src_files+=("${f#src/}") ;; | ||
| tests/*) test_files+=("$f") ;; | ||
| esac | ||
| done | ||
| if [ "${#src_files[@]}" -gt 0 ]; then | ||
| (cd src && uv run mypy "${src_files[@]}") | ||
| fi | ||
| if [ "${#test_files[@]}" -gt 0 ]; then | ||
| uv run mypy "${test_files[@]}" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| """Liveness and readiness probes.""" | ||
|
|
||
| import asyncio | ||
|
|
||
| import httpx | ||
| from fastapi import Request | ||
| from fastapi.responses import JSONResponse | ||
|
|
||
| from config.settings import clients | ||
| from utils.logging_config import get_logger | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| async def health_check(request: Request): | ||
| """Simple liveness probe: Indicates that the OpenRAG Backend service is online and running.""" | ||
| return JSONResponse({"status": "ok"}, status_code=200) | ||
|
|
||
|
|
||
| async def opensearch_health_ready(request): | ||
| """Readiness probe: verifies OpenSearch dependency is reachable.""" | ||
| from config.settings import IBM_AUTH_ENABLED, OPENSEARCH_URL | ||
|
|
||
| if IBM_AUTH_ENABLED: | ||
| logger.debug("[OPENSEARCH] OpenSearch auth mode enabled, health check per-request") | ||
| # In IBM auth mode we cannot rely on the global OpenSearch client | ||
| # (auth is established per-request), so perform a lightweight, | ||
| # unauthenticated connectivity check against the OpenSearch endpoint. | ||
| opensearch_url = OPENSEARCH_URL.rstrip("/") | ||
| try: | ||
| timeout = httpx.Timeout(5.0) | ||
| async with httpx.AsyncClient(timeout=timeout) as client: | ||
| resp = await client.get(f"{opensearch_url}/") | ||
| if resp.status_code < 500: | ||
| logger.debug("[OPENSEARCH] OpenSearch health check successful") | ||
| return JSONResponse( | ||
| { | ||
| "status": "ready", | ||
| "dependencies": {"opensearch": "up"}, | ||
| "note": "OpenSearch auth mode - connectivity verified via unauthenticated probe", | ||
| }, | ||
| status_code=200, | ||
| ) | ||
| else: | ||
| logger.debug("[OPENSEARCH] OpenSearch health check failed") | ||
| return JSONResponse( | ||
| { | ||
| "status": "not_ready", | ||
| "dependencies": {"opensearch": "down"}, | ||
| "error": f"Unexpected status from OpenSearch: {resp.status_code}", | ||
| }, | ||
| status_code=503, | ||
| ) | ||
| except Exception as e: | ||
| logger.error("[OPENSEARCH] OpenSearch health check failed", error=str(e)) | ||
| return JSONResponse( | ||
| { | ||
| "status": "not_ready", | ||
| "dependencies": {"opensearch": "down"}, | ||
| "error": "OpenSearch health check failed", | ||
| }, | ||
| status_code=503, | ||
| ) | ||
|
|
||
| try: | ||
| await asyncio.wait_for(clients.opensearch.info(), timeout=5.0) | ||
| return JSONResponse( | ||
| {"status": "ready", "dependencies": {"opensearch": "up"}}, | ||
| status_code=200, | ||
| ) | ||
| except Exception as e: | ||
| logger.error("[OPENSEARCH] OpenSearch health check failed", error=str(e)) | ||
| return JSONResponse( | ||
| { | ||
| "status": "not_ready", | ||
| "dependencies": {"opensearch": "down"}, | ||
| "error": "OpenSearch health check failed", | ||
| }, | ||
| status_code=503, | ||
| ) | ||
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't report readiness on arbitrary 4xx responses.
resp.status_code < 500marks 404/429/etc. as healthy, so a badOPENSEARCH_URLor proxy misroute can still return 200 from/search/health. Only explicit expected statuses for the unauthenticated probe should count as ready.Suggested guard
📝 Committable suggestion
🤖 Prompt for AI Agents