Skip to content

Commit

Permalink
[Bug] Add warning and hint for legacy metrics (#867)
Browse files Browse the repository at this point in the history
* Add warning and hint for legacy metrics

Signed-off-by: Ching Yi, Chan <[email protected]>

* Add tests

Signed-off-by: Ching Yi, Chan <[email protected]>

---------

Signed-off-by: Ching Yi, Chan <[email protected]>
  • Loading branch information
qrtt1 authored Aug 30, 2023
1 parent 9ae345d commit f128375
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions piperider_cli/compare_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def _update_implicit_and_explicit_changeset(self):

self.summary_change_set = SummaryChangeSet(self._base, self._target)
except BaseException as e:
self.warning_for_legacy_metrics(e)

console = Console()
console.print('[bold yellow]Warning:[/bold yellow]')
if isinstance(e, ValueError) and e.args:
Expand All @@ -201,6 +203,21 @@ def _update_implicit_and_explicit_changeset(self):
console.print(e)
console.print('\nGot problem to generate changeset.')

def warning_for_legacy_metrics(self, e):
if not hasattr(e, 'MESSAGE') or getattr(e, 'MESSAGE') != 'Compilation Error':
return

""""
Example for "msg":
'model.git_repo_analytics.commit_weekly' depends on 'metric.git_repo_analytics.total_commits' which is not in the graph!
"""
if not hasattr(e, 'msg') or "depends on" not in getattr(e, 'msg'):
return

from piperider_cli.error import PipeRiderError
raise PipeRiderError("Found legacy metrics",
hint="The dbt_metrics package has been deprecated and replaced with MetricFlow.")

def _update_github_pr_info(self):
if os.environ.get('GITHUB_EVENT_PATH'):
self.metadata = fetch_pr_metadata()
Expand Down
1 change: 1 addition & 0 deletions tests/mock_dbt_data/git-repo-analytics_metrics_1.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/mock_dbt_data/git-repo-analytics_metrics_2.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions tests/test_compare_summary_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from piperider_cli.compare_report import ComparisonData
from piperider_cli.dbt import dbt_version
from piperider_cli.error import PipeRiderError


def pbcopy_string(input_string):
Expand Down Expand Up @@ -86,3 +87,12 @@ def test_in_memory_compare_with_manifests_target_not_profiled(self):

with open("output.md", "w") as fh:
fh.write(result)

@unittest.skipIf(dbt_version < version.parse('1.6'), 'before 1.6 the legacy metrics are supported')
def test_in_memory_compare_with_manifests_v_1_6(self):
run1 = self.manifest_dict("git-repo-analytics_metrics_1.json")
run2 = self.manifest_dict("git-repo-analytics_metrics_2.json")

with self.assertRaises(PipeRiderError) as ctx:
data = ComparisonData(run1, run2, None)
self.assertEqual("Found legacy metrics", ctx.exception.message)

0 comments on commit f128375

Please sign in to comment.