mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-26 05:03:01 +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:
@@ -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: {
|
||||
/** 这一次取回来新结束的表(写进目录了,或者失败、停止了):重取清单,正在看的表在里面就重新载入 */
|
||||
|
||||
Reference in New Issue
Block a user