For the complete documentation index, see llms.txt. This page is also available as Markdown.

如何开发扩展Flusher插件

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

Flusher 接口定义

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

  • Description: 插件描述

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

  • 数据出口:分为 FlusherV1FlushFlusherV2Export(见下方接口)。V1 的 Flush 使用 projectName / logstoreName / configName[]*protocol.LogGroup;V2 的 Export 使用 []*models.PipelineGroupEventsPipelineContext。详见 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,并任选 FlusherV1Flush)或 FlusherV2Export)。可从 flusher/stdoutflusher/http 对照阅读。

  3. 注册插件:在 init 中通过 pipeline.AddFlusherCreator 注册,或向 pipeline.Flushers 写入构造函数。采集配置里的 Type 必须以 flusher_ 开头。

  4. 纳入构建:将本插件所在包加入 插件引用配置文件common / linux / windows 等节,执行构建以更新 plugins/all请勿手改生成文件。

  5. 测试:编写或补充单元测试、E2E 场景,具体流程与约定见 单元测试E2E测试

  6. 代码规范:使用 make lint 检查代码风格与静态检查项。

  7. 提交变更:提交 Pull Request,并在描述中说明行为、配置示例与测试结果(如有)。

Last updated