Skip to content

Commit

Permalink
Don't show sources if their count has not changed (#4176)
Browse files Browse the repository at this point in the history
* Don't show sources if their count has not changed

* Add explanation for missing sources
  • Loading branch information
AetherUnbound authored Apr 24, 2024
1 parent 62c4261 commit 7c6298a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions catalog/dags/data_refresh/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ def report_record_difference(before: dict, after: dict, media_type: str, dag_id:
breakdown_diff = {k: after.get(k, 0) - before.get(k, 0) for k in all_keys}
if breakdown_diff:
breakdown_message = "\n".join(
f"`{k}`:{v:+,}" for k, v in breakdown_diff.items()
f"`{k}`:{v:+,}" for k, v in breakdown_diff.items() if v != 0
)
if any(v == 0 for v in breakdown_diff.values()):
breakdown_message += "\n_Sources not listed had no change in count_"
else:
breakdown_message = "Both indices missing? No breakdown to show"

Expand All @@ -40,8 +42,8 @@ def report_record_difference(before: dict, after: dict, media_type: str, dag_id:
*Record count difference for `{media_type}`*: {total_before:,}{total_after:,}
*Change*: {count_diff:+,} ({percent_diff:+}% Δ)
*Breakdown of changes*:
{breakdown_message}
"""
message += breakdown_message
slack.send_message(
text=message, dag_id=dag_id, username="Data refresh record difference"
)
Expand Down
4 changes: 3 additions & 1 deletion catalog/tests/dags/data_refresh/test_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
[
{"src1": 4, "src2": 21},
{"src1": 4},
["25 → 4", "-21 (-84.0%", "`src1`:+0", "`src2`:-21"],
# Unchanged source count shouldn't show up
["25 → 4", "-21 (-84.0%", "`src2`:-21"],
],
[
{"src1": 4000, "src2": 20},
Expand All @@ -36,6 +37,7 @@
{},
["20 → 0", "-20 (-100.0%", "`src1`:-10", "`src2`:-10"],
],
[{"src1": 4}, {"src1": 4}, ["Sources not listed had no change in count"]],
[{}, {}, ["Both indices missing? No breakdown to show"]],
],
)
Expand Down

0 comments on commit 7c6298a

Please sign in to comment.