Skip to content

Commit

Permalink
Merge branch 'tickets/DM-45722'
Browse files Browse the repository at this point in the history
  • Loading branch information
kfindeisen committed Aug 28, 2024
2 parents b9c5a67 + f6f0254 commit c68239a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions doc/changes/DM-45722.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Explanatory logs for "initial data ID query returned no rows" now appear as a single log message instead of one entry per line. This improves display in log aggregators, but there is no change to console behavior.
1 change: 1 addition & 0 deletions doc/changes/DM-45722.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Explanatory logs for "initial data ID query returned no rows" are now reported at ERROR, not CRITICAL, level.
3 changes: 0 additions & 3 deletions doc/changes/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ The ``<TYPE>`` should be one of:
* ``perf``: A performance enhancement.
* ``doc``: A documentation improvement.
* ``removal``: An API removal or deprecation.
* ``other``: Other Changes and Additions of interest to general users.
* ``misc``: Changes that are of minor interest.

An example file name would therefore look like ``DM-30291.misc.rst``.

If the change concerns specifically the registry or a datastore the news fragment can be placed in the relevant subdirectory.

You can test how the content will be integrated into the release notes by running ``towncrier --draft --version=V.vv``.
``towncrier`` can be installed from PyPI or conda-forge.
51 changes: 30 additions & 21 deletions python/lsst/pipe/base/all_dimensions_quantum_graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import dataclasses
from collections.abc import Iterator, Mapping
from contextlib import contextmanager
from io import StringIO
from typing import TYPE_CHECKING, Any, final

from lsst.daf.butler.registry import MissingDatasetTypeError
Expand Down Expand Up @@ -507,31 +508,39 @@ def from_builder(
yield result

def log_failure(self, log: LsstLogAdapter) -> None:
"""Emit a series of CRITICAL-level log message that attempts to explain
"""Emit an ERROR-level log message that attempts to explain
why the initial data ID query returned no rows.
Parameters
----------
log : `logging.Logger`
The logger to use to emit log messages.
"""
log.critical("Initial data ID query returned no rows, so QuantumGraph will be empty.")
for message in self.common_data_ids.explain_no_results():
log.critical(message)
log.critical(
"To reproduce this query for debugging purposes, run "
"Registry.queryDataIds with these arguments:"
)
# We could just repr() the queryArgs dict to get something
# the user could make sense of, but it's friendlier to
# put these args in an easier-to-reconstruct equivalent form
# so they can read it more easily and copy and paste into
# a Python terminal.
log.critical(" dimensions=%s,", list(self.query_args["dimensions"].names))
log.critical(" dataId=%s,", dict(self.query_args["dataId"].required))
if self.query_args["where"]:
log.critical(" where=%s,", repr(self.query_args["where"]))
if "datasets" in self.query_args:
log.critical(" datasets=%s,", list(self.query_args["datasets"]))
if "collections" in self.query_args:
log.critical(" collections=%s,", list(self.query_args["collections"]))
# A single multiline log plays better with log aggregators like Loki.
buffer = StringIO()
try:
buffer.write("Initial data ID query returned no rows, so QuantumGraph will be empty.\n")
for message in self.common_data_ids.explain_no_results():
buffer.write(message)
buffer.write("\n")
buffer.write(
"To reproduce this query for debugging purposes, run "
"Registry.queryDataIds with these arguments:\n"
)
# We could just repr() the queryArgs dict to get something
# the user could make sense of, but it's friendlier to
# put these args in an easier-to-reconstruct equivalent form
# so they can read it more easily and copy and paste into
# a Python terminal.
buffer.write(f" dimensions={list(self.query_args['dimensions'].names)},")
buffer.write(f" dataId={dict(self.query_args['dataId'].required)},")
if self.query_args["where"]:
buffer.write(f" where={repr(self.query_args['where'])},")
if "datasets" in self.query_args:
buffer.write(f" datasets={list(self.query_args['datasets'])},")
if "collections" in self.query_args:
buffer.write(f" collections={list(self.query_args['collections'])},")
finally:
# If an exception was raised, write a partial.
log.error(buffer.getvalue())
buffer.close()

0 comments on commit c68239a

Please sign in to comment.