Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 15 additions & 6 deletions elementary/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def get_log_path(ctx):
return os.path.join(target_path, "edr.log")


def get_quiet_logs(ctx):
try:
return "--quiet-logs" in ctx.args
except (ValueError, AttributeError):
return False


class ElementaryCLI(click.MultiCommand):
_CMD_MAP = {
"monitor": monitor,
Expand Down Expand Up @@ -57,12 +64,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
1 change: 1 addition & 0 deletions elementary/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(
env: str = DEFAULT_ENV,
run_dbt_deps_if_needed: Optional[bool] = None,
project_name: Optional[str] = None,
quiet_logs: Optional[bool] = None,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: The quiet_logs parameter is not stored in the Config instance.

The parameter is accepted but never assigned to self.quiet_logs or used elsewhere in the constructor. This means the quiet_logs preference cannot be accessed by any code that uses the Config object, breaking the intended functionality.

🔎 Proposed fix to store the parameter

Add the assignment in the constructor body, similar to other parameters:

         self.env = env
         self.project_name = project_name
+        self.quiet_logs = quiet_logs

Consider adding this around line 87, near other simple assignments.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Ruff (0.14.10)

78-78: Unused method argument: quiet_logs

(ARG002)

🤖 Prompt for AI Agents
In elementary/config/config.py around line 78, the constructor accepts the
quiet_logs parameter but never stores it on the Config instance; add an
assignment like self.quiet_logs = quiet_logs in the constructor body (near other
simple assignments around line ~87) so the value is accessible via the Config
object and preserves the Optional[bool] type.

):
self.config_dir = config_dir
self.profiles_dir = profiles_dir
Expand Down
13 changes: 13 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",
is_flag=True,
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 All @@ -356,6 +364,7 @@ def monitor(
report_url=report_url,
teams_webhook=teams_webhook,
maximum_columns_in_alert_samples=maximum_columns_in_alert_samples,
quiet_logs=quiet_logs,
)
anonymous_tracking = AnonymousCommandLineTracking(config)
anonymous_tracking.set_env("use_select", bool(select))
Expand Down Expand Up @@ -450,6 +459,7 @@ def report(
env,
select,
target_path,
quiet_logs,
):
"""
Generate a local observability report of your warehouse.
Expand All @@ -463,6 +473,7 @@ def report(
target_path,
dbt_quoting=dbt_quoting,
env=env,
quiet_logs=quiet_logs,
)
anonymous_tracking = AnonymousCommandLineTracking(config)
anonymous_tracking.set_env("use_select", bool(select))
Expand Down Expand Up @@ -680,6 +691,7 @@ def send_report(
disable,
include,
target_path,
quiet_logs,
):
"""
Generate and send the report to an external platform.
Expand Down Expand Up @@ -722,6 +734,7 @@ def send_report(
report_url=report_url,
env=env,
project_name=project_name,
quiet_logs=quiet_logs,
)
anonymous_tracking = AnonymousCommandLineTracking(config)
anonymous_tracking.set_env("use_select", bool(select))
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)