<@U088WCP3B4P> elementary的新鲜度检测帮我详细解释一下
# ask-elementary-ai
l
@kapa.ai elementary的新鲜度检测帮我详细解释一下
k
A message from kapa.ai
下面是对 Elementary 新鲜度(Freshness)检测的详细说明,涵盖“自动化监控”和“dbt 测试”两类方式,以及常见疑问与配置要点。 - 两种能力概览 - 自动化 Freshness 监控(Cloud 自动创建,基于仓库元数据,零配置、低成本):学习表的更新频率,实时判断“距上次更新的间隔”是否超出模型预测(或固定 SLA),用于发现数据延迟与中断(默认对 dbt 项目里的 sources 启用,可按需扩展到更多表)([Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors); [Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness)). - dbt 测试 freshness_anomalies(查询原始数据):按时间桶统计“最大新鲜度”,并用历史窗口训练、在检测窗口内找异常点(需配置 timestamp_column)([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies); [How it works](https://docs.elementary-data.com/data-tests/how-anomaly-detection-works))。 - 自动化 Freshness 监控(Cloud) - 模式 - Anomaly detection(默认):用约 21 天历史学习更新节奏(含季节性/工作日规律),将“现在到最后一次更新的间隔”与模型预测对比判定异常(可调灵敏度)([Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness)). - SLA based:为表设定固定阈值(如应在 X 小时内更新),超过即告警(完全可控)([Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness)). - 结果阅读:时间线右端黑色三角为“现在”,关注“最后更新到现在”的间隔;绿色=正常,黄/红=超出期望(虚线显示上限)。支持在界面里调节灵敏度、设置严重级别与元数据标签([Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness)). - 警报:默认不触发,需要到 Setup > Alert Rules 勾选“automated monitors”或为特定数据集创建规则([Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors))。 - dbt 测试:freshness_anomalies - 作用:根据“更新之间的时间间隔”(新鲜度)找异常。按时间桶(默认天)把数据分桶,在训练期内计算每个桶的“最大新鲜度”,将检测期(默认最近2天)的值与历史期望范围对比,若为离群值则失败。默认仅对“延迟”(spike)告警([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies); [How anomaly tests work](https://docs.elementary-data.com/data-tests/how-anomaly-detection-works)). - 必填与常用参数:timestamp_column 必填;可调 time_bucket、training_period、detection_period、anomaly_sensitivity、detection_delay、ignore_small_changes 等([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies)). - 指标含义澄清:图表中一个“时间桶”的新鲜度是该桶内的“最大新鲜度”(通常为相邻两条 timestamp 之间经过的秒数的最大值);显示的“上次更新”时间点,指向产生该最大新鲜度的异常时间戳,易与“真正的最后一行时间”混淆([Slack 讨论:最大新鲜度解释](https://slack.com/archives/C02CTC89LAX/p1718731076544139)). - 若漏更一天未报警:可能因为历史波动使其未被判定为异常,可降低 anomaly_sensitivity 提高敏感度进行试错([Slack 建议:调低灵敏度](https://slack.com/archives/C02CTC89LAX/p1703157711512959))。 - 连续流/事件场景:更适合用 event_freshness_anomalies,度量“事件发生时间”与“加载时间”的差;若未提供 update_timestamp_column,则度量“现在”与最近事件时间的差([event_freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/event-freshness-anomalies))。 - 与 dbt Source Freshness 集成 - 若使用 dbt source freshness 并希望在 Elementary 中告警,需要在 dbt Cloud 任务中先执行 dbt source freshness,再执行 dbt run-operation elementary.upload_source_freshness;Elementary 侧运行 edr monitor 以生成/分发告警([Slack 指南](https://slack.com/archives/C02CTC89LAX/p1667567840168569))。 - 最佳实践与定位差异 - 自动化监控:零配置、基于元数据、覆盖广、低成本,适合全局“表是否按时更新”的守护([Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors)). - dbt 测试:可深度定制时间桶与训练/检测窗口,适合对关键表做更精细、可解释的阈值与趋势检测([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies); [How it works](https://docs.elementary-data.com/data-tests/how-anomaly-detection-works)). - 当“表更新准时但数据本身过期”时,可用 dbt_utils.recency 或 dbt source freshness 做“数据新鲜度”校验,或用 event_freshness_anomalies 衡量事件实际到库时延(而非仅看更新节奏)(该思路见最佳实践页)([Best practices – Data sources](https://docs.elementary-data.com/best-practices/detection-and-coverage#common-testing-use-cases)).
l
@kapa.ai 你刚才说的为表设定固定阈值是什么意思?
k
A message from kapa.ai
指的是把“新鲜度告警”的判定改为固定的 SLA 阈值,而不是用模型自适应阈值。 - 在 Elementary Cloud 的自动化 Freshness 监控中,可将检测方式从“Automatic(模型学习更新频率)”切换为“Manual(SLA based)”,手动设定如“X 小时/天未更新就告警”的阈值;一旦超过该时长即触发告警(可配置为 Warning 或 Fail) ([Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness); [Monitors Configuration](https://docs.elementary-data.com/features/anomaly-detection/monitors-configuration)). - 这样做适用于更新时间非常规律、需要明确 SLO/SLA 的资产;若继续用“Automatic”模式,则由模型基于最近约 21 天的更新历史自动判断是否延迟(可调灵敏度) ([Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness))。 如果你使用的是 dbt 的 source freshness,也可通过 error_after/warn_after 设定固定阈值,并配合 elementary.upload_source_freshness 将结果带入 Elementary 做告警 ([Slack 指南](https://slack.com/archives/C02CTC89LAX/p1667567840168569)).
l
@kapa.ai 我不用elementary could,还能像你说的切换为manual吗
k
A message from kapa.ai
不行,切换为 Manual(SLA based)是 Elementary Cloud 的“自动化 Freshness 监控”提供的配置项,需在 Cloud 界面中设定固定阈值(SLA)。如果不使用 Cloud,这个切换不可用(在 OSS 里对应的是 dbt 测试而非 Cloud 监控)。([Monitors Configuration](https://docs.elementary-data.com/features/anomaly-detection/monitors-configuration); [Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness)) 替代方案(OSS): - 使用 dbt 的 source freshness(warn_after/error_after)设固定阈值,并执行 dbt run-operation elementary.upload_source_freshness 将结果上传到 Elementary,以便告警。([Slack 指南](https://slack.com/archives/C02CTC89LAX/p1667567840168569)) - 使用 Elementary 的 anomaly 测试(freshness_anomalies 或 event_freshness_anomalies)做异常检测;它们是基于统计异常而非固定 SLA,如需固定阈值则建议用 dbt freshness。([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies); [event_freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/event-freshness-anomalies))
l
@kapa.ai 那你再重新给我说明下elementary的新鲜度检测
k
A message from kapa.ai
下面按“Cloud 自动化监控”和“OSS/dbt 测试”两类,简明说明 Elementary 的新鲜度检测。 - Cloud 自动化 Freshness 监控 - 两种模式: - Automatic(默认):基于约 21 天历史更新间隔学习节奏(含工作日/季节性),用“现在到最近一次更新的时间差”对比模型预测判断是否延迟,支持灵敏度调节与严重级别设置(告警颜色与阈线直观呈现)(“Automated Freshness Monitor”)。([Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness)) - SLA based(Manual):手动设定固定阈值(如 X 小时/天内需更新),超过即告警,适合更新规律、需强约束的表。可在侧边配置中切换模式与灵敏度/严重级别等。(同上)([Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness)) - 自动覆盖:默认为 dbt 项目中的 sources 自动创建新鲜度监控,也可按需扩展到其他表(Cloud)([Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness))。 - 与 OSS 的区别:Cloud 监控基于元数据、实时、零查询成本;OSS 测试在 dbt 中执行、需要查询数据且按计划运行(非实时)([Anomaly Detection Tests - OSS vs Cloud](https://docs.elementary-data.com/data-tests/anomaly-detection-tests-oss-vs-cloud))。 - OSS/dbt 测试:freshness_anomalies - 作用:监控“更新之间的时间间隔”(新鲜度)是否出现异常。将数据按时间桶(默认日)分桶,在训练期汇总每桶的最大新鲜度,再用检测期与历史比较,若出现异常(默认仅检测延迟 spike)则测试失败(需配置 timestamp_column)([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies))。 - 关键配置:timestamp_column(必填);time_bucket、training_period、detection_period、anomaly_sensitivity、detection_delay、ignore_small_changes 等(默认 anomaly_direction: spike,仅报延迟)([freshness_anomalies–Test configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies))。 - 适用性提示:若表长期不更新且历史也不更新,模型会认为“无更新是常态”,测试可能不报错;需在规律更新的表上最有效,或调整桶粒度/训练期等以提升敏感度(来源于工作机制描述)([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies))。 - 事件型数据:event_freshness_anomalies - 监控“事件时间”与“入库时间”之间的时延;若仅提供 event_timestamp_column,则监控“现在”与最近事件时间的差,适合连续/流式更新场景(可选 update_timestamp_column)([event_freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/event-freshness-anomalies))。 - 配置项:event_timestamp_column(必填)、update_timestamp_column(可选)、time_bucket、training/detection_period、anomaly_sensitivity 等(默认仅报延迟)([event_freshness_anomalies–Test configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/event-freshness-anomalies#test-configuration))。 - 与 dbt Source Freshness(固定阈值)搭配 - 若你需要固定阈值(warn_after/error_after),在 OSS 中使用 dbt source freshness;想把其结果纳入 Elementary 告警,需要在运行 dbt source freshness 后执行 upload_source_freshness(dbt Cloud 用 dbt run-operation elementary.upload_source_freshness;本地/核心版用 edr run-operation upload-source-freshness 并在 edr monitor 前执行)([Slack 指南](https://slack.com/archives/C02CTC89LAX/p1667567840168569); [Guide](https://docs.elementary-data.com/oss/guides/collect-dbt-source-freshness))。 - 实践建议 - 源表:同时关注更新新鲜度与数据本身新鲜度。若“表按时更新但数据值过期”,可用 dbt_utils.recency 或 dbt source freshness 进行“数据新鲜度”校验;事件类用 event_freshness_anomalies 更贴切(最佳实践)([Best practices – Data sources](https://docs.elementary-data.com/best-practices/detection-and-coverage#common-testing-use-cases))。
l
@kapa.ai dbt_utils.recency不是只能用在,拍的;
k
A message from kapa.ai
我不太确定你的问题想表达的是哪种限制。根据已知资料: - dbt-utils 的 recency 测试既可以用于 sources,也可以用于模型;社区里有人把它用于监控“最近是否有数据到来”(非 dbt source freshness),并确认它作为“常规 dbt 测试”会出现在 Elementary 的报告里(只是不能被“注册成”Freshness类别的专用卡片)([社区问答](https://slack.com/archives/C02CTC89LAX/p1695199887349889); [最佳实践-数据源](https://docs.elementary-data.com/best-practices/detection-and-coverage#common-testing-use-cases))。 - Elementary 团队也明确:dbt 的 source freshness 仅适用于 sources;而 Elementary 的 freshness_anomalies 既可用于 sources 也可用于模型(如果你考虑用 Elementary 自带的 freshness 检测)([社区答复](https://slack.com/archives/C02CTC89LAX/p1696346623801349))。 如果你指的是 “recency 只能用于某种对象(例如只能用于 source、不能用于 view/表)”,知识来源没有明确这种限制;它作为通用 dbt 测试,可在你为其提供所需字段配置时使用。若需要固定阈值的新鲜度校验,recency 是常见替代方案;若要异常检测型的新鲜度,则用 Elementary 的 freshness_anomalies 更合适(两者都被 Elementary 收集展示)([数据测试概览](https://docs.elementary-data.com/features/data-tests/data-tests-overview); [最佳实践-数据源](https://docs.elementary-data.com/best-practices/detection-and-coverage#common-testing-use-cases))。
l
@kapa.ai dbt_utils.recency不是只能用在model表吗?
k
A message from kapa.ai
不是。根据社区讨论与最佳实践,dbt_utils.recency 可以用于 sources,也可以用于 models;作为常规 dbt 测试执行并出现在 Elementary 的报告中(只是不能被“注册”为 Elementary 仪表盘里的专属 Freshness 卡片)([社区问答](https://slack.com/archives/C02CTC89LAX/p1695199887349889); [最佳实践-数据源](https://docs.elementary-data.com/best-practices/detection-and-coverage#common-testing-use-cases)).
l
@kapa.ai 介绍一下elementary是什么东西
k
A message from kapa.ai
Elementary 是一个面向 dbt 的数据可观测性平台,帮助数据与分析工程师保障数据产品的可靠性与质量。它有两种形态: - Elementary Cloud Platform:与 dbt 工作流深度集成,提供自动化的新鲜度与体量监控、ML 异常检测、数据测试与模式校验、列级血缘、告警与事件管理、简单数据目录,以及与 BI/告警/工单等丰富集成,支持在 UI 与代码双向配置(可将 UI 变更回写到代码仓库)([Elementary Cloud Platform](https://docs.elementary-data.com/cloud/introduction); [Platform features](https://docs.elementary-data.com/cloud/features); [Integrations](https://docs.elementary-data.com/features/integrations))。 - Elementary OSS:开源 CLI 与 dbt 包的组合。dbt 包提供异常检测与元数据表;CLI 用于发送告警并生成/自托管观测报告,集中查看 dbt 运行与测试结果、血缘、覆盖率与健康状况(适合小团队的基础检测与自部署)([Elementary OSS](https://docs.elementary-data.com/oss/oss-introduction); [Cloud vs OSS](https://docs.elementary-data.com/overview/cloud-vs-oss); [dbt package](https://docs.elementary-data.com/guides/modules-overview/dbt-package))。 核心能力包括: - 将 dbt 原生测试、社区包测试与 Elementary 自带测试统一管理与展示(代码优先,避免重复配置与锁定)([dbt, Packages and Elementary Tests](https://docs.elementary-data.com/features/data-tests/dbt-tests)). - 异常检测与自动化监控(新鲜度、体量等),以及模式变更校验等测试,支持近实时结果与灵活告警配置(Cloud)([Platform features](https://docs.elementary-data.com/cloud/features)). - 安全架构:仅需访问 Elementary schema 的日志与元数据,不读取业务数据(Cloud)([Introduction](https://docs.elementary-data.com/introduction)).
l
@kapa.ai 你能帮我介绍一下elementary的新鲜度检测吗,举个形象生动的例子说明下
k
A message from kapa.ai
下面用简明对比+小例子说明 Elementary 的新鲜度检测。 - 两种新鲜度检测方式 - Cloud 自动化 Freshness 监控(基于元数据,零配置、低成本): - 默认“自动检测”模式:学习表的更新节奏(约21天历史,含工作日/季节性),实时比较“现在到最后一次更新的间隔”是否超出模型预测;也可改为“固定SLA阈值”(Manual),超过固定时长就告警(可调灵敏度与严重级别)(“Automated Freshness Monitor”)([Automated freshness](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness); [Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors))。 - OSS/dbt 测试 freshness_anomalies(查询数据本身): - 将数据按时间桶分组(默认按天),在训练期(默认14天)计算每个桶的“最大新鲜度”(更新间隔),在检测期(默认最近2天)与历史对比,若出现异常则失败;默认仅对“延迟/变慢”(spike)告警(需配置 timestamp_column)([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies))。 - 形象例子 - 场景:orders 表工作日每天上午8点更新一次,周末不更。 - Cloud 自动化监控: - 模型学到“工作日≈24小时更新、周末停更”的规律。今天中午12点仍未更新,会把“现在-最后一次更新”的间隔与模型预测对比:若超出预期(例如应在10点前更新),就告警;若你选择SLA模式并设“48小时内必须更新”,超过即告警([Automated freshness](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness))。 - OSS 测试 freshness_anomalies: - 你配置 timestamp_column=loaded_at、time_bucket=day。测试会把最近14天按天分桶,计算每个“日桶”的最大更新间隔,然后在最近2天内找是否出现异常的“更慢/延迟”值;如果昨天或今天的更新间隔显著大于历史,就判失败([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies))。 - 注意:若这个表本来就长期不更新,历史也是“不更新”,则不会被视为异常;它更适合“本应规律更新、但突然变慢或停更”的检测([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies))。 - 补充:事件型数据 - 连续/流式数据可用 event_freshness_anomalies:度量“事件时间”和“入库时间”的差(或“现在—最近事件时间”),用同样的异常检测思路判断是否变慢([event freshness anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/event-freshness-anomalies))。 - 固定阈值需求(非 Cloud) - 在 OSS 中如需固定阈值,可用 dbt source freshness 的 warn_after/error_after,并将结果通过 elementary.upload_source_freshness 上传以在 Elementary 中可见与告警([Slack 指南](https://slack.com/archives/C02CTC89LAX/p1667567840168569))。
l
@kapa.ai cloud的方式,我的source数据源你不可能通过查询元数据获取更新时间的吧?
k
A message from kapa.ai
可以。Elementary Cloud 的“自动化新鲜度监控”并不依赖你表内的业务时间列,而是基于数据仓库的元数据(如 information schema、query history)来判断“这张表何时被更新过”,进而学习更新频率并检测是否延迟。这种方式零配置、对计算成本几乎为零,默认对你 dbt 项目中的 sources 启用;如果需要,也可以覆盖非 dbt 表(可选项)([Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors); [Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness); [Slack 说明:信息架构与查询历史](https://slack.com/archives/C02CTC89LAX/p1716464124470759))。 要点: - Cloud 侧通过仓库元数据追踪“表的更新事件与频率”,不读取你的业务数据本身(因此不需要你在 source 中配置 timestamp_column)([Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors))。 - 模型会回填并学习至少约 21 天的历史更新模式,包含工作日/周末等季节性,然后判断“当前距离最近一次更新”的间隔是否超出预期,或你可切换为固定 SLA 阈值模式(Cloud 中设置)([Automated Freshness Monitor](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness))。
l
@kapa.ai 那你完全可以在oss这样做,因为比如数据库snowflake就能通过查询数据仓库的元数据获取更新时间,做到不查询业务数据的
k
A message from kapa.ai
结论:目前“基于仓库元数据、零配置、自动覆盖的更新监控”是 Elementary Cloud 的能力,OSS 并不提供同样的自动化机制。 - Cloud 怎么做的:Cloud 会持续读取你的数据仓库元数据(如 information schema、query history),自动为 dbt 项目里的 sources 建立“自动化新鲜度/体量监控”,用 ML 学习更新频率并在延迟时告警,且不查询业务数据本身(也可扩展到非 dbt 表)。(这是 Cloud 的平台服务特性)(“自动化监控基于元数据,覆盖所有生产表、零配置”;并明确“监控信息架构与查询历史”,默认对 dbt sources 启用)([Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors); [Automated Freshness](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness); [Slack 说明](https://slack.com/archives/C02CTC89LAX/p1716464124470759))。 - OSS 的定位与差异:官方对比里,Freshness/Volume 这类“管道健康监控”在 OSS 是以 dbt 测试实现、需要你手动在代码中添加与运行;而 Cloud 则是由平台侧自动创建、基于元数据、实时检测、无需配置(也不消耗 DWH 计算)。(换言之,OSS 并没有提供 Cloud 那样的“自动化元数据监控引擎”)([Anomaly Tests - OSS vs Cloud](https://docs.elementary-data.com/data-tests/anomaly-detection-tests-oss-vs-cloud))。 - 你在 Snowflake 自行“查元数据做新鲜度”的想法在技术上可行,但属于你自建能力,Elementary OSS 官方文档未提供“在 OSS 里用信息架构/查询历史自动监控”的现成功能或指令。OSS 侧可选的是: - 用 Elementary 的 freshness_anomalies/event_freshness_anomalies(需要查询数据本身,手动配置并随 dbt 运行)([freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies))。 - 用 dbt source freshness 设定固定阈值,并将结果通过 elementary.upload_source_freshness 上传到 Elementary 以纳入告警与报告(仍需你在流水线中显式执行)([Collect source freshness](https://docs.elementary-data.com/oss/guides/collect-dbt-source-freshness); [Slack 指南](https://slack.com/archives/C02CTC89LAX/p1705449360937459))。 如果你希望“不查业务数据、依赖元数据、自动监控所有表”,这是 Cloud 的产品功能;在 OSS 中需要自行实现元数据采集与检测逻辑,知识库未提供现成支持或范式(我无法在资料中找到 OSS 对应的官方实现)。
l
@kapa.ai volume-anomalies再给我这样说明下
k
A message from kapa.ai
下面按“是什么、怎么工作、怎么配置、例子”简明说明 elementary.volume_anomalies。 - 是什么 - 监控表的行数随时间的变化,检测突增/突降的体量异常。若未配置 timestamp_column,就监控表的总行数;配置后按时间桶统计增量/行数趋势(默认按天)并做异常检测([Volume anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/volume-anomalies))。 - 工作机制 - 运行 dbt test 时,将数据按 time_bucket 分桶(默认日);采集训练期内各桶的行数(默认14天),再将最近的检测期(默认2天)与历史对比;若检测期内有点超出期望范围即判为异常并使测试失败(仅对“完成的时间桶”执行判断)([How anomaly tests work](https://docs.elementary-data.com/data-tests/how-anomaly-detection-works); [Volume anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/volume-anomalies))。 - 建议配置 timestamp_column;若不配,则测试相当于“快照当下总行数”,适合每日定时跑以形成时间序列([Test configuration Q&A](https://slack.com/archives/C02CTC89LAX/p1675261374154379))。 - 基本配置示例
Copy code
yaml   models:     - name: your_model       tests:         - elementary.volume_anomalies:             timestamp_column: event_time            # 建议配置             where_expression: status = 'active'     # 可选:过滤             time_bucket:               period: day                           # 可选:hour/day/week/month               count: 1
可选参数还包括 anomaly_sensitivity、anomaly_direction(both/spike/drop)、training_period、detection_period、seasonality、fail_on_zero、ignore_small_changes、detection_delay、anomaly_exclude_metrics 等([Test configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/volume-anomalies#test-configuration))。 - 形象例子 - 你的 orders 表工作日每天约新增 10 万行。过去两周都很稳定。今天测试跑完后发现“昨天”的时间桶只有 2 万行,远低于历史分布的期望区间,于是 volume_anomalies 测试失败,提示存在“体量下跌”的异常([Volume anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/volume-anomalies); [How anomaly tests work](https://docs.elementary-data.com/data-tests/how-anomaly-detection-works))。 - 相关提示 - 想按维度看某列不同取值的体量是否异常,可用 dimension_anomalies(按维度分组计数检测分布变化)([Add tests – Dimension anomalies](https://docs.elementary-data.com/data-tests/add-elementary-tests))。 - 在 Cloud 端还有“自动化体量监控”,基于元数据、零配置,适合全量覆盖(与本测试不同的实现方式)([Automated Volume](https://docs.elementary-data.com/features/anomaly-detection/automated-volume); [Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors))。
l
@kapa.ai 那你是怎么做到不消耗 DWH 计算的?
k
A message from kapa.ai
在 Cloud 的“自动化监控”(新鲜度/体量)里,Elementary 只读取数据仓库的元数据与查询历史来判断表是否更新、更新频率与增减行数,不去扫描业务表数据本身,因此不消耗你的仓库计算资源(或近乎为零成本)。这些监控由平台在云端执行,基于 information schema 与 query history 回填并训练模型(默认回填至少约 21 天历史),实现零配置、实时检测(包括 sources)(“仅使用仓库元数据”“无计算成本增加”)([Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors); [Automated Freshness & Volume](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors); [Automated Freshness](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness))。此外,Cloud 的安全与权限模型也强调只读 Elementary schema 与元数据,不读取原始数据([Security and Privacy](https://docs.elementary-data.com/cloud/general/security-and-privacy))。
l
@kapa.ai 比如说数据库snowflake,你查询的不也是snowflake的元数据吗?不也是要执行sql吗,只要执行sql就会触发dwh消耗啊
k
A message from kapa.ai
是的,会查询 Snowflake 的信息架构与查询历史等“元数据表/视图”,这些也是通过 SQL 访问的。区别在于: - 访问的是系统元数据(如 INFORMATION_SCHEMA、QUERY_HISTORY),不扫描业务表数据,查询量小、成本极低;Elementary Cloud 的自动化新鲜度/体量监控就是基于这些元数据完成的,因此对你的仓库计算基本没有新增负载(相较于扫描业务数据的测试) ([Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors); [Automated Freshness & Volume](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors)). - 安全与权限上,Cloud 只需对 Elementary schema 的只读权限以及读取信息架构/查询历史的权限,不读取原始业务数据;连接走加密通道,可通过固定 IP 加入 allowlist(体现为最低必要权限与最小化风险) ([Security and privacy](https://docs.elementary-data.com/cloud/general/security-and-privacy); [Connect to Snowflake](https://docs.elementary-data.com/cloud/integrations/dwh/snowflake)). 换言之,“会执行 SQL”不等于“显著消耗 DWH 计算”。用元数据做监控与直接扫描大表的数据开销不在一个量级,这也是 Cloud 自动化监控强调“仅用元数据、无需计算资源”的原因(面向实时、全覆盖的监控场景) ([Anomaly tests – OSS vs Cloud](https://docs.elementary-data.com/data-tests/anomaly-detection-tests-oss-vs-cloud)).
l
@kapa.ai 那我也可以自己实现自定义测试,达到你这样的目的啊?那我还要你elementary干什么呢
k
A message from kapa.ai
可以自己做,但 Elementary 省去的是“从能做,到做得好、做得久”的巨大投入与运维成本,具体体现在: - 自动化与覆盖面 - Cloud 自动为所有生产表建立基于元数据的 Freshness/Volume 监控,零配置、实时、低成本;包括可扩到非 dbt 表与“来源的来源”检测,而不是你手动为每张表写规则与调度(并长期维护)([Monitors overview](https://docs.elementary-data.com/features/anomaly-detection/monitors-overview); [Slack: 自动发现与元数据来源](https://slack.com/archives/C02CTC89LAX/p1716464124470759); [Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors))。 - 检测质量与易用性 - ML 驱动的异常检测,自动学习频率、季节性与趋势;也可一键切为固定 SLA 阈值,减少你手写阈值与反复调参的工作量(含灵敏度、反馈调优)([Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors); [Automated Freshness](https://docs.elementary-data.com/features/anomaly-detection/automated-freshness))。 - 将 dbt 原生测试、包测试与 Elementary 测试统一管理,代码即配置,避免多处重复与厂商锁定(UI 还可批量加测并回写代码)([dbt tests in Elementary](https://docs.elementary-data.com/features/data-tests/dbt-tests); [Configuration-as-Code](https://docs.elementary-data.com/features/config-as-code))。 - 端到端响应能力 - 列级血缘(到 BI),带测试与监控结果,用于根因与影响分析;未被消费的数据集识别、变更影响分析等,都是自建很难长期维护的能力(性能/可用性优化过的可视化)([Lineage](https://docs.elementary-data.com/features/data-lineage/lineage))。 - 事件分组、告警路由、所有权、事故管理与历史指标,支持跨团队协同与SLA治理,而不是零散脚本+手动沟通(减少告警疲劳)([Alerts & Incidents](https://docs.elementary-data.com/features/alerts-and-incidents/alerts-and-incidents-overview); [Incidents](https://docs.elementary-data.com/features/alerts-and-incidents/incidents); [Incident management](https://docs.elementary-data.com/features/alerts-and-incidents/incident-management))。 - 成本与可靠性 - 元数据监控不扫描业务数据,带来“近乎零仓库计算”的广域覆盖;平台负责回填历史与模型维护,缩短落地时间并避免自研长期维护成本与隐性风险(可选将告警范围、灵敏度等集中调优)([Automated monitors](https://docs.elementary-data.com/features/anomaly-detection/automated-monitors); [OSS vs Cloud](https://docs.elementary-data.com/overview/cloud-vs-oss))。 - 渐进式路径 - 你也可先用 OSS 做基础检测与评估;当团队需要规模化协作、面向业务用户的可视化与自动化监控,再切到 Cloud,二者在 dbt 工作流中无缝衔接(配置与测试可延续)([Cloud vs OSS](https://docs.elementary-data.com/overview/cloud-vs-oss); [Cloud introduction](https://docs.elementary-data.com/cloud/introduction))。 总结:自建能实现“点状”检测;Elementary 提供的是“体系化的平台能力”——自动覆盖、智能检测、代码与 UI 一体化、列级血缘与事故响应,全流程打通,目的是更快、更稳、更省人力地把数据可靠性做成“长期工程”(而非一次性脚本)([Cloud features](https://docs.elementary-data.com/cloud/features)).