intentdataflow 0.3.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- intentdataflow-0.3.10.dist-info/METADATA +191 -0
- intentdataflow-0.3.10.dist-info/RECORD +83 -0
- intentdataflow-0.3.10.dist-info/WHEEL +5 -0
- intentdataflow-0.3.10.dist-info/entry_points.txt +2 -0
- intentdataflow-0.3.10.dist-info/licenses/LICENSE +202 -0
- intentdataflow-0.3.10.dist-info/licenses/NOTICE +4 -0
- intentdataflow-0.3.10.dist-info/top_level.txt +1 -0
- intentflow/__init__.py +2 -0
- intentflow/auth.py +30 -0
- intentflow/business_rules.py +77 -0
- intentflow/catalogs.py +100 -0
- intentflow/change_review.py +331 -0
- intentflow/checks/__init__.py +92 -0
- intentflow/checks/airflow3.py +174 -0
- intentflow/checks/business.py +27 -0
- intentflow/checks/catalog.py +43 -0
- intentflow/checks/cluster.py +81 -0
- intentflow/checks/contracts.py +79 -0
- intentflow/checks/cost.py +35 -0
- intentflow/checks/dbt_quality.py +90 -0
- intentflow/checks/dbt_run.py +83 -0
- intentflow/checks/deep.py +180 -0
- intentflow/checks/dq.py +53 -0
- intentflow/checks/elementary.py +50 -0
- intentflow/checks/external.py +91 -0
- intentflow/checks/lakehouse.py +46 -0
- intentflow/checks/lint.py +81 -0
- intentflow/checks/orchestration.py +148 -0
- intentflow/checks/probes.py +66 -0
- intentflow/checks/runtime_history.py +94 -0
- intentflow/checks/schema_drift.py +92 -0
- intentflow/checks/sql_quality.py +274 -0
- intentflow/checks/streaming.py +62 -0
- intentflow/cli.py +914 -0
- intentflow/contracts.py +107 -0
- intentflow/datadiff.py +172 -0
- intentflow/dbt_loader.py +194 -0
- intentflow/dbt_results.py +55 -0
- intentflow/dq_results.py +108 -0
- intentflow/extensions.py +51 -0
- intentflow/external.py +381 -0
- intentflow/http_utils.py +89 -0
- intentflow/i18n.py +76 -0
- intentflow/incidents.py +83 -0
- intentflow/integrations.py +139 -0
- intentflow/lakehouse.py +62 -0
- intentflow/lineage.py +336 -0
- intentflow/lineage_api.py +244 -0
- intentflow/lineage_oracle.py +374 -0
- intentflow/locale/pt.json +1300 -0
- intentflow/model.py +43 -0
- intentflow/monitoring.py +197 -0
- intentflow/notify.py +154 -0
- intentflow/ol_emit.py +93 -0
- intentflow/openlineage.py +168 -0
- intentflow/orchestrators/__init__.py +53 -0
- intentflow/orchestrators/airflow.py +69 -0
- intentflow/orchestrators/aws.py +93 -0
- intentflow/orchestrators/dagster.py +48 -0
- intentflow/orchestrators/dbtcloud.py +68 -0
- intentflow/orchestrators/extra.py +135 -0
- intentflow/orchestrators/ingestion.py +112 -0
- intentflow/orchestrators/kestra.py +27 -0
- intentflow/orchestrators/more.py +135 -0
- intentflow/orchestrators/prefect.py +53 -0
- intentflow/orchestrators/spark.py +118 -0
- intentflow/otel.py +53 -0
- intentflow/overview.py +123 -0
- intentflow/preflight.py +363 -0
- intentflow/promexport.py +39 -0
- intentflow/pyflow.py +554 -0
- intentflow/risks.py +178 -0
- intentflow/runner.py +264 -0
- intentflow/secrets_box.py +84 -0
- intentflow/sqlmesh_loader.py +134 -0
- intentflow/store.py +1006 -0
- intentflow/streaming.py +115 -0
- intentflow/totp.py +38 -0
- intentflow/warehouses/__init__.py +190 -0
- intentflow/warehouses/cloud.py +160 -0
- intentflow/warehouses/more.py +342 -0
- intentflow/web.html +878 -0
- intentflow/web.py +726 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"""Badly written SQL and optimization opportunities (static AST analysis, nothing is executed).
|
|
2
|
+
|
|
3
|
+
Each finding carries an objective recommendation; when a deterministic rewrite exists it goes in
|
|
4
|
+
`evidence.suggested_sql` (over the compiled SQL, for review — never applied on its own).
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import re
|
|
9
|
+
|
|
10
|
+
import sqlglot
|
|
11
|
+
from sqlglot import exp
|
|
12
|
+
from sqlglot.optimizer import optimize
|
|
13
|
+
|
|
14
|
+
from ..i18n import cat, tr
|
|
15
|
+
from ..lineage import DIALECTS
|
|
16
|
+
from ..model import Finding
|
|
17
|
+
from . import Context, check
|
|
18
|
+
|
|
19
|
+
NON_SARGABLE = (exp.Lower, exp.Upper, exp.Cast, exp.TryCast, exp.Substring, exp.Trim, exp.Abs, exp.Length)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _parse(n, project):
|
|
23
|
+
d = DIALECTS.get(project.adapter)
|
|
24
|
+
try:
|
|
25
|
+
return sqlglot.parse_one(n.compiled_code, read=d)
|
|
26
|
+
except Exception:
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _models(ctx):
|
|
31
|
+
for uid, n in ctx.project.nodes.items():
|
|
32
|
+
if n.resource_type in ("model", "snapshot") and n.language == "sql" and n.compiled_code:
|
|
33
|
+
key = (uid, ctx.project.adapter, n.compiled_code)
|
|
34
|
+
if key not in ctx.parsed_sql:
|
|
35
|
+
ctx.parsed_sql[key] = _parse(n, ctx.project)
|
|
36
|
+
tree = ctx.parsed_sql[key]
|
|
37
|
+
if (tree is None or isinstance(tree, exp.Command)) and ctx.active_check in ctx.required_checks:
|
|
38
|
+
ctx.failed_checks.add(ctx.active_check)
|
|
39
|
+
if tree is not None:
|
|
40
|
+
yield uid, n, tree
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _impact(ctx, uid) -> str:
|
|
44
|
+
return "high" if len(ctx.project.downstream(uid)) >= 3 else "medium"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _f(check_id, sev, uid, n, title, detail, **ev):
|
|
48
|
+
return Finding(check_id, sev, cat(n.name, ": ", title), detail, [uid], "pre-merge", ev)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
_STAR_REF = re.compile(r"select\s+\*\s+from\s+\{\{\s*ref\(\s*['\"](\w+)['\"]\s*\)\s*\}\}", re.I)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def star_fix(project, n):
|
|
55
|
+
"""Deterministic fix: `select * from {{ ref('x') }}` → the catalog columns of x."""
|
|
56
|
+
refs = {}
|
|
57
|
+
for name in _STAR_REF.findall(n.raw_code or ""):
|
|
58
|
+
src = next((u for u, m in project.nodes.items() if m.name == name), None)
|
|
59
|
+
cols = list(project.actual_columns(src)) if src else []
|
|
60
|
+
if cols:
|
|
61
|
+
refs[name] = cols
|
|
62
|
+
return {"kind": "expand_star", "node": n.name, "refs": refs} if refs else None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _import_star(star, tree, project) -> bool:
|
|
66
|
+
"""`select * from <one table>` without join/filter, in an import CTE or as the whole model (tmp/staging),
|
|
67
|
+
whose upstream has no known columns: nothing mechanical to expand (an idiom of packages like Fivetran)."""
|
|
68
|
+
sel = star.parent
|
|
69
|
+
if not isinstance(sel, exp.Select) or len(sel.expressions) != 1:
|
|
70
|
+
return False
|
|
71
|
+
if any(sel.args.get(k) for k in ("joins", "where", "group", "having", "qualify", "distinct", "limit")):
|
|
72
|
+
return False
|
|
73
|
+
frm = sel.args.get("from_") or sel.args.get("from")
|
|
74
|
+
if frm is None or not isinstance(frm.this, exp.Table):
|
|
75
|
+
return False
|
|
76
|
+
if not (isinstance(sel.parent, exp.CTE) or sel is tree):
|
|
77
|
+
return False
|
|
78
|
+
t = frm.this
|
|
79
|
+
uid = project.by_relation().get((t.catalog.lower(), t.db.lower(), t.name.lower()))
|
|
80
|
+
return not (uid and (project.actual_columns(uid) or project.nodes[uid].columns))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@check("SQL001", "SELECT * in a model")
|
|
84
|
+
def select_star(ctx: Context):
|
|
85
|
+
out = []
|
|
86
|
+
for uid, n, tree in _models(ctx):
|
|
87
|
+
# `select *` in the final SELECT alone is enough to break with new/removed columns
|
|
88
|
+
stars = [s for s in tree.find_all(exp.Star) if not isinstance(s.parent, exp.Count) and not _import_star(s, tree, ctx.project)]
|
|
89
|
+
if stars:
|
|
90
|
+
f = _f("SQL001", "medium", uid, n, tr("{n} use(s) of SELECT *", n=len(stars)),
|
|
91
|
+
tr("SELECT * couples the model to the upstream schema (a new/removed column changes the output without warning) and reads unneeded columns (cost and memory)."),
|
|
92
|
+
recommendation=tr("list only the columns you use"), occurrences=len(stars))
|
|
93
|
+
f.fix = star_fix(ctx.project, n)
|
|
94
|
+
out.append(f)
|
|
95
|
+
return out
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@check("SQL002", "Cartesian product")
|
|
99
|
+
def cartesian(ctx: Context):
|
|
100
|
+
out = []
|
|
101
|
+
for uid, n, tree in _models(ctx):
|
|
102
|
+
for j in tree.find_all(exp.Join):
|
|
103
|
+
cross = (j.args.get("kind") or "").upper() == "CROSS" or (not j.args.get("on") and not j.args.get("using") and not j.args.get("side") and (j.args.get("kind") or "") != "NATURAL")
|
|
104
|
+
if cross and not isinstance(j.this, exp.Unnest):
|
|
105
|
+
out.append(_f("SQL002", "high", uid, n, tr("JOIN without a condition (cartesian product)"),
|
|
106
|
+
tr("Without ON/USING, the row count is the product of both inputs; it is the most common cause of running out of memory."),
|
|
107
|
+
join=j.sql()[:120], recommendation=tr("add the join condition or aggregate first")))
|
|
108
|
+
return out
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@check("SQL003", "UNION without ALL")
|
|
112
|
+
def union_distinct(ctx: Context):
|
|
113
|
+
out = []
|
|
114
|
+
for uid, n, tree in _models(ctx):
|
|
115
|
+
for u in tree.find_all(exp.Union):
|
|
116
|
+
if u.args.get("distinct", True) and not isinstance(u, (exp.Except, exp.Intersect)):
|
|
117
|
+
out.append(_f("SQL003", "low", uid, n, tr("UNION deduplicates"),
|
|
118
|
+
tr("UNION sorts/groups the whole result to remove duplicates. If the inputs are already disjoint, UNION ALL is cheaper."),
|
|
119
|
+
recommendation=tr("use UNION ALL when duplicates are impossible")))
|
|
120
|
+
break
|
|
121
|
+
return out
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@check("SQL004", "Unneeded ORDER BY")
|
|
125
|
+
def useless_order(ctx: Context):
|
|
126
|
+
out = []
|
|
127
|
+
for uid, n, tree in _models(ctx):
|
|
128
|
+
for sub in list(tree.find_all(exp.Subquery)) + list(tree.find_all(exp.CTE)):
|
|
129
|
+
inner = sub.this
|
|
130
|
+
if isinstance(inner, exp.Select) and inner.args.get("order") and not inner.args.get("limit"):
|
|
131
|
+
out.append(_f("SQL004", "low", uid, n, tr("ORDER BY in a subquery/CTE without LIMIT"),
|
|
132
|
+
tr("The consumer throws the ordering away and it costs memory/disk."), recommendation=tr("remove the inner ORDER BY")))
|
|
133
|
+
break
|
|
134
|
+
return out
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@check("SQL005", "Non-sargable predicate")
|
|
138
|
+
def non_sargable(ctx: Context):
|
|
139
|
+
out = []
|
|
140
|
+
for uid, n, tree in _models(ctx):
|
|
141
|
+
hits = []
|
|
142
|
+
for cond in list(tree.find_all(exp.Where)) + list(tree.find_all(exp.Join)):
|
|
143
|
+
for cmp_ in cond.find_all(exp.EQ, exp.GT, exp.GTE, exp.LT, exp.LTE, exp.NEQ, exp.In):
|
|
144
|
+
lhs = cmp_.this
|
|
145
|
+
if isinstance(lhs, NON_SARGABLE) and lhs.find(exp.Column):
|
|
146
|
+
hits.append(cmp_.sql()[:100])
|
|
147
|
+
if hits:
|
|
148
|
+
out.append(_f("SQL005", "medium", uid, n, tr("function applied to the column in a filter/join"),
|
|
149
|
+
tr("Applying a function to the column prevents using an index, partition or file pruning (full scan)."),
|
|
150
|
+
examples=hits[:3], recommendation=tr("move the function to the constant side or materialize the transformed column")))
|
|
151
|
+
return out
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@check("SQL006", "Suspicious DISTINCT")
|
|
155
|
+
def distinct_masking(ctx: Context):
|
|
156
|
+
out = []
|
|
157
|
+
for uid, n, tree in _models(ctx):
|
|
158
|
+
for s in tree.find_all(exp.Select):
|
|
159
|
+
if s.args.get("distinct") and s.args.get("joins"):
|
|
160
|
+
out.append(_f("SQL006", "medium", uid, n, tr("SELECT DISTINCT combined with JOIN"),
|
|
161
|
+
tr("DISTINCT after a JOIN often hides duplicates (fan-out) caused by a non-unique key; it costs a sort and masks a modeling error."),
|
|
162
|
+
recommendation=tr("fix the join cardinality (aggregate first or use a unique key)")))
|
|
163
|
+
break
|
|
164
|
+
return out
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@check("SQL007", "Correlated subquery")
|
|
168
|
+
def correlated(ctx: Context):
|
|
169
|
+
out = []
|
|
170
|
+
for uid, n, tree in _models(ctx):
|
|
171
|
+
for sq in tree.find_all(exp.Subquery):
|
|
172
|
+
if isinstance(sq.parent, (exp.Select, exp.Alias, exp.EQ, exp.GT, exp.LT)) and not isinstance(sq.parent, exp.From):
|
|
173
|
+
inner_tables = {t.alias_or_name for t in sq.find_all(exp.Table)}
|
|
174
|
+
outer_refs = {c.table for c in sq.find_all(exp.Column) if c.table and c.table not in inner_tables}
|
|
175
|
+
if outer_refs and isinstance(sq.this, exp.Select):
|
|
176
|
+
out.append(_f("SQL007", "medium", uid, n, tr("correlated subquery"),
|
|
177
|
+
tr("Runs once per row in many engines (quadratic cost)."),
|
|
178
|
+
recommendation=tr("rewrite as a JOIN with prior aggregation or a window function")))
|
|
179
|
+
break
|
|
180
|
+
return out
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
@check("SQL008", "LIKE with a leading wildcard")
|
|
184
|
+
def leading_wildcard(ctx: Context):
|
|
185
|
+
out = []
|
|
186
|
+
for uid, n, tree in _models(ctx):
|
|
187
|
+
for lk in tree.find_all(exp.Like, exp.ILike):
|
|
188
|
+
pat = lk.expression
|
|
189
|
+
if isinstance(pat, exp.Literal) and pat.is_string and pat.name.startswith("%"):
|
|
190
|
+
out.append(_f("SQL008", "low", uid, n, tr("LIKE '%…' prevents using an index"), tr("A leading wildcard forces a full scan."),
|
|
191
|
+
pattern=pat.name[:40], recommendation=tr("use a prefix search, a trigram index or a derived column")))
|
|
192
|
+
break
|
|
193
|
+
return out
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
@check("SQL009", "NOT IN with a subquery")
|
|
197
|
+
def not_in_subquery(ctx: Context):
|
|
198
|
+
out = []
|
|
199
|
+
for uid, n, tree in _models(ctx):
|
|
200
|
+
for nt in tree.find_all(exp.Not):
|
|
201
|
+
if isinstance(nt.this, exp.In) and nt.this.args.get("query"):
|
|
202
|
+
out.append(_f("SQL009", "medium", uid, n, tr("NOT IN (subquery)"),
|
|
203
|
+
tr("Returns nothing if the subquery contains NULL (three-valued logic) and often gets a bad plan."),
|
|
204
|
+
recommendation=tr("use NOT EXISTS or LEFT JOIN ... IS NULL")))
|
|
205
|
+
break
|
|
206
|
+
return out
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
@check("SQL010", "Very large IN list")
|
|
210
|
+
def big_in(ctx: Context):
|
|
211
|
+
out = []
|
|
212
|
+
for uid, n, tree in _models(ctx):
|
|
213
|
+
for i in tree.find_all(exp.In):
|
|
214
|
+
if len(i.expressions) > 100:
|
|
215
|
+
out.append(_f("SQL010", "low", uid, n, tr("IN with {n} literals", n=len(i.expressions)), tr("Large lists degrade planning."),
|
|
216
|
+
recommendation=tr("load the values into a table/seed and JOIN")))
|
|
217
|
+
break
|
|
218
|
+
return out
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
@check("SQL011", "OR condition in a JOIN")
|
|
222
|
+
def or_join(ctx: Context):
|
|
223
|
+
out = []
|
|
224
|
+
for uid, n, tree in _models(ctx):
|
|
225
|
+
for j in tree.find_all(exp.Join):
|
|
226
|
+
on = j.args.get("on")
|
|
227
|
+
if on is not None and on.find(exp.Or):
|
|
228
|
+
out.append(_f("SQL011", "medium", uid, n, tr("JOIN with OR in the condition"),
|
|
229
|
+
tr("Prevents a hash join in most engines and falls back to a nested loop."),
|
|
230
|
+
recommendation=tr("split into two JOINs and combine them with UNION ALL")))
|
|
231
|
+
break
|
|
232
|
+
return out
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def equivalent(wh, a_sql: str, b_sql: str) -> bool | None:
|
|
236
|
+
"""Compare the results as multisets in the warehouse itself. None = could not be checked."""
|
|
237
|
+
try:
|
|
238
|
+
q = (f"select (select count(*) from (({a_sql}) except all ({b_sql}))) + "
|
|
239
|
+
f"(select count(*) from (({b_sql}) except all ({a_sql})))")
|
|
240
|
+
return int(wh.scalar(q)) == 0
|
|
241
|
+
except Exception:
|
|
242
|
+
return None
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
@check("SQL012", "Optimized rewrite available")
|
|
246
|
+
def optimizer_rewrite(ctx: Context):
|
|
247
|
+
"""Optimized SQL (qualified, predicates pushed down, CTEs/subqueries simplified).
|
|
248
|
+
With a warehouse available, equivalence is checked by running both versions."""
|
|
249
|
+
out = []
|
|
250
|
+
schema = ctx.project.sqlglot_schema()
|
|
251
|
+
d = DIALECTS.get(ctx.project.adapter)
|
|
252
|
+
for uid, n, tree in _models(ctx):
|
|
253
|
+
try:
|
|
254
|
+
opt = optimize(tree.copy(), schema=schema, dialect=d).sql(dialect=d, pretty=True)
|
|
255
|
+
except Exception:
|
|
256
|
+
continue
|
|
257
|
+
base = tree.sql(dialect=d, pretty=True)
|
|
258
|
+
try: # the optimizer output may not re-parse in the dialect (e.g. JSONExtract): no suggestion, no check crash
|
|
259
|
+
n_opt_ctes = len(list(sqlglot.parse_one(opt, read=d).find_all(exp.CTE)))
|
|
260
|
+
except Exception:
|
|
261
|
+
continue
|
|
262
|
+
if opt == base or n_opt_ctes >= len(list(tree.find_all(exp.CTE))):
|
|
263
|
+
continue
|
|
264
|
+
eq = equivalent(ctx.warehouse, n.compiled_code, opt) if ctx.warehouse is not None else None
|
|
265
|
+
if eq is False:
|
|
266
|
+
out.append(Finding("SQL012", "info", tr("{model}: the optimizer rewrite is NOT equivalent (discarded)", model=n.name),
|
|
267
|
+
tr("The result differs from the original when run; the suggestion was discarded for safety."), [uid], "pre-merge",
|
|
268
|
+
{"verified_equivalent": False}))
|
|
269
|
+
continue
|
|
270
|
+
out.append(Finding("SQL012", "info", tr("{model}: the SQLGlot optimizer simplifies this SQL", model=n.name),
|
|
271
|
+
tr("Fewer CTEs/subqueries and predicates pushed to the source. Review and adopt it if the semantics are the same."),
|
|
272
|
+
[uid], "pre-merge", {"suggested_sql": opt, "verified_equivalent": eq,
|
|
273
|
+
"equivalence": tr("checked by execution (EXCEPT ALL both ways)") if eq else tr("not checked: no warehouse")}))
|
|
274
|
+
return out
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Kafka: growing consumer lag and incompatible schema changes (Schema Registry)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from ..i18n import tr
|
|
5
|
+
from ..model import Finding
|
|
6
|
+
from . import Context, check
|
|
7
|
+
|
|
8
|
+
DEFAULT_MAX_LAG = 10_000
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _topic_node(ctx, subject: str):
|
|
12
|
+
"""subject `orders-value` / `orders-key` → the node named after the topic (source or model)."""
|
|
13
|
+
if ctx.project is None:
|
|
14
|
+
return None
|
|
15
|
+
topic = subject.rsplit("-", 1)[0] if subject.endswith(("-value", "-key")) else subject
|
|
16
|
+
for uid, n in ctx.project.nodes.items():
|
|
17
|
+
if n.name.lower() == topic.lower():
|
|
18
|
+
return uid
|
|
19
|
+
return None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@check("KAF001", "High and growing Kafka consumer lag", stage="continuous", cost="statistical")
|
|
23
|
+
def lag(ctx: Context):
|
|
24
|
+
limit = float(ctx.policies.get("kafka_lag_max", DEFAULT_MAX_LAG) or DEFAULT_MAX_LAG)
|
|
25
|
+
series: dict[str, list] = {}
|
|
26
|
+
for s in sorted(ctx.samples, key=lambda x: x.ts):
|
|
27
|
+
if s.source == "kafka" and s.metric == "consumer_lag":
|
|
28
|
+
series.setdefault(s.scope, []).append(s)
|
|
29
|
+
out = []
|
|
30
|
+
for scope, v in series.items():
|
|
31
|
+
last = v[-1].value
|
|
32
|
+
rising = len(v) < 2 or last > v[0].value
|
|
33
|
+
if last >= limit and rising:
|
|
34
|
+
out.append(Finding("KAF001", "high" if last >= 10 * limit else "medium", tr("{scope}: lag of {n} messages", scope=scope, n=int(last)),
|
|
35
|
+
tr("The consumer does not keep up with production; data reaches the warehouse late and the lag can become loss through retention."),
|
|
36
|
+
[f"kafka:{scope}"], "continuous", {"lag": last, "limit": limit, "samples": len(v),
|
|
37
|
+
"recommendation": tr("scale the consumer, check reprocessing/errors and the processing time per batch")}))
|
|
38
|
+
return out
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@check("KAF002", "Incompatible schema change in the Schema Registry", stage="continuous", cost="static")
|
|
42
|
+
def schema_change(ctx: Context):
|
|
43
|
+
snap = (ctx.store.get_setting("state.kafka_schemas") if ctx.store is not None else None) or {}
|
|
44
|
+
out = []
|
|
45
|
+
for subject, vs in snap.items():
|
|
46
|
+
if len(vs) < 2 or not vs[-1].get("fields") or not vs[-2].get("fields"):
|
|
47
|
+
continue
|
|
48
|
+
old, new = vs[-2]["fields"], vs[-1]["fields"]
|
|
49
|
+
removed = sorted(set(old) - set(new))
|
|
50
|
+
retyped = sorted(c for c in set(old) & set(new) if old[c] != new[c])
|
|
51
|
+
if not removed and not retyped:
|
|
52
|
+
continue
|
|
53
|
+
uid = _topic_node(ctx, subject)
|
|
54
|
+
down = len(ctx.project.downstream(uid)) if uid and ctx.project else 0
|
|
55
|
+
what = [tr("`{field}` removed", field=c) for c in removed] + [f"`{c}`: {old[c]} → {new[c]}" for c in retyped]
|
|
56
|
+
out.append(Finding("KAF002", "critical" if down else "high",
|
|
57
|
+
tr("{subject}: v{old} → v{new} breaks consumers ({changes})", subject=subject, old=vs[-2]["version"], new=vs[-1]["version"],
|
|
58
|
+
changes="; ".join(what)),
|
|
59
|
+
tr("Incompatible change in the topic contract.") + (" " + tr("Affects {n} downstream model(s).", n=down) if down else ""),
|
|
60
|
+
[uid] if uid else [f"kafka:{subject}"], "continuous",
|
|
61
|
+
{"removed": removed, "retyped": retyped, "downstream": down, "from": vs[-2]["version"], "to": vs[-1]["version"]}))
|
|
62
|
+
return out
|