Skip to content

Commit

Permalink
Healthcheck gives correct result even behind proxy (#1964)
Browse files Browse the repository at this point in the history
* Fixed #1962

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update base-notebook/docker_healthcheck.py

Use empty string instead of None

Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 13, 2023
1 parent afe6311 commit 72ef9bc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
7 changes: 6 additions & 1 deletion base-notebook/docker_healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
url = json.loads(json_file.read_bytes())["url"]
url = url + "api"

r = requests.get(url, verify=False) # request without SSL verification
proxies = {
"http": "",
"https": "",
}

r = requests.get(url, proxies=proxies, verify=False) # request without SSL verification
r.raise_for_status()
print(r.content)
47 changes: 47 additions & 0 deletions tests/base-notebook/test_healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,53 @@ def test_health(
assert get_health(running_container) == "healthy"


@pytest.mark.parametrize(
"env,cmd,user",
[
(
["HTTPS_PROXY=host.docker.internal", "HTTP_PROXY=host.docker.internal"],
None,
None,
),
(
[
"NB_USER=testuser",
"CHOWN_HOME=1",
"JUPYTER_PORT=8123",
"HTTPS_PROXY=host.docker.internal",
"HTTP_PROXY=host.docker.internal",
],
["start-notebook.sh", "--ServerApp.base_url=/test"],
"root",
),
],
)
def test_health_proxy(
container: TrackedContainer,
env: Optional[list[str]],
cmd: Optional[list[str]],
user: Optional[str],
) -> None:
running_container = container.run_detached(
tty=True,
environment=env,
command=cmd,
user=user,
)

# sleeping some time to let the server start
time_spent = 0.0
wait_time = 0.1
time_limit = 15
while time_spent < time_limit:
time.sleep(wait_time)
time_spent += wait_time
if get_health(running_container) == "healthy":
return

assert get_health(running_container) == "healthy"


@pytest.mark.parametrize(
"env,cmd,user",
[
Expand Down

0 comments on commit 72ef9bc

Please sign in to comment.