Skip to content

Commit

Permalink
Move self diagnostic mostly to the SDK side and add more compatibilit…
Browse files Browse the repository at this point in the history
…y for multiple platforms
  • Loading branch information
LeiGlobus committed Sep 6, 2024
1 parent f06f3aa commit b926067
Show file tree
Hide file tree
Showing 21 changed files with 1,075 additions and 577 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Changed
^^^^^^^

- The Globus Compute self-diagnostic is now available as a stand-alone console
script installed as part of the globus-compute-sdk package, instead of only
as the ``self-diagnostic`` sub-command of the globus-compute-endpoint CLI.

For more information, see ``globus-compute-diagnostic --help``

47 changes: 28 additions & 19 deletions compute_endpoint/globus_compute_endpoint/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import annotations

import contextlib
import difflib
import gzip
import json
import logging
import os
Expand All @@ -12,7 +10,6 @@
import sys
import textwrap
import uuid
from datetime import datetime

import click
from click import ClickException
Expand All @@ -27,10 +24,10 @@
)
from globus_compute_endpoint.exception_handling import handle_auth_errors
from globus_compute_endpoint.logging_config import setup_logging
from globus_compute_endpoint.self_diagnostic import run_self_diagnostic
from globus_compute_sdk.sdk._environments import ensure_compute_dir
from globus_compute_sdk.sdk.diagnostic import run_all_diags_wrapper
from globus_compute_sdk.sdk.login_manager import LoginManager
from globus_compute_sdk.sdk.login_manager.client_login import is_client_login
from globus_compute_sdk.sdk.login_manager.tokenstore import ensure_compute_dir
from globus_compute_sdk.sdk.login_manager.whoami import print_whoami_info
from globus_sdk import MISSING, AuthClient, GlobusAPIError, MissingType

Expand Down Expand Up @@ -870,35 +867,47 @@ def delete_endpoint(
"compress",
default=False,
is_flag=True,
help="Save the output to a Gzip-compressed file.",
help=(
"Generate a Gzip-compressed file only, and skip printing diagnostic "
"results to the console."
),
)
@click.option(
"-k",
"--log-kb",
default=5120,
help=(
"Specify the number of kilobytes (KB) to read from log files."
" Defaults to 5,120 KB (5 MB)."
),
)
@click.option(
"-e",
"--endpoint-uuid",
default=None,
help=(
"Test an endpoint by registering a sample function and sending "
"a task to it using the newly registered function. An endpoint "
"UUID is required."
),
)
@click.help_option("-h", "--help")
def self_diagnostic(compress: bool, log_kb: int):
def self_diagnostic(compress, log_kb: int, endpoint_uuid: str):
"""Run several diagnostic commands to help identify issues.
This may produce a large amount of output.
"""
log_bytes = log_kb * 1024
Note that this functionality has been migrated to the SDK, leaving only
a wrapper here.
if not compress:
run_self_diagnostic(log_bytes=log_bytes)
else:
current_date = datetime.now().strftime("%Y-%m-%d")
filename = f"globus_compute_diagnostic_{current_date}.txt.gz"
The -z and --log-kb arguments have been preserved from the previous
command, though the diagnostic always generates a gzipped file now,
with printing to console being optional.
with gzip.open(filename, "wb") as f:
with contextlib.redirect_stdout(f): # type: ignore[type-var]
run_self_diagnostic(log_bytes=log_bytes)

click.echo(f"Successfully created {filename}")
TODO should we add a deprecation message here? ie.
The endpoint specific self-diagnostic command has been deprecated.
Please use the `globus-compute-diagnostic` command instead.
"""
run_all_diags_wrapper(not compress, log_kb * 1024, endpoint_uuid)


@app.command(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import globus_compute_sdk as GC
from cachetools import TTLCache
from globus_compute_endpoint.endpoint.identity_mapper import PosixIdentityMapper
from globus_compute_sdk.sdk._environments import ensure_compute_dir

try:
import pyprctl
Expand Down Expand Up @@ -971,7 +972,7 @@ def cmd_start_endpoint(
startup_proc_title = f"Endpoint starting up for {uname} [{args_title}]"
setproctitle.setproctitle(startup_proc_title)

gc_dir: pathlib.Path = GC.sdk.login_manager.tokenstore.ensure_compute_dir()
gc_dir: pathlib.Path = ensure_compute_dir()
ep_dir = gc_dir / ep_name
ep_dir.mkdir(mode=0o700, parents=True, exist_ok=True)
ep_log = ep_dir / "endpoint.log"
Expand Down
187 changes: 0 additions & 187 deletions compute_endpoint/globus_compute_endpoint/self_diagnostic.py

This file was deleted.

Loading

0 comments on commit b926067

Please sign in to comment.