Agent skill

Clickhouse Batchwriter

by Rain-kl in Rain-kl/OpenFlare

Wavelet 项目专用:当新增或修改 ClickHouse 批量写入、接入 internal/infra/persistence/batchwriter、将业务域异步 flush 到分析表、迁移 riskcontrol/节点访问日志/可观测时序写入、或评估 asyncinsert 与背压策略时必须使用。本技能指导分层职责、各域独立 Writer 实例、repository 批量 API…

Apache-2.0Auto-check passedDatabases

Install Clickhouse Batchwriter

skills CLI
$ npx skills add Rain-kl/OpenFlare --skill clickhouse-batchwriter -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install Rain-kl/OpenFlare clickhouse-batchwriter --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/Rain-kl/OpenFlare.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/clickhouse-batchwriter .claude/skills/clickhouse-batchwriter && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
clickhouse-batchwriter
GitHub stars
288
Token cost
~1.4k tokens
SKILL.md length
343 words
Files
1
Skills in repo
12
Repo updated
First seen
Licence
Apache-2.0

At a glance

Wavelet 项目专用:当新增或修改 ClickHouse 批量写入、接入 internal/infra/persistence/batchwriter、将业务域异步 flush 到分析表、迁移 riskcontrol/节点访问日志/可观测时序写入、或评估 asyncinsert 与背压策略时必须使用。本技能指导分层职责、各域独立 Writer 实例、repository 批量 API…

  • Works in 6 steps: Model:在 internal/model/analytics/ 定义… → Goose DDL:在… → Repository:实现 BatchInsertX(ctx,… → …
  • Tasks that involve Data warehousing
  • SKILL.md covers 分层职责, batchwriter 框架契约, 各域独立实例(不共享队列) and 新增 ClickHouse 写入工作流, plus 6 more sections
  • Calls go and make

What it does

Clickhouse Batchwriter is an agent skill from Rain-kl/OpenFlare. Wavelet 项目专用:当新增或修改 ClickHouse 批量写入、接入 internal/infra/persistence/batchwriter、将业务域异步 flush 到分析表、迁移 riskcontrol/节点访问日志/可观测时序写入、或评估 asyncinsert 与背压策略时必须使用。本技能指导分层职责、各域独立 Writer 实例、repository 批量 API 与禁止写法。

Its SKILL.md is about 1.4k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Databases, covering Data warehousing. It works with ClickHouse and Cloudflare. The repository describes itself as: OpenFlare is an open-source CDN orchestration and edge security platform. It supports reverse proxy, centralized configuration synchronization, in-network tunneling (Tunnels)… The licence is Apache-2.0.

When your agent uses it

  • Tasks that involve Data warehousing

Example prompts

  • “/clickhouse-batchwriter”

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. Model:在 internal/model/analytics/ 定义 struct 与 BatchInsertSQL()(列顺序与 goose DDL 一致)。
  2. Goose DDL:在 internal/infra/persistence/migrator/goose/clickhouse/ 新增迁移(见 database-migration)。
  3. Repository:实现 BatchInsertX(ctx, []analyticsmodel.X) error
  4. Writer 胶水(internal/apps//)
  5. 测试
  6. 运行 make code-check;有 API 变更时 make swagger。

What it can do on your machine

Read from SKILL.md and the folder at commit 7c2304d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • go
    • make

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Clickhouse Batchwriter loads about 1.4k tokens when it runs. Until then it costs about 57 tokens; SKILL.md has 343 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~57
When it runs · the whole SKILL.md, loaded when a task matches
~1.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from Rain-kl/OpenFlare at commit 7c2304d, republished under its Apache-2.0 licence (© Rain-kl). 343 words, ~1,434 tokens.

Download SKILL.mdSave it as .claude/skills/clickhouse-batchwriter/SKILL.md (or your agent's skills folder).
name
clickhouse-batchwriter
description
Wavelet 项目专用:当新增或修改 ClickHouse 批量写入、接入 internal/infra/persistence/batchwriter、将业务域异步 flush 到分析表、迁移 risk_control/节点访问日志/可观测时序写入、或评估 async_insert 与背压策略时必须使用。本技能指导分层职责、各域独立 Writer 实例、repository 批量 API 与禁止写法。

ClickHouse 批量写入开发

开始前阅读根目录 AGENTS.md。ClickHouse 是辅助 OLAP 存储,厌恶高频单条写入(过多小 part);写入路径必须优先批量或异步聚合。

DDL 与表结构变更见 database-migration 技能。日志/分析用途表的判定、三库回落与切换见 logstore 技能。本技能只覆盖运行时写入架构。

分层职责

层级路径职责
连接internal/infra/persistence/clickhouse.goChConn(原生批量写)、ChDB(GORM 查询);禁止在业务包直接 clickhouse.Open
批量框架internal/infra/persistence/batchwriter/泛型队列 + 按条数/时间 flush + 非阻塞入队 + 优雅停机;各业务域独立实例
Modelinternal/model/analytics/列定义、TableName()、BatchInsertSQL()(及可选 InsertColumns())
Repositoryinternal/repository/analytics/BatchInsert* / BatchInsertNodeAccessLogs 等;PrepareBatch + 多行 Append + 一次 Send
Appsinternal/apps/<domain>/采集、入队、背压;FlushFunc 只调 logstore / repository,不写 SQL、不 PrepareBatch
装配internal/platform/bootstrap/bootstrap.go进程启动时调用 Writer.Start;初始化时需调用 lifecycle.OnShutdown 挂载停机钩子
生命周期internal/platform/lifecycle/lifecycle.go统一协调全局并发优雅停机,业务包无需在 bootstrap.go 中硬编码 Stop 逻辑

禁止在 Handler / middleware 内直接 db.ChConn.PrepareBatch;禁止在 repository 内启动 goroutine 或维护全局 channel(队列生命周期由 apps + bootstrap 或专用 writer 包负责)。

batchwriter 框架契约

go
writer, err := batchwriter.New[YourType](cfg, flushFunc, opts...)
writer.Start(ctx)
writer.TryEnqueue(item)   // 非阻塞;满则 false
writer.IsFull()           // 背压探测
writer.Stop(stopCtx)      // close 队列 + drain + 最终 flush
Config 默认值(batchwriter.DefaultConfig())
  • QueueSize: 10_000
  • MaxBatchSize: 1_000
  • MinBatchSize: 50(未达阈值则跳过按时间 flush,除非设了 MaxFlushWait)
  • FlushInterval: 1s

各域可独立覆盖;可观测低频指标可用更小 MaxBatchSize(如 100)与更长 FlushInterval(如 2–5s),但不要退化为逐条 Send。

可选回调
  • WithFlushErrorHandler[T]:flush 失败时记录日志;批次丢弃后 worker 继续
  • WithDropHandler[T]:队列满或未 Start 时丢弃项
FlushFunc 规范
  • 签名:func(ctx context.Context, items []T) error
  • 日志/分析用途表:logstore.Active(ctx) 再调对应 BatchInsert*。禁止 apps 直连 analyticsrepo 或 db.ChConn。
  • 仅 CH、无需主库回落的分析表:才直接调 repository/analytics 的 BatchInsert*。
  • 在 flush 边界记录一次错误日志,不要把 DB 驱动错误直接暴露给 HTTP 客户端
  • Start 使用 context.WithoutCancel(parent),避免请求 ctx 取消中断后台 flush

各域独立实例(不共享队列)

每个业务域拥有自己的 Writer、配置与 FlushFunc:

域表写入路径
管理端审计w_user_access_logsrisk_control → batchwriter → logstore.Active
边缘访问日志of_node_access_logsopenflare/chwriter → logstore.Active
可观测时序of_node_metric_snapshots 等openflare/chwriter 分表 writer + 进程内短 TTL 去重 → logstore.Active

不要把 audit、access log、observability 并入同一 channel。

新增 ClickHouse 写入工作流

  1. Model:在 internal/model/analytics/ 定义 struct 与 BatchInsertSQL()(列顺序与 goose DDL 一致)。
  2. Goose DDL:在 internal/infra/persistence/migrator/goose/clickhouse/ 新增迁移(见 database-migration)。
  3. Repository:实现 BatchInsertX(ctx, []analyticsmodel.X) error:
    • len(items)==0 直接返回
    • db.ChConn == nil 返回明确错误
    • 一次 PrepareBatch → 循环 Append → 一次 Send
  4. Writer 胶水(internal/apps/<domain>/):
    • New + Start,并在初始化逻辑内通过 lifecycle.OnShutdown("your_writer_name", Stop) 注册停机回调
    • 日志表的 FlushFunc 调 logstore.Active(见 logstore skill)
    • 业务路径 TryEnqueue;HTTP 背压用 IsFull()
  5. 测试:
    • repository:mock ChConn 验证 BatchInsertSQL 与 append 列数
    • batchwriter:go test ./internal/infra/persistence/batchwriter
  6. 运行 make code-check;有 API 变更时 make swagger。

背压与丢弃策略

场景推荐策略
管理端 API 审计队列满 → IsFull() 触发 429(见 risk_control middleware)
Agent 心跳指标队列满 → WithDropHandler 记 warn;不阻塞心跳响应
边缘 access log优先扩大队列与 batch;必要时丢弃最旧或采样

禁止写法

go
// ❌ 单条伪批量:每条都 PrepareBatch + Send
batch.Append(oneRow)
batch.Send()

// ❌ 写前 OLTP 式去重(高 RTT + 仍产生小 part)
SELECT count() FROM ... WHERE node_id = ? AND captured_at = ?

// ❌ Handler 内直接写 ClickHouse
db.ChConn.PrepareBatch(...)

// ❌ 全局单队列承载所有分析表
var globalChan chan any

去重应使用:ReplacingMergeTree、查询侧 argMax、或进程内短 TTL 去重缓存——不要在每次 insert 前 SELECT count()。

async_insert(补充,非主方案)

可在 internal/infra/persistence/clickhouse.go 的 Settings 增加服务端异步写入作为第二层防护:

go
"async_insert": 1,
"wait_for_async_insert": 1,

不能替代应用层批量;接入前需评估丢失可观测性与服务端负载。优先完成 batchwriter 接入后再考虑。

Bootstrap 装配示例

go
// internal/platform/bootstrap/bootstrap.go(示意)
func RegisterAPI(ctx context.Context) {
    // 日志 writer 不依赖 clickhouse.enabled:flush 时由 logstore 选库
    risk_control.InitLogWriter(ctx)
}
  • RegisterAPI / RegisterAll:Start
  • 进程优雅停机:业务模块在初始化时调用 lifecycle.OnShutdown 注册,由 bootstrap.Stop() 代理 lifecycle.Stop() 并发停机。
  • 使用 sync.Once 保证幂等

验证清单

bash
go test ./internal/infra/persistence/batchwriter
go test ./internal/repository/analytics
make code-check
  • flush 按 MaxBatchSize 与 FlushInterval 触发
  • Stop 能 drain 队列内剩余项
  • repository 层无 goroutine、无 channel
  • 日志表:clickhouse.enabled: false 时 writer 仍 Start,flush 走主库 logstore
  • 仅 CH 的分析表:未启用 CH 时不要 Start、不要入队

相关文件速查

  • 框架:internal/infra/persistence/batchwriter/{config,writer,errs}.go
  • 连接:internal/infra/persistence/clickhouse.go
  • 审计写入:internal/apps/risk_control/logics.go
  • OpenFlare 写入胶水:internal/apps/openflare/chwriter/writer.go
  • 日志抽象:internal/repository/logstore
  • 节点访问日志 CH 实现:internal/repository/analytics/node_access_log_writer.go
  • 可观测 CH 实现:internal/repository/analytics/node_observability_writer.go
  • 生命周期管理器:internal/platform/lifecycle/lifecycle.go
  • Bootstrap:internal/platform/bootstrap/bootstrap.go

© Rain-kl, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/clickhouse-batchwriter of Rain-kl/OpenFlare.

Open the folder on GitHubat commit 7c2304d

Compare with similar skills

Clickhouse Batchwriter next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Clickhouse Batchwriter compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Clickhouse Batchwriter this skillRain-kl/OpenFlare288—~1.4kAutomated safety check: PassApache-2.0
Clickhouse Logs Queriessupabase/supabase111k—~2.4kAutomated safety check: PassApache-2.0
Keeper Stress AnalysisClickHouse/ClickHouse50k—~4.7kAutomated safety check: PassApache-2.0
Perf ComparisonClickHouse/ClickHouse50k—~3.9kAutomated safety check: NotesApache-2.0
Patch Release CheckClickHouse/ClickHouse50k—~4kAutomated safety check: NotesApache-2.0
Chdb SQLvemetric/vemetric3951 repos~1.2kAutomated safety check: PassApache-2.0

Similar skills

  • Clickhouse Logs Queries

    supabase/supabase

    Official

    Write, review, and migrate Supabase logs queries against the ClickHouse-backed logs table (the logs.all.otel analytics endpoint).

    111k GitHub stars~2.4k tokensUpdated today
    DatabasesAuto-check passed
  • Keeper Stress Analysis

    ClickHouse/ClickHouse

    Analyze ClickHouse Keeper stress-test results from play.clickhouse.com / keeperstresstests data warehouse.

    50k GitHub stars~4.7k tokensUpdated today
    DatabasesAuto-check passed
  • Perf Comparison

    ClickHouse/ClickHouse

    Evaluate ClickHouse performance test results from existing CI/dashboard data or local perf.py runs.

    50k GitHub stars~3.9k tokensUpdated today
    DatabasesAuto-check: notes
  • Patch Release Check

    ClickHouse/ClickHouse

    Check whether ClickHouse's supported versions (last 3 majors + latest LTS) have recent stable patch releases, diagnose why the scheduled AutoReleases pipeline failed, and identify which releases…

    50k GitHub stars~4k tokensUpdated today
    DatabasesAuto-check: notes
  • Chdb SQL

    vemetric/vemetric

    A skill your agent uses when the user wants to run SQL — especially analytical SQL — on local files (parquet/csv/json), URLs, S3 paths, or remote databases (Postgres, MySQL, MongoDB, ClickHouse…

    395 GitHub starsUsed in 1 repo~1.2k tokens
    DatabasesAuto-check passed
  • Bisect

    ClickHouse/ClickHouse

    Bisect a ClickHouse regression using pre-built master binaries from CI.

    50k GitHub stars~1.4k tokensUpdated today
    DatabasesAuto-check passed

More from Rain-kl/OpenFlare

All 12 skills in this repo
  • Code Review Skill

    Rain-kl/OpenFlare

    Provides comprehensive code review guidance for React 19, Vue 3, Angular 17+, Svelte 5, Rust, TypeScript, Java, PHP, Python, Django, Go, C/.NET, Kotlin, Swift, NestJS, C/C++, and more.

    288 GitHub stars~2.3k tokensUpdated yesterday
    Auto-check: notes
  • Go Logging

    Rain-kl/OpenFlare

    在选择日志方案、配置 slog、编写结构化日志语句或决定日志级别时使用。也适用于设置生产日志、为日志添加请求作用域上下文或从 log 迁移到 slog 的场景,即使用户未明确提及日志。不涵盖错误处理策略(参见 go-error-handling)。

    288 GitHub stars~1.1k tokensUpdated yesterday
    Auto-check passed
  • New API

    Rain-kl/OpenFlare

    Wavelet 项目专用:当新增或修改自定义业务 API、新增业务路由、新增 service 层核心逻辑时必须使用。本技能指导包职责划分、推荐文件结构、路由解耦、Swagger 文档生成与质量门禁验证。

    288 GitHub stars~1.4k tokensUpdated yesterday
    Auto-check passed
  • Cache Framework

    Rain-kl/OpenFlare

    Wavelet 项目专用:当新增或修改业务缓存(RAM/Redis/DB 三层读路径)、缓存失效、多节点 pub/sub 同步、或评估高频读是否应接入缓存时必须使用。本技能说明系统标准缓存框架、参考实现、禁止写法与分布式一致性要求。

    288 GitHub stars~1.7k tokensUpdated yesterday
    Auto-check passed
  • Database Migration

    Rain-kl/OpenFlare

    Wavelet 项目专用:当新增或修改数据库表结构、索引、初始化数据、系统配置 seed、模板 seed、默认管理员、goose SQL 迁移、internal/infra/persistence/migrator、ClickHouse 分析库 DDL 或数据库升级流程时必须使用。本技能指导在 internal/infra/persistence/migrator/goose 下编写…

    288 GitHub stars~1.3k tokensUpdated yesterday
    Auto-check passed
  • File Upload

    Rain-kl/OpenFlare

    Wavelet 项目专用:当业务需要上传文件、读取已上传文件、在 Worker/任务中程序化摄取字节流、选择存储引擎能力、或排查 wuploads / 文件统计异常时必须使用。本技能指导 storage 与 upload 分层、upload.Ingest 策略选型、前后端接入与禁止旁路写表。

    288 GitHub stars~1.7k tokensUpdated yesterday
    Auto-check passed

Categories

Questions about Clickhouse Batchwriter

What does Clickhouse Batchwriter do?

Wavelet 项目专用:当新增或修改 ClickHouse 批量写入、接入 internal/infra/persistence/batchwriter、将业务域异步 flush 到分析表、迁移 riskcontrol/节点访问日志/可观测时序写入、或评估 asyncinsert 与背压策略时必须使用。本技能指导分层职责、各域独立 Writer 实例、repository 批量 API…. Clickhouse Batchwriter is an agent skill from Rain-kl/OpenFlare.

When should I use Clickhouse Batchwriter?

Clickhouse Batchwriter fits situations like: tasks that involve Data warehousing.

How do I install Clickhouse Batchwriter in Claude Code?

Run `npx skills add Rain-kl/OpenFlare --skill clickhouse-batchwriter -a claude-code`. Or copy the skill folder (.agents/skills/clickhouse-batchwriter in Rain-kl/OpenFlare) into .claude/skills/clickhouse-batchwriter in your project. Claude Code loads it when a task matches its description.

How do I install Clickhouse Batchwriter in Codex?

Run `npx skills add Rain-kl/OpenFlare --skill clickhouse-batchwriter -a codex`. Or copy the skill folder (.agents/skills/clickhouse-batchwriter in Rain-kl/OpenFlare) into .agents/skills/clickhouse-batchwriter in your project. Codex loads it when a task matches its description.

Can I use Clickhouse Batchwriter in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add Rain-kl/OpenFlare --skill clickhouse-batchwriter -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/clickhouse-batchwriter, .gemini/skills/clickhouse-batchwriter, .github/skills/clickhouse-batchwriter and .opencode/skills/clickhouse-batchwriter in your project.

What does Clickhouse Batchwriter need to run?

Going by SKILL.md and its folder, Clickhouse Batchwriter needs the command-line tools its instructions call (go and make).

Does Clickhouse Batchwriter access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Clickhouse Batchwriter safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Clickhouse Batchwriter use?

Clickhouse Batchwriter is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Clickhouse Batchwriter use?

About 1.4k tokens (SKILL.md is roughly 5.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Clickhouse Batchwriter?

Skills that share tags, products or a category with Clickhouse Batchwriter: Clickhouse Logs Queries (supabase/supabase, 111k stars), Keeper Stress Analysis (ClickHouse/ClickHouse, 50k stars), Perf Comparison (ClickHouse/ClickHouse, 50k stars) and Patch Release Check (ClickHouse/ClickHouse, 50k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Clickhouse Batchwriter?

Rain-kl (a GitHub user) maintains it in Rain-kl/OpenFlare, which has 288 GitHub stars. The repository holds 12 skills in this directory. The repository was last updated on October 8, 2026.

Source: Rain-kl/OpenFlare on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.