mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-16 19:31:58 +00:00
剖析任务接口收取值观察范围,对话框给出「取值观察」;定时维护挑不出要观察的表时把原因记进触发记录
验收:取值观察只能经定时维护触发——POST /catalog/profile-jobs 的 scope 只收 needed、all,可剖析任务本来就支持
observe(只观察、不剖析)。另外 12 小时内观察过的表不再观察时,任务以 0 张表结束,原因只在剖析任务的 notice
里,从定时维护触发时触发记录(ScheduleFire.inputs)看不出来。
后端:
- ProfileJobIn.scope 加 observe(maintenance 是定时维护用的,接口照旧不收)。挑不出表时照旧 409 profile_nothing,
说法是 NOTHING_TO_OBSERVE(「最近 12 小时内都观察过了」)。
- catalog_profile_jobs.nothing_reason:按此刻的表结构和目录一张表都挑不出来时交回 ProfileNothing 的原话;排在
起草后面时说不准,返回 None。
- source_maintenance._start:建出 0 张表的剖析任务、这次触发又没有探查(开始时表结构不会变)、也没排在起草后面
(目录不会变)时,判断得出任务会以 0 张表结束,把原因记进 inputs.skipped(同一套 NOT_RUN 说法进 reason)。
任务照建、触发照旧是 started:每小时一次的维护不至于一天二十几次「没能发起」。同一次触发里有探查、或者排在
起草后面时判断不了,保持现状,写进了模块说明。
前端:剖析对话框的范围里加「取值观察:有数据目录的 N 张表」(说法照维护设置里「取值观察」那一步:码值分布、
最新业务日期、按日行数和行数,和同口径的历史比出取值变化;最近 12 小时内观察过的这次不再观察),建任务带
scope: observe。张数按清单上有数据目录、不是视图的表算(isObservable,profile.ts),观察到期没有由服务端判,
所以是上限。挑不出表时说「没有要观察的表」和服务端原话,不给「改选全部表」(那是剖析,不是观察)。文案进
PROFILE_TEXT。
测试:test_catalog_observe 新增一条(接口建 observe 任务、只做观察检查,再建一次 409 profile_nothing,maintenance
422);test_source_maintenance 新增一条(只选取值观察,12 小时内再触发:任务 0 张表,inputs.skipped 和 reason 写明
原因)。去掉修复回跑两条都挂。check-catalog-profile 跟上:范围多一项 observe:1,说法核对;新一节建取值观察任务
(请求体 {scope: observe})、都观察过时的「没有要观察的表」且没有「改选全部表」。tsc、check-copy 通过,
check-catalog-profile 204 项全过。
This commit is contained in:
@@ -114,8 +114,9 @@ GUIDANCE_NOT_TEXT = "起草要求要是一段文字(要清除起草要求请
|
||||
class ProfileJobIn(BaseModel):
|
||||
#: 要剖析的表(范围 selected,按给的顺序去重);最多 500 张(超了 422,说明是中文)
|
||||
tables: list[str] | None = None
|
||||
#: 不指定表时的范围:needed 需要剖析的表(缺省)、all 全部表(都不含视图、没有可剖析的项的表)
|
||||
scope: Literal["needed", "all"] | None = None
|
||||
#: 不指定表时的范围:needed 需要剖析的表(缺省)、all 全部表(都不含视图、没有可剖析的项的表)、observe 取值观察(只观察
|
||||
#: 有数据目录、观察到期的表,不剖析;见 data/catalog_profile_observe)。maintenance 是定时维护用的,这里不收
|
||||
scope: Literal["needed", "all", "observe"] | None = None
|
||||
|
||||
|
||||
async def _resolved(session: AsyncSession, source_id: str) -> tuple[DataSource, Any]:
|
||||
|
||||
@@ -692,6 +692,18 @@ async def _behind_draft(session: AsyncSession, source_id: str) -> bool:
|
||||
return catalog_jobs.sync_drafting(source_id) or await catalog_jobs.active_job(session, source_id) is not None
|
||||
|
||||
|
||||
async def nothing_reason(session: AsyncSession, row: Any, source: Any, scope: str) -> str | None:
|
||||
"""按此刻的表结构和目录,这个范围一张表都挑不出来时为什么(ProfileNothing 的原话);挑得出、或者排在起草后面(开始时按
|
||||
起草后的目录再挑,现在说不准)返回 None。定时维护建出 0 张表的任务时用它把原因记进触发记录。"""
|
||||
if await _behind_draft(session, row.id):
|
||||
return None
|
||||
try:
|
||||
await _pick(session, row, source, tables=None, scope=scope)
|
||||
except ProfileNothing as e:
|
||||
return str(e)
|
||||
return None
|
||||
|
||||
|
||||
async def create_job(session: AsyncSession, row: Any, source: Any, *, tables: list[str] | None, scope: str,
|
||||
settings: ProfileSettings, actor: str | None, retry_of: str | None = None,
|
||||
trigger: str = "manual", fire_at: str | None = None, schedule_id: str | None = None,
|
||||
@@ -1161,5 +1173,6 @@ __all__ = ["INTERRUPTED_ERROR", "KEEP_JOBS", "MAX_TABLES", "NOTHING_AT_ALL", "NO
|
||||
"NOTHING_TO_OBSERVE", "NothingToRetry", "OBSERVING_SCOPES", "SCOPES", "task_modes", "trigger_of",
|
||||
"ProfileBusy", "ProfileFinished", "ProfileJobs", "ProfileNothing", "THEN_PROFILE", "active_job",
|
||||
"busy_message", "cancel", "create_job", "due_reason", "ensure_free", "job_brief", "job_dict", "job_out",
|
||||
"last_detail", "last_facts", "last_profiles", "outside_of", "latest_job", "load", "load_task", "manager", "prune", "public_last",
|
||||
"retry_tables", "startup", "task_detail", "task_row", "task_rows", "unsaved_error", "waiting_for"]
|
||||
"last_detail", "last_facts", "last_profiles", "outside_of", "latest_job", "load", "load_task", "manager",
|
||||
"nothing_reason", "prune", "public_last", "retry_tables", "startup", "task_detail", "task_row", "task_rows",
|
||||
"unsaved_error", "waiting_for"]
|
||||
|
||||
@@ -13,7 +13,10 @@ observe 取值观察,可多选,没设过是三步都做。
|
||||
|
||||
**到点**(fire,持着 scheduler 的 launch_lock):按顺序建探查任务 → 剖析任务(范围 needed / observe / maintenance,按选的
|
||||
步骤),任务上记 trigger=schedule 和 fire_at,靠 SourceLanes 串行:剖析排在同一次触发的探查后面(等探查进了同源队才建剖析
|
||||
任务),开始时按那时的表结构和目录挑表(挑出 0 张也照建,任务以 0 张表结束、提醒里写明为什么)。预算、止损照剖析设置。
|
||||
任务),开始时按那时的表结构和目录挑表(挑出 0 张也照建,任务以 0 张表结束、提醒里写明为什么)。建任务时就判断得出会是 0 张
|
||||
的(这次没有探查、也没排在起草后面,开始时表结构和目录都不会变——比如有数据目录的表都在 12 小时内观察过),原因另记进触发
|
||||
记录的 inputs.skipped 和 reason;同一次触发里有探查、或者排在起草后面时说不准(探查完、起草完可能就有了),保持现状,只在
|
||||
任务的提醒里写。预算、止损照剖析设置。
|
||||
照实记没执行的:数据源不存在、已停用、是上传表格或记录表时整次不执行(failed_to_start);剖析没开时剖析、观察两步不执行、
|
||||
探查照做;上一次的维护(或别的探查、剖析)还没做完时这次跳过(skipped_overlap)。每次触发记下建了哪几个任务、哪几步没执行、
|
||||
为什么(触发记录的 inputs:{steps, jobs, skipped})。
|
||||
@@ -221,6 +224,11 @@ async def _start(source_id: str, steps: list[str], *, actor: str, fire_at: str,
|
||||
table_versions.SnapshotMissing) as e:
|
||||
skipped += [{"step": s, "reason": str(e)} for s in wanted]
|
||||
return jobs, skipped
|
||||
if not tasks and introspect_id is None and (why := await catalog_profile_jobs.nothing_reason(
|
||||
session, row, view, scope)):
|
||||
# 建任务时就挑不出表、这次又没有探查(开始时表结构不会变)、也没排在起草后面(目录不会变):任务会以 0 张表
|
||||
# 结束,原因照实记进触发记录,不只在剖析任务的提醒里。任务照建(触发照旧是 started)
|
||||
skipped += [{"step": s, "reason": why} for s in wanted]
|
||||
catalog_profile_jobs.manager.start(job.id)
|
||||
jobs.append({"step": "+".join(wanted), "kind": "profile", "id": job.id, "scope": scope, "tables": len(tasks)})
|
||||
return jobs, skipped
|
||||
|
||||
@@ -271,6 +271,27 @@ def test_observation_today_is_the_server_local_date(monkeypatch):
|
||||
time.tzset()
|
||||
|
||||
|
||||
async def test_the_profile_jobs_api_takes_the_observe_scope(client, shop):
|
||||
"""取值观察以前只能经定时维护触发:POST /catalog/profile-jobs 的 scope 只收 needed、all(下一轮验收)。现在也收 observe:
|
||||
只观察、不剖析;12 小时内都观察过时 409 profile_nothing,说清为什么。"""
|
||||
sid, _ = shop
|
||||
r = await client.post(f"/api/datasources/{sid}/catalog/profile-jobs", json={"scope": "observe"})
|
||||
assert r.status_code == 202, r.text
|
||||
job = r.json()["job"]
|
||||
assert job["scope"] == "observe"
|
||||
await catalog_profile_jobs.manager.wait(job["id"], timeout=60)
|
||||
async with SessionLocal() as session:
|
||||
[task] = (await session.execute(select(CatalogProfileTask).where(
|
||||
CatalogProfileTask.job_id == job["id"]))).scalars()
|
||||
assert {c["kind"] for c in task.checks} == set(observe.OBSERVE_KINDS), "只观察:不做关系、码值、日期的剖析"
|
||||
assert {o.kind for o in await _obs(sid)} == set(observe.OBSERVE_KINDS)
|
||||
again = await client.post(f"/api/datasources/{sid}/catalog/profile-jobs", json={"scope": "observe"})
|
||||
assert again.status_code == 409 and again.json()["code"] == "profile_nothing"
|
||||
assert f"{observe.OBSERVE_EVERY_H} 小时内都观察过" in again.json()["detail"]
|
||||
bad = await client.post(f"/api/datasources/{sid}/catalog/profile-jobs", json={"scope": "maintenance"})
|
||||
assert bad.status_code == 422, "maintenance 是定时维护用的,接口不收"
|
||||
|
||||
|
||||
class _FakeCx:
|
||||
"""只看拼出来的 SQL:大表、业务日期没有索引。"""
|
||||
|
||||
|
||||
@@ -111,6 +111,32 @@ async def test_fire_builds_introspect_then_profile_in_order(client, tmp_path, ma
|
||||
await drop_source(sid)
|
||||
|
||||
|
||||
async def test_observing_again_within_the_window_records_why_in_the_fire(client, tmp_path, made):
|
||||
"""只选取值观察:12 小时内观察过的表不再观察,任务以 0 张表结束。建任务时就判断得出(这次没有探查、也没排在起草后面,
|
||||
开始时表结构、目录不会变):原因记进触发记录的 inputs.skipped 和 reason(下一轮验收:以前只在剖析任务的提醒里)。
|
||||
任务照建(触发照旧是 started,不当成没能发起)。"""
|
||||
sid = await _source(client, tmp_path / "c.db")
|
||||
try:
|
||||
async with SessionLocal() as session:
|
||||
row = await session.get(DataSource, sid)
|
||||
row.options = sm.with_steps(row.options, ["observe"], actor="测试员")
|
||||
await session.commit()
|
||||
schedule_id = await _schedule(sid)
|
||||
made.append(schedule_id)
|
||||
at = utcnow().replace(microsecond=0)
|
||||
first = await service.fire_once(schedule_id, at, "manual")
|
||||
assert first.status == "started" and not first.inputs.get("skipped"), first.inputs
|
||||
await _wait_jobs(first)
|
||||
second = await service.fire_once(schedule_id, at + timedelta(seconds=1), "manual")
|
||||
await _wait_jobs(second)
|
||||
assert second.status == "started" and [j["tables"] for j in second.inputs["jobs"]] == [0]
|
||||
[skipped] = second.inputs["skipped"]
|
||||
assert skipped["step"] == "observe" and "12 小时内都观察过" in skipped["reason"], skipped
|
||||
assert "取值观察没有执行" in second.reason
|
||||
finally:
|
||||
await drop_source(sid)
|
||||
|
||||
|
||||
async def test_profile_off_records_steps_not_run_and_still_introspects(client, tmp_path, made):
|
||||
sid = await _source(client, tmp_path / "b.db", profile=False)
|
||||
try:
|
||||
|
||||
@@ -530,7 +530,7 @@ export const api = {
|
||||
* 409 带机读码:profile_disabled、datasource_inactive、schema_missing、snapshot_tampered、profile_busy(这个源已有排队、
|
||||
* 进行中的剖析任务,detail 写明进行到第几张)、profile_nothing(按范围挑出 0 张表,detail 写明原因和建议)
|
||||
*/
|
||||
create: (sourceId: string, body: { tables?: string[]; scope?: 'needed' | 'all' }) =>
|
||||
create: (sourceId: string, body: { tables?: string[]; scope?: 'needed' | 'all' | 'observe' }) =>
|
||||
post<{ job: CatalogProfileJob }>(`${catalogBase(sourceId)}/profile-jobs`, body),
|
||||
/** 排队或进行中的那个剖析任务;没有为 null */
|
||||
active: (sourceId: string, opts?: RequestOptions) =>
|
||||
|
||||
@@ -3035,6 +3035,11 @@ export const PROFILE_TEXT = {
|
||||
scopeNeededNone: '没有需要剖析的表:都剖析过、上次都做完了,也没有新的待核实关联关系和新的码值、日期列',
|
||||
scopeAll: (n: number) => `全部 ${formatNumber(n)} 张表`,
|
||||
scopeAllHint: '有可剖析项的表,不含视图',
|
||||
/** 取值观察(范围 observe):只观察、不剖析。张数是有数据目录的表,其中最近观察过的服务端这次不观察 */
|
||||
scopeObserve: (n: number) => `取值观察:有数据目录的 ${formatNumber(n)} 张表`,
|
||||
scopeObserveHint: (hours: number) => '只观察、不剖析:码值分布、最新业务日期、按日行数和行数,和同口径的历史比出取值变化,'
|
||||
+ `列在「变化」里。最近 ${formatNumber(hours)} 小时内观察过的表这次不再观察`,
|
||||
scopeObserveNone: '还没有有数据目录的表:取值观察只看有数据目录的表,请先起草数据目录',
|
||||
/** 已选、筛选结果里有剖析不了的表:不交给服务端,写明有几张 */
|
||||
scopeLeftOut: (n: number) => `另有 ${formatNumber(n)} 张不剖析(视图、表结构中已没有,或没有可剖析的项)`,
|
||||
scopeEmpty: '这个范围里没有可剖析的表',
|
||||
@@ -3230,6 +3235,7 @@ export const PROFILE_TEXT = {
|
||||
busy: '这个数据源已有剖析任务',
|
||||
tampered: '数据文件核对未通过',
|
||||
nothing: '没有可剖析的表',
|
||||
nothingObserve: '没有要观察的表',
|
||||
other: '无法开始剖析',
|
||||
} as Record<string, string>,
|
||||
blockedNext: {
|
||||
@@ -3239,6 +3245,7 @@ export const PROFILE_TEXT = {
|
||||
busy: '同一个数据源同一时间只有一个剖析任务:可以查看它的进度,等它结束后再开始新的剖析。',
|
||||
tampered: '请重新上传表格,或联系管理员核对数据文件。',
|
||||
nothing: '可以改选「全部表」,或在表清单中选定要剖析的表。',
|
||||
nothingObserve: '观察过的表要过一段时间才再观察;要剖析,可以回到上一步改选「需要剖析的表」或「全部表」。',
|
||||
other: '请稍后重试。',
|
||||
} as Record<string, string>,
|
||||
busyAt: (who: string | null, done: number, total: number) =>
|
||||
|
||||
@@ -20,8 +20,8 @@ import {
|
||||
} from '../../lib/terms'
|
||||
import { STATUS_TONE, StatusChip } from './parts'
|
||||
import {
|
||||
PROFILE_MAX_TABLES, PROFILE_RETRYABLE, UNFINISHED_REASONS, coverageText, fillKey, isProfilable, profileBlockOf, profileScopeTables,
|
||||
secondsText, sizeText, spanText,
|
||||
PROFILE_MAX_TABLES, PROFILE_OBSERVE_EVERY_H, PROFILE_RETRYABLE, UNFINISHED_REASONS, coverageText, fillKey, isProfilable, profileBlockOf,
|
||||
profileScopeTables, secondsText, sizeText, spanText,
|
||||
} from './profile'
|
||||
import type { ProfileBlock } from './profile'
|
||||
import { isJobActive } from './draftJob'
|
||||
@@ -32,16 +32,18 @@ import type { ProfileStartBody } from './profileJob'
|
||||
// 数据目录页的「数据剖析」。剖析是服务端的后台任务(profileJob.ts):这里选范围、看预算、建任务;之后显示页面跟着的
|
||||
// 那个任务(进行中的逐表进度、结束后的结果),任务本身的状态在页面上,关掉对话框照常进行。照起草对话框的结构:
|
||||
//
|
||||
// 开始前:范围(已选 / 当前筛选 / 需要剖析的表(默认)/ 全部表,个数按清单上每行的 profile_due、profile_checks 算)、按表写的
|
||||
// 预算和这次最多约几条查询、醒目一句「只读查询、一条一条发、可随时停止」;同一个数据源有起草任务时按钮写「排队剖析」。
|
||||
// 开始前:范围(已选 / 当前筛选 / 需要剖析的表(默认)/ 全部表 / 取值观察,个数按清单上每行的 profile_due、profile_checks、
|
||||
// 有没有数据目录算;取值观察只观察不剖析,最近观察过的服务端这次不观察,张数是上限)、按表写的预算和这次最多约几条查询、
|
||||
// 醒目一句「只读查询、一条一条发、可随时停止」;同一个数据源有起草任务时按钮写「排队剖析」。
|
||||
// 进行中:几张 / 共几张、已发几条查询、用时,按表数的真进度条,停止;逐表一行(状态、各类检查的进度、查询数、用时、正在做
|
||||
// 哪一项),点一行展开这张表的检查清单、发现和发过的查询。
|
||||
// 结束后:汇总(各状态几张、核实了什么)、止损和停止的原因照实写、按「有发现 / 有跳过 / 失败」筛、重试没做完的表;码值的
|
||||
// 「填写含义」照旧(填完回到这里,接着下一列)。
|
||||
// 开始不了(409):每种情况一句说法和下一步(未开启就地打开剖析设置;正忙写清是谁的、到哪了,可以去看它的进度)。
|
||||
// 开始不了(409):每种情况一句说法和下一步(未开启就地打开剖析设置;正忙写清是谁的、到哪了,可以去看它的进度;取值观察
|
||||
// 挑不出表时说「没有要观察的表」,不给「改选全部表」)。
|
||||
// ===========================================================================
|
||||
|
||||
type Scope = 'selected' | 'filtered' | 'needed' | 'all'
|
||||
type Scope = 'selected' | 'filtered' | 'needed' | 'all' | 'observe'
|
||||
type Filter = 'all' | 'findings' | 'skipped' | 'failed'
|
||||
const FILTERS: readonly Filter[] = ['all', 'findings', 'skipped', 'failed']
|
||||
|
||||
@@ -114,6 +116,10 @@ export function ProfileDialog({
|
||||
tables: needed, leftOut: 0, body: { scope: 'needed' } })
|
||||
const all = profileScopeTables(rows, 'all')
|
||||
out.push({ key: 'all', label: PT.scopeAll(all.length), hint: PT.scopeAllHint, tables: all, leftOut: 0, body: { scope: 'all' } })
|
||||
const watched = profileScopeTables(rows, 'observe')
|
||||
out.push({ key: 'observe', label: PT.scopeObserve(watched.length),
|
||||
hint: watched.length ? PT.scopeObserveHint(PROFILE_OBSERVE_EVERY_H) : PT.scopeObserveNone, tables: watched, leftOut: 0,
|
||||
body: { scope: 'observe' } })
|
||||
return out
|
||||
}, [rows, visible, selected, filtered])
|
||||
const [scope, setScope] = useState<Scope>(() => {
|
||||
@@ -260,8 +266,9 @@ export function ProfileDialog({
|
||||
<div className="space-y-1.5" role="radiogroup" aria-label={PT.scope}>
|
||||
{scopes.map((s) => {
|
||||
const over = !!s.body.tables && s.tables.length > PROFILE_MAX_TABLES
|
||||
const note = over ? PT.scopeTooMany(PROFILE_MAX_TABLES) : !s.tables.length && s.key !== 'needed' ? PT.scopeEmpty
|
||||
: s.leftOut ? PT.scopeLeftOut(s.leftOut) : s.hint
|
||||
const note = over ? PT.scopeTooMany(PROFILE_MAX_TABLES)
|
||||
: !s.tables.length && s.key !== 'needed' && s.key !== 'observe' ? PT.scopeEmpty
|
||||
: s.leftOut ? PT.scopeLeftOut(s.leftOut) : s.hint
|
||||
return (
|
||||
<label key={s.key} className={clsx('flex cursor-pointer items-start gap-2 rounded-md border px-3 py-2 text-xs',
|
||||
picked.key === s.key ? 'border-[var(--accent)] bg-accent-soft' : 'hover:bg-hover')} data-profile-scope={s.key}
|
||||
@@ -307,7 +314,8 @@ export function ProfileDialog({
|
||||
</>
|
||||
)
|
||||
} else if (phase === 'blocked' && blocked) {
|
||||
body = <Blocked blocked={blocked} onSettings={onSettings} onGoSource={onGoSource} onViewActive={() => void viewActive()}
|
||||
body = <Blocked blocked={blocked} observing={blocked.body.scope === 'observe'} onSettings={onSettings} onGoSource={onGoSource}
|
||||
onViewActive={() => void viewActive()}
|
||||
onChooseAll={() => { setScope('all'); void begin({ scope: 'all' }) }} onRetry={() => void begin(blocked.body)} />
|
||||
footer = (
|
||||
<>
|
||||
@@ -384,32 +392,35 @@ function Budget({ settings: s, sourceName, tables, onSettings }: {
|
||||
}
|
||||
|
||||
/** 开始不了(409):是哪种情况、服务端的原话、下一步和对应的按钮 */
|
||||
function Blocked({ blocked: b, onSettings, onGoSource, onViewActive, onChooseAll, onRetry }: {
|
||||
function Blocked({ blocked: b, observing, onSettings, onGoSource, onViewActive, onChooseAll, onRetry }: {
|
||||
blocked: { kind: ProfileBlock; message: string; active: CatalogProfileJob | null }
|
||||
/** 选的是取值观察:挑不出表时说「没有要观察的表」,不给「改选全部表」(那是剖析,不是观察) */
|
||||
observing: boolean
|
||||
onSettings: () => void
|
||||
onGoSource: () => void
|
||||
onViewActive: () => void
|
||||
onChooseAll: () => void
|
||||
onRetry: () => void
|
||||
}) {
|
||||
const nothingObserve = observing && b.kind === 'nothing'
|
||||
const action = b.kind === 'disabled'
|
||||
? <button type="button" className="btn btn-sm btn-primary" onClick={onSettings} data-profile-enable="">{PT.enable}</button>
|
||||
: b.kind === 'busy'
|
||||
? <button type="button" className="btn btn-sm btn-primary" onClick={onViewActive} data-profile-view-active="">{PT.viewActive}</button>
|
||||
: b.kind === 'nothing'
|
||||
? <button type="button" className="btn btn-sm" onClick={onChooseAll} data-profile-choose-all="">{PT.chooseAll}</button>
|
||||
? (observing ? null : <button type="button" className="btn btn-sm" onClick={onChooseAll} data-profile-choose-all="">{PT.chooseAll}</button>)
|
||||
: b.kind === 'other'
|
||||
? <button type="button" className="btn btn-sm" onClick={onRetry} data-profile-retry-start="">{PT.retryStart}</button>
|
||||
: <button type="button" className="btn btn-sm" onClick={onGoSource} data-profile-go-source="">{PT.goSource}</button>
|
||||
return (
|
||||
<Notice tone={b.kind === 'busy' || b.kind === 'nothing' ? 'info' : 'warn'} attr={{ 'data-profile-blocked': b.kind }}>
|
||||
<p className="font-medium">{PT.blocked[b.kind]}</p>
|
||||
<p className="font-medium">{PT.blocked[nothingObserve ? 'nothingObserve' : b.kind]}</p>
|
||||
<p className="mt-0.5 break-words text-dim">{b.message}</p>
|
||||
{b.kind === 'busy' && b.active && (
|
||||
<p className="tnum mt-0.5 text-dim" data-profile-busy-at="">{PT.busyAt(b.active.created_by, b.active.done, b.active.total)}</p>
|
||||
)}
|
||||
<p className="mt-0.5 text-dim">{PT.blockedNext[b.kind]}</p>
|
||||
<div className="mt-2">{action}</div>
|
||||
<p className="mt-0.5 text-dim">{PT.blockedNext[nothingObserve ? 'nothingObserve' : b.kind]}</p>
|
||||
{action && <div className="mt-2">{action}</div>}
|
||||
</Notice>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -167,9 +167,19 @@ export const isProfilable = (r: Pick<CatalogTableRow, 'in_schema' | 'is_view' |
|
||||
/** 服务端「需要剖析」的口径:能剖析、并且 profile_due(从没剖析过、上次没做完、之后出现了新的待核实关系) */
|
||||
export const isProfileDue = (r: CatalogTableRow): boolean => isProfilable(r) && r.profile_due === true
|
||||
|
||||
/** 范围的几张表:needed 需要剖析的、all 全部能剖析的(服务端挑表的顺序:有待核实关系的在前,再按使用次数) */
|
||||
export function profileScopeTables(rows: CatalogTableRow[], scope: 'needed' | 'all'): string[] {
|
||||
return rows.filter(scope === 'needed' ? isProfileDue : isProfilable).map((r) => r.table_name)
|
||||
/** 能不能做取值观察:在表结构里、不是视图、有数据目录(version > 0)。同服务端 _pick_observing 的前两条;观察到期没有
|
||||
* (上一次观察在 PROFILE_OBSERVE_EVERY_H 小时以前)清单里没有,由服务端判 */
|
||||
export const isObservable = (r: Pick<CatalogTableRow, 'in_schema' | 'is_view' | 'version'>): boolean =>
|
||||
r.in_schema && !r.is_view && r.version > 0
|
||||
|
||||
/** 上一次观察多久以前才再观察(同服务端 catalog_profile_observe.OBSERVE_EVERY_H) */
|
||||
export const PROFILE_OBSERVE_EVERY_H = 12
|
||||
|
||||
/** 范围的几张表:needed 需要剖析的、all 全部能剖析的(服务端挑表的顺序:有待核实关系的在前,再按使用次数)、observe 有数据
|
||||
* 目录、可以观察的(其中最近观察过的服务端这次不观察,张数是上限) */
|
||||
export function profileScopeTables(rows: CatalogTableRow[], scope: 'needed' | 'all' | 'observe'): string[] {
|
||||
const test = scope === 'needed' ? isProfileDue : scope === 'observe' ? isObservable : isProfilable
|
||||
return rows.filter(test).map((r) => r.table_name)
|
||||
}
|
||||
|
||||
/** 因为运行原因没查成的项(计入 unfinished、使表成为部分完成);其余跳过的原因是按规则不查 */
|
||||
|
||||
@@ -21,7 +21,7 @@ export const PROFILE_POLL_MS = 1500
|
||||
|
||||
export const retryableTasks = (j: CatalogProfileJob): CatalogProfileTaskRow[] => j.tasks.filter((t) => PROFILE_RETRYABLE.has(t.status))
|
||||
|
||||
export interface ProfileStartBody { tables?: string[]; scope?: 'needed' | 'all' }
|
||||
export interface ProfileStartBody { tables?: string[]; scope?: 'needed' | 'all' | 'observe' }
|
||||
|
||||
export function useProfileJob(sourceId: string, active: CatalogActiveProfileJob | null | undefined, on: {
|
||||
/** 这一次取回来新结束的表(写进目录了,或者失败、停止了):重取清单,正在看的表在里面就重新载入 */
|
||||
|
||||
@@ -421,7 +421,9 @@ function dueOf(state, src, t) {
|
||||
}
|
||||
/** 范围 needed / all:服务端的口径(有待核实关系的在前,这里按使用次数,同清单顺序) */
|
||||
const scopeTables = (state, src, scope) => state.tables[src].filter((t) => !t.missing).sort((a, b) => b.usage - a.usage)
|
||||
.filter((t) => (scope === 'all' ? checksOf(t) > 0 && !t.is_view : dueOf(state, src, t) != null)).map((t) => t.name)
|
||||
.filter((t) => (scope === 'all' ? checksOf(t) > 0 && !t.is_view
|
||||
// 取值观察:有数据目录、不是视图的表;state.observedRecently 时都算最近观察过(服务端 12 小时内不再观察)
|
||||
: scope === 'observe' ? !!t.notes && !t.is_view && !state.observedRecently : dueOf(state, src, t) != null)).map((t) => t.name)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 假服务端的起草任务:只做排队要用的部分(建、取、停),起草本身不推
|
||||
@@ -560,6 +562,10 @@ function handlers(state, replies = {}) {
|
||||
if ((body?.tables?.length ?? 0) > 500) return json({ detail: '一次最多剖析 500 张表' }, 422)(route)
|
||||
const tables = body?.tables?.length ? [...new Set(body.tables)] : scopeTables(state, src, body?.scope ?? 'needed')
|
||||
if (!tables.length) {
|
||||
if (body?.scope === 'observe') {
|
||||
return json({ detail: '没有要观察的表:取值观察只看有数据目录的表,这些表最近 12 小时内都观察过了(或者还没有数据目录)',
|
||||
code: 'profile_nothing' }, 409)(route)
|
||||
}
|
||||
return json({ detail: '按「需要剖析的表」挑出 0 张表:表都剖析过、上次都做完了,也没有新的待核实关联关系。可以改选「全部表」,或指定要剖析的表',
|
||||
code: 'profile_nothing' }, 409)(route)
|
||||
}
|
||||
@@ -793,10 +799,14 @@ await section('剖析 · 开始前:范围、个数与预算', async () => {
|
||||
check('页头写「数据剖析」', (await head(page).getAttribute('aria-label')) === '数据剖析' && (await head(page).getAttribute('data-catalog-profile')) === '')
|
||||
await openDialog(page)
|
||||
const scopes = await box(page).locator('[data-profile-scope]').evaluateAll((els) => els.map((e) => `${e.getAttribute('data-profile-scope')}:${e.getAttribute('data-count')}`))
|
||||
const observeText = await inBox(page, '[data-profile-scope="observe"]')
|
||||
// 需要剖析:从没剖析过的订单、空日志表;上次没做完的访问记录、退款;剖析后有新关系的商品。全部:再加上客户,不含视图、
|
||||
// 没有可剖析项的配置表、只剩目录的旧表
|
||||
check('没选表、没筛选:范围是「需要剖析的 5 张表」(默认)和「全部 6 张表」', scopes.join(',') === 'needed:5,all:6'
|
||||
check('没选表、没筛选:范围是「需要剖析的 5 张表」(默认)、「全部 6 张表」和「取值观察:有数据目录的 1 张表」',
|
||||
scopes.join(',') === 'needed:5,all:6,observe:1'
|
||||
&& await box(page).locator('[data-profile-scope="needed"] input').isChecked(), scopes.join(','))
|
||||
check('……取值观察写明只观察不剖析、看哪几样、最近 12 小时内观察过的不再观察', ['取值观察:有数据目录的 1 张表', '只观察、不剖析',
|
||||
'码值分布、最新业务日期、按日行数和行数', '最近 12 小时内观察过的表这次不再观察'].every((x) => observeText.includes(x)), observeText)
|
||||
check('……写明需要剖析的口径(含上次是空表的不算)、全部不含视图', (await inBox(page, '[data-profile-scope="needed"]')).includes('从没剖析过、上次没做完,或剖析之后又出现了待核实关联关系、要取码值或日期范围的列的表。上次是空表的不算')
|
||||
&& (await inBox(page, '[data-profile-scope="all"]')).includes('不含视图'))
|
||||
const budget = await inBox(page, '[data-profile-budget]')
|
||||
@@ -840,6 +850,43 @@ await section('剖析 · 开始前:范围、个数与预算', async () => {
|
||||
await close()
|
||||
})
|
||||
|
||||
await section('剖析 · 取值观察:范围、请求与挑不出表', async () => {
|
||||
// 取值观察以前只能经定时维护触发(下一轮验收):对话框的范围里多一项「取值观察」,建任务带 scope: observe;
|
||||
// 有数据目录的表都在 12 小时内观察过时服务端 409 profile_nothing,说「没有要观察的表」,不给「改选全部表」(那是剖析)
|
||||
const state = freshState()
|
||||
const { page, sent, errors, natives, close } = await open(`/data/catalog/${S1}`, { handlers: handlers(state) })
|
||||
await page.locator('[data-catalog-row]').first().waitFor()
|
||||
await openDialog(page)
|
||||
await box(page).locator('[data-profile-scope="observe"]').click()
|
||||
check('选取值观察:预算按 1 张表估', (await inBox(page, '[data-profile-budget-total]')).startsWith('这次 1 张表'),
|
||||
await inBox(page, '[data-profile-budget-total]'))
|
||||
await page.locator('[data-profile-start]').click()
|
||||
check('开始:建任务的请求带「取值观察」范围', await until(async () => (await phase(page)) === 'running')
|
||||
&& JSON.stringify(lastBody(sent, /profile-jobs$/)) === JSON.stringify({ scope: 'observe' }), JSON.stringify(lastBody(sent, /profile-jobs$/)))
|
||||
const job = state.pjobs.at(-1)
|
||||
check('……任务的范围是 observe、只含有数据目录的订单表', job.scope === 'observe' && job.tasks.map((t) => t.table_name).join(',') === 'orders',
|
||||
`${job.scope} ${job.tasks.map((t) => t.table_name).join(',')}`)
|
||||
for (const t of job.tasks) settle(state, job, t.table_name, { queries: 4, elapsed_ms: 2000 })
|
||||
finish(job)
|
||||
check('……观察完:对话框显示结束后的结果', await until(async () => (await phase(page)) === 'done'), await phase(page))
|
||||
await page.keyboard.press('Escape')
|
||||
await until(async () => (await box(page).count()) === 0)
|
||||
|
||||
// 都在 12 小时内观察过:开始不了,说「没有要观察的表」,没有「改选全部表」
|
||||
state.observedRecently = true
|
||||
await openDialog(page)
|
||||
await box(page).locator('[data-profile-scope="observe"]').click()
|
||||
await page.locator('[data-profile-start]').click()
|
||||
check('挑不出表:说「没有要观察的表」和服务端的原话(12 小时内都观察过)', await until(async () => (await inBox(page, '[data-profile-blocked]')).startsWith('没有要观察的表'))
|
||||
&& (await inBox(page, '[data-profile-blocked]')).includes('最近 12 小时内都观察过了'), await inBox(page, '[data-profile-blocked]'))
|
||||
check('……不给「改选全部表」(那是剖析,不是观察),可以回到上一步', await box(page).locator('[data-profile-choose-all]').count() === 0
|
||||
&& await page.locator('[data-profile-back]').count() === 1)
|
||||
check('写请求只有建任务', writes(sent, /./).every((s) => /profile-jobs$/.test(s.key)), JSON.stringify(writes(sent, /./).map((s) => s.key)))
|
||||
check('没有原生对话框', natives.length === 0, natives.join(' | '))
|
||||
check('没有运行时报错', errors.length === 0, errors[0] ?? '')
|
||||
await close()
|
||||
})
|
||||
|
||||
await section('剖析 · 进行中:逐表进度、后台继续与停止', async () => {
|
||||
const state = freshState()
|
||||
const { page, sent, errors, close } = await open(`/data/catalog/${S1}`, { handlers: handlers(state) })
|
||||
|
||||
Reference in New Issue
Block a user