From dec7902e4a7325e5da375d99cd7a352bd1791de6 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Thu, 12 Dec 2024 12:05:00 -0500 Subject: [PATCH 1/3] Add healthcheck to docker-compose. --- docker-compose.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index c2dda2ec2..d5d5e41f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,12 @@ services: ports: - 8000:8000 restart: unless-stopped + healthcheck: + test: curl --fail http://localhost:8000/healthz || exit 1 + interval: 60s + timeout: 10s + retries: 3 + start_period: 30s # Below we additionally configure monitoring with Prometheus and Grafana. # This is optional; it is not required for Tiled to function. From 4efda3b8c3efb7d87140bf3c2cdc733dc0525955 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Thu, 12 Dec 2024 12:05:37 -0500 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18548cffb..f09df0e25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ Write the date in place of the "Unreleased" in the case a new version is release # Changelog +## Unreleased + +### Added + +- `docker-compose.yml` now uses the healthcheck endpoint `/healthz` + ## 2024-12-09 ### Added From 9f8e11a026f169882c20827d8fb9e2dcec28ae4f Mon Sep 17 00:00:00 2001 From: Dylan McReynolds <40469975+dylanmcreynolds@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:03:38 -0800 Subject: [PATCH 3/3] Fix subprocess logging during database creation (#726) * fix subprocess logging * Fix branching --------- Co-authored-by: Dan Allan --- tiled/_tests/test_catalog.py | 31 +++++++++++++++++++++++++++++++ tiled/catalog/adapter.py | 4 ++-- tiled/commandline/_serve.py | 17 +++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/tiled/_tests/test_catalog.py b/tiled/_tests/test_catalog.py index 61b24e98f..a4c915ec0 100644 --- a/tiled/_tests/test_catalog.py +++ b/tiled/_tests/test_catalog.py @@ -528,3 +528,34 @@ async def test_constraints_on_parameter_and_num(a, assets): ) ], ) + + +@pytest.mark.asyncio +async def test_init_db_logging(tmpdir, caplog): + config = { + "database": { + "uri": "sqlite+aiosqlite://", # in-memory + }, + "trees": [ + { + "tree": "catalog", + "path": "/", + "args": { + "uri": f"sqlite+aiosqlite:///{tmpdir}/catalog.db", + "writable_storage": str(tmpdir / "data"), + "init_if_not_exists": True, + }, + }, + ], + } + # Issue 721 notes that the logging of the subprocess that creates + # a database logs normal things to error. This test looks at the log + # and fails if an error log happens. This could catch anything that is + # an error during the app build. + import logging + + with caplog.at_level(logging.INFO): + app = build_app_from_config(config) + for record in caplog.records: + assert record.levelname != "ERROR", f"Error found creating app {record.msg}" + assert app diff --git a/tiled/catalog/adapter.py b/tiled/catalog/adapter.py index 13bd2353c..7acd34f7a 100644 --- a/tiled/catalog/adapter.py +++ b/tiled/catalog/adapter.py @@ -1397,8 +1397,8 @@ def from_uri( # Capture stdout and stderr from the subprocess and write to logging stdout = process.stdout.decode() stderr = process.stderr.decode() - logging.info(f"Subprocess stdout: {stdout}") - logging.error(f"Subprocess stderr: {stderr}") + logger.info(f"Subprocess stdout: {stdout}") + logger.info(f"Subprocess stderr: {stderr}") parsed_url = make_url(uri) if (parsed_url.get_dialect().name == "sqlite") and ( diff --git a/tiled/commandline/_serve.py b/tiled/commandline/_serve.py index 2fb7754cf..828bba1bf 100644 --- a/tiled/commandline/_serve.py +++ b/tiled/commandline/_serve.py @@ -178,6 +178,10 @@ def serve_directory( adapters_by_mimetype=adapters_by_mimetype, ) if verbose: + from tiled.catalog.adapter import logger as catalog_logger + + catalog_logger.addHandler(StreamHandler()) + catalog_logger.setLevel("INFO") register_logger.addHandler(StreamHandler()) register_logger.setLevel("INFO") # Set the API key manually here, rather than letting the server do it, @@ -345,6 +349,12 @@ def serve_catalog( log_timestamps: bool = typer.Option( False, help="Include timestamps in log output." ), + verbose: bool = typer.Option( + False, + "--verbose", + "-v", + help=("Log details of catalog creation."), + ), ): "Serve a catalog." import urllib.parse @@ -418,6 +428,13 @@ def serve_catalog( err=True, ) raise typer.Abort() + elif verbose: + from logging import StreamHandler + + from tiled.catalog.adapter import logger as catalog_logger + + catalog_logger.addHandler(StreamHandler()) + catalog_logger.setLevel("INFO") if write is None: typer.echo(