altinity/altinity-skills

altinity-expert-clickhouse-kafka

Diagnose ClickHouse Kafka engine health, stuck consumers, thread pool capacity, consumer lag, slow materialized views, and Kafka rack-awareness or cross-AZ traffic.

ソースを見る

使い方

  1. インストールコマンドをコピーし、自分の環境へ導入する前にソースを確認します。
  2. 必要なツール、認証情報、対応環境を原文で確認します。
  3. 入力と成果物を指定し、出力を資料と照合します。
npx skills add https://github.com/altinity/altinity-skills --skill altinity-expert-clickhouse-kafka

開始前の確認

  • 導入にはモデル契約、API枠、ファイルへのアクセス許可は含まれません。
  • スター数や導入数は活動の指標であり、独立した品質・安全性試験ではありません。
リポジトリの原文

見出し、例、コード、表、リンク、参照画像を含む原文を表示しています。

Kafka engine health

Answers "are the Kafka consumers polling, committing and keeping up, and is anything starving them?" from system.kafka_consumers, system.metric_log, system.query_views_log and system.text_log. Run altinity-expert-clickhouse-connection first if the connection mode, cluster and time window are not yet established.

Query packs

  • checks.sql — 7 checks: consumption health per consumer (kafka-01), average rows per commit (kafka-02), rebalances and assignments (kafka-03), consumers versus message broker pool size (kafka-04), pool utilization over 12 hours (kafka-05, needs system.metric_log), slow materialized views on Kafka tables (kafka-06, needs system.query_views_log), Kafka messages in the log (kafka-07, needs system.text_log).
  • advanced_checks.sql — 4 checks: consumer exception drill-down for one table (needs {db} and {kafka_table}), total lag per table, lag per partition, broker connection health. The last three parse rdkafka_stat. The file also contains a three-statement consumption-speed recipe marked @skip-matrix: it creates a temporary table, sleeps, then compares snapshots, so all three statements must run in ONE clickhouse-client session. It cannot run over MCP or as separate --query calls.
  • troubleshooting.md — common Kafka errors and configuration fixes (ACL errors, poll interval, dead letter queue, offset rewind, parallel consumption tuning).
  • references/rack-awareness.md — cross-AZ and client.rack investigation; load it when the question involves AWS MSK, KAFKA_CLIENT_RACK, cross-AZ cost, VPC endpoints, or a Kafka cluster migration.
  • reference.md — background (Kafka engine and librdkafka settings); read only when you need to explain a recommendation.

How to run the query packs

  1. Read each pack file from this skill's directory (the skill loader prints the directory path).
  2. Run statements one at a time, never a whole file. Statements end with ; and start with a -- @check <id> <title> header; keep the id with its result.
  3. Honor -- @requires: skip the statement when the named table is missing, when keeper is required and the server has no Keeper/ZooKeeper, or when the version condition is not met. List skipped ids with the reason.
  4. Keep {cluster} as written when a cluster macro exists; otherwise apply the connection skill's rewrite rule. Any other {placeholder} is a template variable: substitute a real value first or skip the statement.
  5. On an error, record the check id and the first line of the error, then continue. Only for UNKNOWN_IDENTIFIER, run DESCRIBE TABLE system.<table> and drop the missing column.
  6. A severity column is the verdict for that row. Copy it; do not re-grade.

Interpretation rules

  • A consumer is stuck when last_exception_time >= last_poll_time or last_exception_time >= last_commit_time: it is failing rather than progressing. Otherwise treat it as healthy even if lag exists.
  • exceptions is a tuple of arrays with matching indices. exceptions.time[-1] and exceptions.text[-1] are the most recent error; quote both.
  • kafka_consumers > mb_pool_size (kafka-04) is thread starvation: consumers wait for a free thread. Fix by raising background_message_broker_schedule_pool_size (default 16). Size it as the total of all Kafka, RabbitMQ and NATS consumers plus 25 percent.
  • Materialized view average duration above 30 seconds (kafka-06) risks exceeding max.poll.interval.ms, which gets the consumer kicked from the group. Errored view executions are usually the rebalance interrupting a batch mid-flight, not an independent bug.
  • The most common cause of a slow view on a Kafka table is several JSONExtract calls re-parsing the same JSON blob. The fix is one-pass JSONExtract(json, 'Tuple(...)') plus tupleElement(); see troubleshooting.md in this directory.
  • Pool utilization over 12 hours (kafka-05): values sustained near the pool size mean capacity pressure; spikes that line up with lag mean temporary overload; a flat zero means the consumers are not running at all, which is a different finding from lag.
  • rdkafka_stat is empty unless <statistics_interval_ms> is set in the Kafka engine config. If it is empty, report the three lag and broker checks as skipped for a missing prerequisite, not as OK.
  • client.rack alone changes nothing: the brokers must run RackAwareReplicaSelector, which is not the default. Verify the broker-side selector before recommending any rack setting.
  • In librdkafka broker counters, tx and rx are request and response counts while txbytes and rxbytes are bytes. Attribute per-broker and cross-AZ traffic from the byte counters only.

Report format

  1. Header: connection mode, cluster or "single node", ClickHouse version, time window.
  2. Findings: table with columns check, severity, object, evidence, recommendation; one row per finding, Critical first. Evidence quotes the numbers from the result rows.
  3. OK checks: one line listing the check ids that returned no problem rows.
  4. Skipped and failed checks: id and reason or first error line. Never omit this section.
  5. Next steps: skills to load next and immediate actions.

Next skills

  • Materialized view inserts are the bottleneck, or insert latency dominates → load skill altinity-expert-clickhouse-ingestion
  • High merge memory or a part backlog on the destination table → load skill altinity-expert-clickhouse-merges
  • The view query itself is slow independent of Kafka → load skill altinity-expert-clickhouse-reporting
  • The destination table design or the view chain looks wrong → load skill altinity-expert-clickhouse-schema
  • Cross-AZ cost remains after the Kafka checks, or the traffic uses ClickHouse interserver ports → load skill altinity-expert-clickhouse-replication
  • Message broker pool saturation needs a longer trend than 12 hours → load skill altinity-expert-clickhouse-metrics

タスクに関連する項目

同じリポジトリから

関連する Skills

すべての Skills
altinity
コミュニティ

altinity-expert-clickhouse-caches

Analyzes the ClickHouse mark cache, uncompressed cache, query cache and compiled expression cache, their hit ratios and their RAM footprint. Use when cache hit ratios are poor, caches take too much RAM, mark counts look excessive, or cache sizing needs tuning.

導入数
1
GitHub Stars
17
更新日
9月17日
altinity
コミュニティ

altinity-expert-clickhouse-index-analysis

Analyze whether ClickHouse indexes (PRIMARY KEY, ORDER BY, skipping indexes, projections) are effective for the actual query patterns. Use when investigating index effectiveness, ORDER BY key design, query-to-index alignment, or when queries scan far more data than expected.

導入数
1
GitHub Stars
17
更新日
9月17日
altinity
コミュニティ

altinity-expert-clickhouse-ingestion

Diagnoses ClickHouse INSERT performance, batch sizing, part creation patterns and materialized-view overhead on inserts. Use for slow inserts, failed inserts, micro-batching, high part creation rate, Buffer table flushes and data pipeline issues.

導入数
1
GitHub Stars
17
更新日
9月17日
altinity
コミュニティ

altinity-expert-clickhouse-memory

Diagnoses ClickHouse RAM usage, memory limits, OOM errors and the allocation breakdown across queries, caches, dictionaries and primary keys. Use when MEMORYLIMITEXCEEDED appears, the server is killed by the OOM killer, memory grows steadily, or GROUP BY and JOIN queries run out of memory.

導入数
1
GitHub Stars
17
更新日
9月17日