Batch analytics events into an EventSink and compute stats from it
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 78/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 13
- Fork
- 7
- Merge medio
- 3h 33m
- PR unite (30g)
- 176
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di codercops/chatcops
-
Add startup checks that catch weak or leaked security settingsForse già presa @varun-pahuja l’ha presa 2 giorni fa. Apertaenhancement good first issue hacktoberfest server
codercops/chatcops#231 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Type-check the TypeScript samples in the docsForse già presa @An16og l’ha presa 2 giorni fa. Apertadocumentation hacktoberfest help wanted testing
Difficoltà 4/5 3-5 giorni Idoneità per principianti 70/100
codercops/chatcops#201 · 7 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
hacktoberfest
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
Add built-in translations to the widgetForse già presa @piyusshhjangid l’ha presa 1 giorno fa. Apertahelp wanted widget
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
codercops/chatcops#55 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di codercops/chatcops
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
db-ux-design-system/core-web#8613 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
bug:new
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
callstackincubator/simlock#934 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
gchq/LD-Explorer#286 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
foxglove/mcap#1907 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno