Skip to content

Commit

Permalink
/* PR_START p--short-term-perf 22 */ Fix more logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Oct 7, 2024
1 parent aa11516 commit d44fd4a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
18 changes: 9 additions & 9 deletions metricflow/dataflow/optimizer/source_scan/cm_branch_combiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dataclasses import dataclass
from typing import List, Optional, Sequence

from metricflow_semantics.mf_logging.lazy_formattable import LazyFormat
from metricflow_semantics.specs.metric_spec import MetricSpec

from metricflow.dataflow.dataflow_plan import (
Expand Down Expand Up @@ -129,21 +130,21 @@ class ComputeMetricsBranchCombiner(DataflowPlanNodeVisitor[ComputeMetricsBranchC

def __init__(self, left_branch_node: DataflowPlanNode) -> None: # noqa: D107
self._current_left_node: DataflowPlanNode = left_branch_node
self._log_level = logging.DEBUG

def _log_visit_node_type(self, node: DataflowPlanNode) -> None:
logger.log(level=self._log_level, msg=f"Visiting {node}")
logger.debug(LazyFormat(lambda: f"Visiting {node}"))

def _log_combine_failure(
self,
left_node: DataflowPlanNode,
right_node: DataflowPlanNode,
combine_failure_reason: str,
) -> None:
logger.log(
level=self._log_level,
msg=f"Because {combine_failure_reason}, unable to combine nodes "
f"left_node={left_node} right_node={right_node}",
logger.debug(
LazyFormat(
lambda: f"Because {combine_failure_reason}, unable to combine nodes "
f"left_node={left_node} right_node={right_node}",
)
)

def _log_combine_success(
Expand All @@ -152,9 +153,8 @@ def _log_combine_success(
right_node: DataflowPlanNode,
combined_node: DataflowPlanNode,
) -> None:
logger.log(
level=self._log_level,
msg=f"Combined left_node={left_node} right_node={right_node} combined_node: {combined_node}",
logger.debug(
LazyFormat(lambda: f"Combined left_node={left_node} right_node={right_node} combined_node: {combined_node}")
)

def _combine_parent_branches(self, current_right_node: DataflowPlanNode) -> Optional[Sequence[DataflowPlanNode]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class SourceScanOptimizer(
"""

def _log_visit_node_type(self, node: DataflowPlanNode) -> None:
logger.debug(LazyFormat(lambda: "Visiting {node}"))
logger.debug(LazyFormat(lambda: f"Visiting {node}"))

def _default_base_output_handler(
self,
Expand Down
2 changes: 1 addition & 1 deletion metricflow/engine/metricflow_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def _create_execution_plan(self, mf_query_request: MetricFlowQueryRequest) -> Me
order_by=mf_query_request.order_by,
min_max_only=mf_query_request.min_max_only,
).query_spec
logger.info(LazyFormat("Parsed query", query_spec=query_spec))
logger.debug(LazyFormat("Parsed query", query_spec=query_spec))

output_selection_specs: Optional[InstanceSpecSet] = None
if mf_query_request.query_type == MetricFlowQueryType.DIMENSION_VALUES:
Expand Down
8 changes: 2 additions & 6 deletions metricflow/telemetry/handlers/python_log.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

import logging
import textwrap

from metricflow_semantics.mf_logging.pretty_print import mf_pformat
from metricflow_semantics.mf_logging.lazy_formattable import LazyFormat

from metricflow.telemetry.handlers.handlers import PayloadType, TelemetryHandler

Expand All @@ -17,7 +16,4 @@ def __init__(self, logger_level: int) -> None: # noqa: D107
self._logger_level = logger_level

def _write_log(self, client_id: str, payload: PayloadType) -> None:
logger.log(
level=self._logger_level,
msg=f"Logging telemetry payload:\n{textwrap.indent(mf_pformat(payload), prefix=' ')}",
)
logger.log(level=self._logger_level, msg=LazyFormat("Logging telemetry payload", payload=payload))
2 changes: 1 addition & 1 deletion metricflow/telemetry/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _create_client_id() -> str:
return sha256(id_str.encode("utf-8")).hexdigest()

def add_python_log_handler(self) -> None: # noqa: D102
self._handlers.append(PythonLoggerTelemetryHandler(logger_level=logging.INFO))
self._handlers.append(PythonLoggerTelemetryHandler(logger_level=logging.DEBUG))

def add_test_handler(self) -> None:
"""See test_handler."""
Expand Down

0 comments on commit d44fd4a

Please sign in to comment.