Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions elementary/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ def get_log_path(ctx):
return os.path.join(target_path, "edr.log")


def get_quiet_logs(ctx):
try:
ctx_args = ctx.args
idx = ctx_args.index("--quiet-logs")
return ctx_args[idx + 1].lower() == "true"
except (ValueError, IndexError):
return False


class ElementaryCLI(click.MultiCommand):
_CMD_MAP = {
"monitor": monitor,
Expand Down Expand Up @@ -57,12 +66,14 @@ def format_help(self, ctx, formatter):

def invoke(self, ctx: click.Context) -> Any:
files_target_path = get_log_path(ctx)
set_root_logger_handlers("elementary", files_target_path)
click.echo(
"Any feedback and suggestions are welcomed! join our community here - "
"https://bit.ly/slack-elementary\n"
)
logger.info(f"Running with edr={package.get_package_version()}")
quiet_logs = get_quiet_logs(ctx)
set_root_logger_handlers("elementary", files_target_path, quiet_logs=quiet_logs)
if not quiet_logs:
click.echo(
"Any feedback and suggestions are welcomed! join our community here - "
"https://bit.ly/slack-elementary\n"
)
logger.info(f"Running with edr={package.get_package_version()}")
return super().invoke(ctx)


Expand Down
10 changes: 10 additions & 0 deletions elementary/monitor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def decorator(func):
else "DEPRECATED! Please use --filters instead! - Filter the alerts by tags:<TAGS> / owners:<OWNERS> / models:<MODELS> / "
"statuses:<warn/fail/error/skipped> / resource_types:<model/test>.",
)(func)
func = click.option(
"--quiet-logs",
type=bool,
default=False,
help="Minimize INFO level logs. Only WARNING and above will be shown.",
)(func)
return func

return decorator
Expand Down Expand Up @@ -324,12 +330,14 @@ def monitor(
excludes,
teams_webhook,
maximum_columns_in_alert_samples,
quiet_logs,
):
"""
Get alerts on failures in dbt jobs.
"""
if ctx.invoked_subcommand is not None:
return

if deprecated_slack_webhook is not None:
click.secho(
'\n"-s" is deprecated and won\'t be supported in the near future.\n'
Expand Down Expand Up @@ -450,6 +458,7 @@ def report(
env,
select,
target_path,
quiet_logs,
):
"""
Generate a local observability report of your warehouse.
Expand Down Expand Up @@ -680,6 +689,7 @@ def send_report(
disable,
include,
target_path,
quiet_logs,
):
"""
Generate and send the report to an external platform.
Expand Down
6 changes: 4 additions & 2 deletions elementary/monitor/fetchers/alerts/alerts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
from typing import Dict, List, Optional

import click

from elementary.clients.dbt.base_dbt_runner import BaseDbtRunner
from elementary.clients.fetcher.fetcher import FetcherClient
from elementary.config.config import Config
Expand Down Expand Up @@ -29,7 +31,7 @@ def skip_alerts(
):
alert_ids = [alert.id for alert in alerts_to_skip]
alert_ids_chunks = self._split_list_to_chunks(alert_ids)
logger.info("Update skipped alerts")
click.echo(f"Update skipped alerts ({len(alerts_to_skip)})")
for alert_ids_chunk in alert_ids_chunks:
self.dbt_runner.run(
select="elementary_cli.update_alerts.update_skipped_alerts",
Expand Down Expand Up @@ -60,7 +62,7 @@ def query_last_alert_times(

def update_sent_alerts(self, alert_ids: List[str]) -> None:
alert_ids_chunks = self._split_list_to_chunks(alert_ids)
logger.info("Update sent alerts")
click.echo(f"Update sent alerts ({len(alert_ids)})")
for alert_ids_chunk in alert_ids_chunks:
self.dbt_runner.run(
select="elementary_cli.update_alerts.update_sent_alerts",
Expand Down
20 changes: 16 additions & 4 deletions elementary/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ def format(self, record):
ROTATION_BACKUP_COUNT = 4


def get_console_handler():
def get_console_handler(quiet_logs: bool = False):
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setFormatter(FORMATTER)
console_handler.setLevel(logging.DEBUG if is_debug() else logging.INFO)
if is_debug():
console_handler.setLevel(logging.DEBUG)
elif quiet_logs:
console_handler.setLevel(logging.WARNING)
else:
console_handler.setLevel(logging.INFO)
return console_handler


Expand All @@ -55,7 +60,14 @@ def get_logger(logger_name):
return logger


def set_root_logger_handlers(logger_name, files_target_path):
def set_root_logger_handlers(logger_name, files_target_path, quiet_logs: bool = False):
logger = logging.getLogger(logger_name)
logger.addHandler(get_console_handler())

# Disable propagation to root logger to avoid duplicate logs
logger.propagate = False

logger.addHandler(get_console_handler(quiet_logs=quiet_logs))
logger.addHandler(get_file_handler(files_target_path))

# Set logger level to DEBUG so it doesn't filter messages (handler will filter)
logger.setLevel(logging.DEBUG)
Loading