Skip to content

Commit

Permalink
Log anonymous configuration in debug
Browse files Browse the repository at this point in the history
If the endpoint configuration is passed in via stdin and the configuration
specifies `debug: True`, then emit the entire passed configuration yaml to the
logs.

[sc-34149]
  • Loading branch information
khk-globus committed Jun 13, 2024
1 parent b1ac847 commit aa231d6
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compute_endpoint/globus_compute_endpoint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,18 @@ def _do_start_endpoint(
console_enabled=state.log_to_console,
no_color=state.no_color,
)
if config_str is not None:
num_lines = config_str.count("\n") + 1 # +1 == 0-based
_rendered_config = config_str.replace("\n", "\n | ")

log.debug(
f"Begin Compute endpoint configuration ({num_lines:,} lines):"
f"\n | {_rendered_config}"
f"\nEnd Compute endpoint configuration"
)
del _rendered_config
del config_str

except Exception as e:
if isinstance(e, ClickException):
raise
Expand Down
25 changes: 25 additions & 0 deletions compute_endpoint/tests/unit/test_cli_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import pathlib
import random
import re
import shlex
import typing as t
import uuid
Expand Down Expand Up @@ -326,6 +327,30 @@ def test_cli_debug_overrides_config(mock_setup_log, run_line, mock_cli_state, ep
assert k["debug"] is True, "Expect --debug flag overrides config"


def test_debug_emits_ephemeral_config(run_line, mock_cli_state, ep_name, randomstring):
mock_ep, mock_ensure = mock_cli_state

mock_ensure.debug = False
ep_dir = mock_ensure.endpoint_config_dir / ep_name
ep_dir.mkdir(parents=True)
dname = randomstring()
config = {
"debug": True,
"display_name": dname,
"engine": {"type": "ThreadPoolEngine"},
}
data = {"config": yaml.safe_dump(config)}

with mock.patch(f"{_MOCK_BASE}log.debug") as mock_logd:
run_line(f"start {ep_name}", stdin=json.dumps(data))

a, *_ = mock_logd.call_args
# Per documentation, verify sentinels
assert a[0].startswith("Begin Compute endpoint"), "Expect start sentinel"
assert a[0].endswith("\nEnd Compute endpoint configuration"), "Expect end sentinel"
assert re.search(rf"\n +\| display_name: {dname}\n", a[0]), "Expect config emitted"


def test_configure_validates_name(mock_command_ensure, run_line):
compute_dir = mock_command_ensure.endpoint_config_dir
compute_dir.mkdir(parents=True, exist_ok=True)
Expand Down
44 changes: 44 additions & 0 deletions docs/endpoints/multi_user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,50 @@ a custom ``globus-compute-endpoint`` wrapper:
(The use of ``exec`` is not critical, but keeps the process tree tidy.)

Debugging User Endpoints
========================

During implementation, most users are accustomed to using the ``--debug`` flag (or
equivalent) to get more information. (And usually, caveat emptor, as the amount of
information can be overwhelming.) The ``globus-compute-endpoint`` executable similarly
implements that flag. However, if applied to the MEP, that flag will not carry-over to
the child UEP instances. In particular, the command executed by the MEP is:

.. code-block:: python
:caption: arguments to ``os.execvpe``
proc_args = ["globus-compute-endpoint", "start", ep_name, "--die-with-parent"]
Note the lack of the ``--debug`` flag; by default UEPs will not emit DEBUG level logs.
To place UEPs into debug mode, use the ``debug`` top-level configuration directive:

.. code-block:: yaml
:caption: ``user_config_template.yaml``
:emphasize-lines: 1
debug: true
display_name: Debugging template
idle_heartbeats_soft: 10
idle_heartbeats_hard: 5760
engine:
...
Note that this is *also* how to get the UEP to emit its configuration to the log, which
may be helpful in determining which set of logs are associated with which configuration
or just generally while implementing and debugging. The configuration is emitted to the
logs very early on in the UEP bootup stage; look for the following sentinel lines::

[TIMESTAMP] DEBUG ... Begin Compute endpoint configuration (5 lines):
...
End Compute endpoint configuration

To this end, the authors have found the following command line helpful for pulling out
the configuration from the logs:

.. code-block:: console
$ sed -n "/Begin Compute/,/End Compute/p" ~/.globus_compute/uep.[...]/endpoint.log | less
Installing the MEP as a Service
===============================

Expand Down

0 comments on commit aa231d6

Please sign in to comment.