diff --git a/elementary/monitor/cli.py b/elementary/monitor/cli.py index 3d97c0f78..1baa1bfdf 100644 --- a/elementary/monitor/cli.py +++ b/elementary/monitor/cli.py @@ -9,6 +9,7 @@ from elementary.monitor.data_monitoring.report.data_monitoring_report import ( DataMonitoringReport, ) +from elementary.monitor.debug import Debug from elementary.tracking.anonymous_tracking import AnonymousCommandLineTracking from elementary.utils import bucket_path from elementary.utils.ordered_yaml import OrderedYaml @@ -20,6 +21,7 @@ class Command: MONITOR = "monitor" REPORT = "monitor-report" SEND_REPORT = "monitor-send-report" + DEBUG = "debug" # Displayed in reverse order in --help. @@ -599,5 +601,26 @@ def send_report( raise +@monitor.command() +@click.option( + "--profiles-dir", + "-p", + type=click.Path(exists=True), + default=None, + help="Which directory to look in for the profiles.yml file. " + "If not set, edr will look in the current working directory first, then HOME/.dbt/", +) +@click.pass_context +def debug(ctx, profiles_dir): + config = Config(profiles_dir=profiles_dir) + anonymous_tracking = AnonymousCommandLineTracking(config) + anonymous_tracking.track_cli_start(Command.DEBUG, None, ctx.command.name) + success = Debug(config).run() + if not success: + sys.exit(1) + + anonymous_tracking.track_cli_end(Command.DEBUG, None, ctx.command.name) + + if __name__ == "__main__": monitor() diff --git a/elementary/monitor/debug.py b/elementary/monitor/debug.py new file mode 100644 index 000000000..5e176563b --- /dev/null +++ b/elementary/monitor/debug.py @@ -0,0 +1,29 @@ +import click + +from elementary.clients.dbt.dbt_runner import DbtRunner +from elementary.config.config import Config +from elementary.exceptions.exceptions import DbtCommandError +from elementary.monitor import dbt_project_utils + + +class Debug: + def __init__(self, config: Config): + self.config = config + + def run(self) -> bool: + dbt_runner = DbtRunner( + dbt_project_utils.PATH, + self.config.profiles_dir, + self.config.profile_target, + ) + + try: + dbt_runner.run_operation("test_conn", quiet=True) + except DbtCommandError as err: + click.echo( + f"Could not connect to the Elementary db and schema. See details below\n\n{err}" + ) + return False + + click.echo("Connected to the Elementary db and schema successfully") + return True