-
Notifications
You must be signed in to change notification settings - Fork 771
feat(service): Add /v1/health and /healthz endpoints for health checking #2169
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
6 commits
Select commit
Hold shift + click to select a range
3dbc85e
Initial checkin of /v1/health service endpoint
tgasser-nv c56039b
Add couple of extra tests
tgasser-nv fc97d11
Add healthz endpoint as well
tgasser-nv 40742b2
Address feedback, add docs, parameterize health-check endpoint in Docker
tgasser-nv e863d49
Add --no-healthcheck to non-server Docker commands
tgasser-nv cb5854b
Bypass proxies in requests library health check
tgasser-nv 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
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
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
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,67 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import pytest | ||
|
|
||
| pytest.importorskip("openai", reason="openai is required for server tests") | ||
| from fastapi.testclient import TestClient | ||
|
|
||
| from nemoguardrails.server import api | ||
|
|
||
| client = TestClient(api.app) | ||
|
|
||
| ENDPOINT = "/v1/health" | ||
|
|
||
|
|
||
| def test_health_returns_200_pass_status(): | ||
| """GET /v1/health returns HTTP 200 with a JSON body of {"status": "pass"}.""" | ||
| response = client.get(ENDPOINT) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == {"status": "pass"} | ||
|
|
||
|
|
||
| def test_health_uses_health_json_media_type(): | ||
| """GET /v1/health responds with exactly the application/health+json media type.""" | ||
| response = client.get(ENDPOINT) | ||
|
|
||
| assert response.headers["content-type"] == "application/health+json" | ||
|
|
||
|
|
||
| def test_health_rejects_post_with_405(): | ||
| """POST /v1/health returns HTTP 405 because the endpoint is GET-only.""" | ||
| response = client.post(ENDPOINT) | ||
|
|
||
| assert response.status_code == 405 | ||
|
|
||
|
|
||
| def test_health_ok_without_config_or_cached_rails(monkeypatch): | ||
| """GET /v1/health returns 200 with no default config and no cached rails instances.""" | ||
| monkeypatch.setattr(api.app, "default_config_id", None) | ||
| monkeypatch.setattr(api, "llm_rails_instances", {}) | ||
|
|
||
| response = client.get(ENDPOINT) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == {"status": "pass"} | ||
|
|
||
|
|
||
| def test_healthz_alias_matches_health_contract(): | ||
| """GET /healthz returns the same 200 application/health+json {"status": "pass"} response as /v1/health.""" | ||
| response = client.get("/healthz") | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.headers["content-type"] == "application/health+json" | ||
| assert response.json() == {"status": "pass"} |
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.
Uh oh!
There was an error while loading. Please reload this page.