Batch analytics events into an EventSink and compute stats from it
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 78/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
Read packages/core/src/analytics/collector.ts and packages/core/src/storage/memory.ts, then compare the existing stats shape and event query API. Implement the buffered sink and stats function in packages/core/src/analytics/sink.ts; use packages/core/tests/analytics/sink.test.ts to cover batching, timers, failures, concurrent flushes, and matching stats. Done when the module is exported, the tests pass, and a minor changeset is added.
索引モデルが issue の本文から書いたものです。
説明
Analytics live in an AnalyticsCollector in memory (packages/core/src/analytics/collector.ts), capped at 1000 events and per process, so on serverless the stats only describe one instance. @chatcops/core now has an EventSink interface (packages/core/src/storage/types.ts) that stores can back with Redis, Postgres or D1. Writing every event as its own database call would be slow, so this issue adds a small buffer in front of the sink and a function that turns the sink's counts back into today's stats shape.
What to do
Create packages/core/src/analytics/sink.ts:
export class BufferedEventSink {
constructor(sink: EventSink, options?: { maxBatch?: number; flushMs?: number });
/** Queues an event. Never throws and never waits. */
track(type: string, data?: Record<string, unknown>): void;
/** Writes everything queued. Safe to call any time, including concurrently. */
flush(): Promise<void>;
}
/** The same shape as AnalyticsCollector.getStats(), from the sink's counts. */
export function statsFromSink(sink: EventSink, range: { from: number; to: number }): Promise<AnalyticsStats>;
maxBatchdefaults to 50: reaching it starts a flush right away.flushMsdefaults to 2000: the firsttrackafter an empty buffer starts onesetTimeout. Create the timer only insidetrack, never in the constructor, because Workers forbid timers at global scope. Callunref()on it when it exists (Node), so it doesn't keep a process alive.- A failed
sink.writelogs one line,[chatcops] analytics write failed: <message>, and drops that batch. Analytics must never break a chat. - Two flushes at the same time must not write the same event twice.
statsFromSinkthrows a clear error when the sink has noquery. It countsconversation:startedas conversations,message:sentplusmessage:receivedas messages, andlead:capturedas leads. Keep the existing field names (includingleadsCapture), since people already read them.
Where to look
packages/core/src/analytics/collector.tsandpackages/core/tests/analytics/collector.test.tspackages/core/src/storage/memory.ts(memoryStorage().eventshasquery, use it in the tests)
Acceptance criteria
- New
packages/core/src/analytics/sink.tsandpackages/core/tests/analytics/sink.test.ts, exported from@chatcops/core - Tests (fake timers): flush on
maxBatch, flush onflushMs, no timer before the firsttrack, a failing sink logs and drops, concurrentflush()calls write each event once -
statsFromSinkonmemoryStorage().eventsmatches whatAnalyticsCollector.getStats()gives for the same events - Changeset for
@chatcops/core(minor) -
pnpm test:coverageandpnpm lintpass
Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #<this issue number>. Setup notes (pnpm, build before test) are in CONTRIBUTING.md.
- 主要言語
- TypeScript
- スター
- 13
- フォーク
- 7
- 平均マージ
- 3時間 33分
- マージ済み PR(30日)
- 176
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
codercops/chatcops のほかの issue
-
Add startup checks that catch weak or leaked security settings対応中かも @varun-pahuja が 2 日前に担当しました。 オープンenhancement good first issue hacktoberfest server
codercops/chatcops#231 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Type-check the TypeScript samples in the docs対応中かも @An16og が 1 日前に担当しました。 オープンdocumentation hacktoberfest help wanted testing
難易度 4/5 3〜5日 初心者へのやさしさ 70/100
codercops/chatcops#201 · コメント 7 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
hacktoberfest
難易度 1/5 1時間未満 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
Add built-in translations to the widget対応中かも @piyusshhjangid が今日担当しました。 オープンhelp wanted widget
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
codercops/chatcops#55 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
codercops/chatcops の issue をすべて見る
似ている issue
-
数据界面的横向滚动条缺失オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
zilliztech/attu#1037 ·
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
openclaw/openclaw#181212 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apify/apify-mcp-server#1684 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Automattic/data-liberation-agent#953 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
siteboon/claudecodeui#1642 ·
メンテナーはふだん 5 日以内に返信