Removed unusable log options and add new section to user_config_template#2121
Removed unusable log options and add new section to user_config_template#2121LeiGlobus wants to merge 2 commits into
Conversation
f090783 to
f5abd40
Compare
29d8e15 to
88f7836
Compare
88f7836 to
031197d
Compare
chris-janidlo
left a comment
There was a problem hiding this comment.
Haven't tested this yet, but looks good overall. Mostly small comments except for maybe some missing tests
| if path_info := _conf.get("paths"): | ||
| if log_path_val := path_info.get("endpoint_log"): | ||
| env["GLOBUS_COMPUTE_LOG_PATH"] = log_path_val | ||
| ep_log = ensure_log_path(None) | ||
| log.info(f"Setting custom endpoint log path to {ep_log}") | ||
| if gc_dir_val := path_info.get("gc_dir"): | ||
| log.info(f"Setting Compute base path to {gc_dir_val}") | ||
| env["GLOBUS_COMPUTE_USER_DIR"] = gc_dir_val |
There was a problem hiding this comment.
Are there any tests verifying this new endpoint_manager behavior?
There was a problem hiding this comment.
No tests for this yet, but the logic is fairly simple, and any errors will be fairly obvious (e.g. the UEP will ignore the config altogether). I'll look into whether it can be added to an existing test.
There was a problem hiding this comment.
Logic/errors aside, if these env vars are a contractual invariant we want the CEP to always set---and we do, because of the fact that UEPs always expect them---we should have a test that verifies it actually happens.
0a29789 to
7777ad1
Compare
| env["GLOBUS_COMPUTE_LOG_PATH"] = log_path_val | ||
| ep_log = ensure_log_path(None) |
There was a problem hiding this comment.
- It is a subtle detail here to rely on the environment variable for the next function call. It's not wrong, just unexpected in the usual course, especially in context of the other branch, which sets its environment variable at the end of the block. A simple comment (inline, if feasible) might help.
- I also observe that
GLOBUS_COMPUTE_LOG_PATHis used in variable form withinensure_log_path. For single-point-of-authority, this should do similar. - You may or may not like a stylistic choice to unindent a block, but I offer it as an option:
if gc_dir_val := _conf.get("paths", {}).get("gc_dir"): ... ... if log_path_val := _conf.get("paths", {}).get("endpoint_log"): ...
There was a problem hiding this comment.
In the common case where endpoint_log is not specified, this represents a slight Shlemiel approach; consider ensure_log_path() to after ensure_compute_dir() has been invoked.
There was a problem hiding this comment.
Rewrote the order in this section to make it flow better with the dependency necessary
| log_dir = os.environ.get(LOG_PATH_ENV) | ||
| if log_dir and log_dir.strip(): | ||
| # This expands both ~/... and $X e.g. ~/$MY_SUB_DIR/abc.log | ||
| log_path = pathlib.Path(os.path.expandvars(log_dir)).expanduser() | ||
| if log_path.is_dir(): | ||
| raise ValueError(f"{LOG_PATH_ENV} can not be a directory: {log_path}") | ||
| else: | ||
| assert ep_dir, "ep_dir must be provided if LOG_PATH_ENV is not set" | ||
| log_path = ep_dir / "endpoint.log" |
There was a problem hiding this comment.
- In the first branch,
log_pathis basically just thepathlib-ization oflog_dir. That's unexpected, then, in line 289 that requires thatlog_pathbe not a directory. - A simplification of the if-conditional might be:
if log_dir := os.environ.get(LOG_PATH_ENV, "").strip():
- I find it unexpected that one branch relies on an environment variable while the other does not. Consider making this function take no arguments and only rely on environment variables. (Especially since we're nominally always setting
GLOBUS_COMPUTE_USER_DIRnow, yeah?)
There was a problem hiding this comment.
Needs a bit more discussion offline.
cd0f685 to
20be140
Compare
18c141d to
c1eec28
Compare
|
|
||
| # Use the environment value set from default or customized log path | ||
| ep_log = ensure_log_path() | ||
|
|
There was a problem hiding this comment.
Given recent iterations, GLOBUS_COMPUTE_USER_DIR is no longer modifiable from the configuration. Thus, this section could be simplified with an else: branch. Consider:
if log_path_val := _conf.get("paths", {}).get("endpoint_log"):
# Overrides the default in ensure_log_path()
env[LOG_PATH_ENV] = log_path_val
if ep_dir_val := _conf.get("paths", {}).get("endpoint_dir"):
log.info(f"Setting endpoint directory to {ep_dir_val}")
ep_dir = pathlib.Path(ep_dir_val)
else:
ep_dir = ensure_compute_dir() / ep_name
ep_dir.mkdir(mode=0o700, parents=True, exist_ok=True)
env[COMPUTE_EP_DIR_ENV] = str(ep_dir.resolve())
ep_log = ensure_log_path()There was a problem hiding this comment.
Given that ensure_log_path could change the value given to it by the environment variable (c.f., expandvars() and expanduser()), we should similarly update the environment variable.
There was a problem hiding this comment.
Updated, but needs some discussion as to where the updating should be done.
| log_dir = os.environ.get(LOG_PATH_ENV, "").strip() | ||
| ep_dir = os.environ.get(COMPUTE_EP_DIR_ENV, "").strip() | ||
| if log_dir: | ||
| # This expands both ~/... and $X e.g. ~/$MY_SUB_DIR/abc.log | ||
| log_path = pathlib.Path(os.path.expandvars(log_dir)).expanduser() | ||
| if log_path.is_dir(): | ||
| raise ValueError(f"{LOG_PATH_ENV} can not be a directory: {log_path}") | ||
| logger.info(f"Setting custom endpoint log path to {log_path}") |
There was a problem hiding this comment.
Please address the incongruence of log_dir.
There was a problem hiding this comment.
(Same comment as made in previous review iteration.)
There was a problem hiding this comment.
Rewrote and simplified the logic
b153118 to
f70c28d
Compare
new paths config block [sc-39546]
f70c28d to
a13d358
Compare
a13d358 to
a345b15
Compare
Description
Removed several log related options that do not work, and added a new log section where one can specify the user log path.
This new log path is passed as an environment variable to the UEP called
GLOBUS_COMPUTE_LOG_PATHthough it's debatable whether we want to use direct parameters fed via stdin instead which then in turn sets the env var in the UEP.Need to move a few fixtures around as they are shared by new test.
Also wrapped cli.py so Exceptions are printed instead of being swallowed by Click and merely printing the --help message.
(TBD adding another test will remove this sentence after addition)
[sc-39546]
Type of change