CnOps 智能运维与可观测社区
首页开源项目实践文章视频课程常见问答开发者工具STAROps 专题
导航菜单
首页开源项目实践文章视频课程常见问答开发者工具STAROps 专题

CnOps 智能运维与可观测社区

愿景

CnOps 智能运维与可观测社区是一个以"智能运维与可观测"为核心的开放、包容、分享的技术社区,旨在聚集运维专家、开发者和爱好者,共同探讨、学习和分享可观测最佳实践与最新技术,与众多技术社区合作互动,共同探讨交叉领域的技术挑战,推动可观测领域的创新与进步。

内容社区

  • 实践文章
  • 视频课程
  • 开源项目
  • 常见问答
  • 开发者工具

友情链接

  • Prometheus
  • Grafana Lab
  • OpenTelemetry
  • LoongCollector

关注我们

阿里云云原生公众号阿里云云原生
阿里云可观测公众号阿里云可观测

Copyright © 2026 CnOps 社区. All rights reserved.

首页/开源项目/LoongCollector/如何开发扩展Flusher插件
文档目录
开发环境代码风格数据模型(C++)数据模型(Golang)
开源插件开发引导
如何开发扩展Input插件如何开发扩展Processor插件如何开发扩展Aggregator插件如何开发扩展Flusher插件如何开发Extension插件如何开发外部私有插件如何自定义构建产物中默认包含的插件插件配置项基本原则

LoongCollector

如何开发扩展Flusher插件

Flusher 插件与外部系统进行交互,将数据发送到外部,以下将从接口定义与案例2方面指导如何开发 Flusher 插件 - Init: 插件初始化接口,对于Flusher 主要作用是创建外部资源链接 - Description: 插件描述 - IsReady:插件系统在调用 Flush / Export 前会调用该接口检查当前 flusher 是否仍能够处理更多数据;若返回否,会等待后重试。...

如何开发 Flusher 插件

Flusher 插件与外部系统进行交互,将数据发送到外部,以下将从接口定义与案例2方面指导如何开发 Flusher 插件

Flusher 接口定义

  • Init: 插件初始化接口,对于Flusher 主要作用是创建外部资源链接

  • Description: 插件描述

  • IsReady:插件系统在调用 Flush / Export 前会调用该接口检查当前 flusher 是否仍能够处理更多数据;若返回否,会等待后重试。

  • 数据出口:分为 FlusherV1 的 Flush 与 FlusherV2 的 Export(见下方接口)。V1 的 Flush 使用 projectName / logstoreName / configName 及 []*protocol.LogGroup;V2 的 Export 使用 []*models.PipelineGroupEvents 与 PipelineContext。详见 Golang 侧数据模型 与 插件系统。

  • SetUrgent:标识 LoongCollector 即将退出,用于让 Flusher 放宽 IsReady、加快吐出等。注释中与 V2 对接的方法名为 Export(取代旧描述里的 Flush 字样)。

  • Stop:停止Flusher 插件,比如断开与外部系统交互的链接

公共接口 Flusher 与两种出口扩展(源码 pkg/pipeline/flusher.go):

type Flusher interface {
    Init(Context) error
    Description() string
    IsReady(projectName string, logstoreName string, logstoreKey int64) bool
    SetUrgent(flag bool)
    Stop() error
}

type FlusherV1 interface {
    Flusher
    Flush(projectName string, logstoreName string, configName string, logGroupList []*protocol.LogGroup) error
}

type FlusherV2 interface {
    Flusher
    Export([]*models.PipelineGroupEvents, PipelineContext) error
}

Flusher 开发

  1. 创建 Issue:描述插件能力与使用场景,由社区讨论可行性与排期;review 通过后再进入实现。
  2. 实现接口:实现 Flusher,并任选 FlusherV1(Flush)或 FlusherV2(Export)。可从 flusher/stdout 或 flusher/http 对照阅读。
  3. 注册插件:在 init 中通过 pipeline.AddFlusherCreator 注册,或向 pipeline.Flushers 写入构造函数。采集配置里的 Type 必须以 flusher_ 开头。
  4. 纳入构建:将本插件所在包加入 插件引用配置文件 的 common / linux / windows 等节,执行构建以更新 plugins/all。请勿手改生成文件。
  5. 测试:编写或补充单元测试、E2E 场景,具体流程与约定见 单元测试 与 E2E测试。
  6. 代码规范:使用 make lint 检查代码风格与静态检查项。
  7. 提交变更:提交 Pull Request,并在描述中说明行为、配置示例与测试结果(如有)。

文章大纲