ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

DataHub 摄取任务遥测上报框架(Reporting Framework)实战与源码解析

DataHub 摄取任务遥测上报框架(Reporting Framework)实战与源码解析 DataHub 摄取任务遥测上报框架Reporting Framework实战与源码解析【免费下载链接】datahubThe Context Platform for your Data and AI Stack项目地址: https://gitcode.com/GitHub_Trending/da/datahub导读本文围绕 DataHub 元数据摄取ingestion管线中的Reporting Framework遥测上报框架展开讲解如何通过reporting配置项把每次摄取任务运行job run的遥测数据telemetry上报到 DataHub 后端或其他目的地用于监控、审计与排障。读完本文你将掌握在 recipe 中配置datahub上报 Provider 与pipeline_name的正确姿势、服务端statefulIngestion能力的前置检查方法、以及如何基于PipelineRunListener接口开发自定义上报 Provider 并注册为 DataHub 插件。DataHub 摄取遥测上报框架是什么DataHub 的 reporting framework 允许在摄取ingestion管线中配置一个或多个reporting provider上报提供者将每次摄取任务运行的遥测信息发送到外部系统以便监控。它由 DataHub 的stateful ingestion有状态摄取框架提供能力支撑datahub类型的 reporting provider 随标准客户端一起安装默认把摄取任务遥测上报到 DataHub 后端。从架构上看上报机制与任务/作业job概念绑定一条摄取管线pipeline内的 source 连接器会执行多个 job每个 job 的运行遥测由 reporting provider 负责保存与检索。遥测数据最终落到 DataHub 后端的timeseries aspect中即datahubIngestionRunSummary从而支持按时间维度查询与监控。前置条件服务端需具备有状态摄取能力注意该功能要求服务端具备statefulIngestion能力这是 metadata service 版本 0.8.20的功能。可以通过访问 GMS 的/config接口检查curl http://datahub-gms-endpoint/config { models: { }, statefulIngestionCapable: true, # -- 必须存在且为 true retention: true, noCode: true }只有statefulIngestionCapable字段存在且为truedatahub类型的 reporting provider 才能正常工作。若服务端版本过旧或未开启该能力上报会失败或静默无效。在 Recipe 中配置 reporting provider摄取管线的 reporting providers 是一个配置对象列表位于管线的reporting配置参数下每个 reporting provider 配置都是type config键值对。遥测数据会发送给列表中的所有 reporting provider。YAML recipe 中约定.表示嵌套字段[idx]表示对象数组中的第 idx 个元素。字段是否必填默认值说明reporting[idx].type✅datahub已在 DataHub 中注册的摄取上报 provider 类型。reporting[idx].config若在管线级别配置了datahub_api则使用该配置否则使用默认的DatahubClientConfig默认值参见 metadata-ingestion/src/datahub/ingestion/graph/client.py。初始化 datahub reporting provider 所需的配置。pipeline_name✅摄取管线的名称。作为该管线内每个 job 上报的遥测数据的标识键identifying key的一部分。其中pipeline_name至关重要从源码看它会参与遥测实体的唯一标识生成。在 datahub_ingestion_run_summary_provider.py 中generate_unique_key依据source.type、pipeline_name与platform_instance生成标识键generate_entity_name将其拼装为形如[CLI] {source_type} ({platform_instance}) [{pipeline_name}]的实体名。更改pipeline_name会导致旧的遥测数据无法再与新的运行关联因此应将其视为长期稳定的标识。支持的 Source所有基于 SQL 的 source如 snowflake、bigquery、redshift 等。snowflake_usage。完整示例配置source: type: snowflake config: username: user_name password: password role: role host_port: host_port warehouse: ware_house # Rest of the source specific params ... # 必填。更改它会导致旧遥测数据的关联丢失。 pipeline_name: my_snowflake_pipeline_1 # 管线级别的 datahub_api 配置。 datahub_api: # 可选。若提供该配置将被 datahub 摄取状态 provider 使用。 server: http://localhost:8080 sink: type: datahub-rest config: server: http://localhost:8080 reporting: - type: datahub # 必填 config: # 可选 datahub_api: # 默认值 server: http://localhost:8080该配置的行为要点pipeline_name在顶层声明作为遥测标识键的一部分顶层datahub_api是可选配置若存在则同时被datahub摄取状态 provider 与 reporting provider 复用reporting[0].config.datahub_api可显式覆盖上报目的端若不写则回落到管线级datahub_api再回落为默认DatahubClientConfig上报通道的承载 sink 即管线自身的 sinkdatahub-rest/datahub-kafka。管线如何加载与调度 reporting provider源码视角注册表与插件机制datahub与file两个 reporting provider 通过 Python entry points 注册。注册表定义在 reporting_provider_registry.pyfrom datahub.ingestion.api.pipeline_run_listener import PipelineRunListener from datahub.ingestion.api.registry import PluginRegistry reporting_provider_registry PluginRegistry[PipelineRunListener]() reporting_provider_registry.register_from_entrypoint( datahub.ingestion.reporting_provider.plugins )而 entry points 在 metadata-ingestion/setup.py 中声明datahub.ingestion.reporting_provider.plugins: [ datahub datahub.ingestion.reporting.datahub_ingestion_run_summary_provider:DatahubIngestionRunSummaryProvider, file datahub.ingestion.reporting.file_reporter:FileReporter, ],可以看到类型字符串到实现类的映射datahub→DatahubIngestionRunSummaryProviderfile→FileReporter。测试 test_plugin_system.py 也验证了注册表中包含[datahub, file]两个 provider。管线初始化与默认上报行为在 pipeline.py 的_configure_reporting中上报 provider 的装配逻辑为dry-run 模式下不上报任何遥测数据report_toNone表示完全禁用上报report_todatahub默认值时若 recipe 的reporting列表中还没有datahub类型会自动追加一个默认的{type: datahub}reporterreport_to被指定为其他字符串时被当作文件名自动追加{type: file, config: {filename: report_to}}文件上报器随后遍历reporting列表从注册表解析类型并调用reporter_class.create(...)实例化初始化失败时若该 reporter 标记了required: true则直接抛错否则仅记录警告。required字段定义在 pipeline_config.py 的ReporterConfig中。在管线生命周期中on_start在摄取开始时被调用_notify_reporters_on_ingestion_starton_completion通过 sink 的register_pre_shutdown_callback挂载在摄取结束、sink 关闭前执行pipeline.py。完成回调会根据管线最终状态传入SUCCESS、FAILURE、CANCELLED或UNKNOWN状态码pipeline.py。生命周期接口PipelineRunListener所有 reporting provider 必须实现 PipelineRunListener 抽象基类它定义了三个方法class PipelineRunListener(ABC): abstractmethod def on_start(self, ctx: PipelineContext) - None: # 摄取启动时的钩子 pass abstractmethod def on_completion( self, status: str, report: Dict[str, Any], ctx: PipelineContext, ) - None: # 摄取完成/失败时的钩子 pass classmethod abstractmethod def create( cls, config_dict: Dict[str, Any], ctx: PipelineContext, sink: Sink, ) - PipelineRunListener: # 创建与初始化 passdatahub 上报 Provider 的内部原理DatahubIngestionRunSummaryProvidertype 为datahub是开箱即用的上报实现构建在datahub_api客户端与 DataHub 后端的timeseries aspect 能力之上实现在 datahub_ingestion_run_summary_provider.py。配置项字段是否必填默认值说明type✅datahub已在 DataHub 中注册的摄取上报 provider 类型。config管线级datahub_api配置否则默认DatahubClientConfig默认值参见 metadata-ingestion/src/datahub/ingestion/graph/client.py。初始化 datahub reporting provider 所需的配置。此外实现中还定义了report_recipe: bool True是否将脱敏后的 recipe 上报可通过config.report_recipe: false关闭以及config.sink允许显式指定上报所用的 sink否则复用管线当前 sink且要求 sink 必须是datahub-rest或datahub-kafka否则上报器会被禁用。运行时的数据流初始化根据pipeline_name、source.type、platform_instance生成唯一标识键与实体名形如[CLI] snowflake (prod) [my_snowflake_pipeline_1]并构造dataHubIngestionSource实体的dataHubIngestionSourceInfoaspect含脱敏 recipe、DataHub 版本号、executor id异步写入 sink。on_start构造dataHubExecutionRequest实体的dataHubExecutionRequestInputaspect记录任务名CLI Ingestion、recipe、版本、请求时间与来源并通过同步模式EmitMode.SYNC_PRIMARY立即写入保证执行请求先于结果落库。on_completion将运行报告structured report与日志缓冲拼接为 summary通过SecretMaskingFilter对 secret 进行脱敏后写入dataHubExecutionRequestResultaspect包含状态、开始时间、持续时长durationMs与结构化报告StructuredExecutionReportClass类型CLI_INGESTJSON content type。其中 summary 会被截断到 800,000 字符_MAX_SUMMARY_SIZE以确保生成的 MCPMetadataChangeProposal不会超过 GMS 的 payload 限制。遥测数据模型上报数据的模型为 DatahubIngestionRunSummary.pdl这是一个timeseries 类型 aspect包含三类字段标识与状态pipelineName用户提供的稳定唯一标识如my_snowflake1-to-datahub、platformInstanceId摄取管线运行所针对的实例如 BigQuery 项目 id、MySQL 主机名等、runId、runStatusSucceeded / Skipped / Failed 等。运行指标numWorkUnitsCommitted、numWorkUnitsCreated、numEventsMCE MCP 事件数、numEntities唯一 entity urn 数、numAspects、numSourceAPICalls/totalLatencySourceAPICalls、numSinkAPICalls/totalLatencySinkAPICalls、numWarnings、numErrors、numEntitiesSkipped。运行上下文config非敏感的 YAML 配置键值对 JSON 字符串、custom_summary、softwareVersion、systemHostName、operatingSystemName、numProcessors、totalMemory、availableMemory等主机信息。正是这些 timeseries 字段使得每次摄取运行的历史遥测可以在 DataHub 中被检索、聚合与监控例如按pipelineName与platformInstanceId追踪一段时间内各任务的成功率与耗时变化。开发者指南编写自定义上报 Provider除了开箱即用的datahubprovider你还可以按照下面的模式为摄取管线接入自定义上报目标例如本地文件、内部监控系统等。步骤一实现 PipelineRunListener参考自带的fileprovider —— file_reporter.py。它把结构化运行报告写成 JSON 文件class FileReporterConfig(ConfigModel): filename: str format: str json field_validator(format, modeafter) classmethod def only_json_supported(cls, v: str) - str: if v and v.lower() ! json: raise ValueError( fFormat {v} is not yet supported. Only json is supported at this time ) return von_start为空实现on_completion将报告通过SecretMaskingFilter脱敏后写入指定文件。配置里format字段目前仅支持json其他值会在校验阶段直接报错——这说明自定义 provider 应尽可能在配置校验期暴露错误。步骤二注册到 entry_points在 metadata-ingestion/setup.py 的entry_points中加入datahub.ingestion.reporting_provider.plugins键格式为type module路径:类名entry_points { # snip other keys datahub.ingestion.reporting_provider.plugins: [ datahub datahub.ingestion.reporting.datahub_ingestion_run_summary_provider:DatahubIngestionRunSummaryProvider, file datahub.ingestion.reporting.file_reporter:FileReporter, # 在此追加自定义 provider例如 # my_reporter my_package.my_reporter:MyReporter, ], }注册完成后PluginRegistry会通过register_from_entrypoint自动发现该类型用户即可在 recipe 的reporting列表中以type: my_reporter引用它。使用建议与注意事项保持pipeline_name稳定它是遥测数据关联的历史键改名会导致旧的运行遥测无法与后续运行建立关联也会改变生成的 ingestion source 实体名。先确认服务端能力在开启datahubreporting 前通过curl gms/config检查statefulIngestionCapable是否为true版本低于0.8.20的 metadata service 不支持该功能。上报通道复用管线 sinkdatahubprovider 默认复用管线的datahub-rest/datahub-kafkasink如果 sink 类型不受支持上报器会被自动禁用抛出IgnorableError并被当作非致命问题处理。敏感信息保护上报的 recipe 与运行报告会经过redact_raw_config与SecretMaskingFilter脱敏如不希望 recipe 被上报可在 provider 的config中设置report_recipe: false。超大运行报告summary 会被截断到 800,000 字符以内避免生成的 MCP 超出 GMS payload 限制对超长日志应依赖 DataHub 侧的日志检索能力而非遥测 summary。dry-run 模式不会触发任何上报便于本地调试时避免污染线上遥测数据。【免费下载链接】datahubThe Context Platform for your Data and AI Stack项目地址: https://gitcode.com/GitHub_Trending/da/datahub创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表