From 85109daea853fed131533d5822aef6e78ef02e67 Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Thu, 19 Oct 2023 00:08:14 +0800 Subject: [PATCH] feat(agent): add count_select in AgentStats event. (#583) * feat(agent): add count_select in AgentStats event. * fix: also count view events in agent stats. --- clients/tabby-agent/src/CompletionProviderStats.ts | 14 ++++++++++++++ clients/tabby-agent/src/TabbyAgent.ts | 1 + 2 files changed, 15 insertions(+) diff --git a/clients/tabby-agent/src/CompletionProviderStats.ts b/clients/tabby-agent/src/CompletionProviderStats.ts index 06ace31..6b388f1 100644 --- a/clients/tabby-agent/src/CompletionProviderStats.ts +++ b/clients/tabby-agent/src/CompletionProviderStats.ts @@ -65,6 +65,8 @@ export class CompletionProviderStats { private cacheHitCount = 0; private cacheMissCount = 0; + private eventMap = new Map(); + private completionRequestLatencyStats = new Univariate(); private completionRequestCanceledStats = new Average(); private completionRequestTimeoutCount = 0; @@ -99,11 +101,19 @@ export class CompletionProviderStats { } } + addEvent(event: string): void { + const count = this.eventMap.get(event) || 0; + this.eventMap.set(event, count + 1); + } + reset() { this.autoCompletionCount = 0; this.manualCompletionCount = 0; this.cacheHitCount = 0; this.cacheMissCount = 0; + + this.eventMap = new Map(); + this.completionRequestLatencyStats = new Univariate(); this.completionRequestCanceledStats = new Average(); this.completionRequestTimeoutCount = 0; @@ -115,12 +125,16 @@ export class CompletionProviderStats { // stats for anonymous usage report stats() { + const eventCount = Object.fromEntries( + Array.from(this.eventMap.entries()).map(([key, value]) => ["count_" + key, value]), + ); return { completion: { count_auto: this.autoCompletionCount, count_manual: this.manualCompletionCount, cache_hit: this.cacheHitCount, cache_miss: this.cacheMissCount, + ...eventCount, }, completion_request: { count: this.completionRequestLatencyStats.count(), diff --git a/clients/tabby-agent/src/TabbyAgent.ts b/clients/tabby-agent/src/TabbyAgent.ts index 56f57bc..fbcf014 100644 --- a/clients/tabby-agent/src/TabbyAgent.ts +++ b/clients/tabby-agent/src/TabbyAgent.ts @@ -594,6 +594,7 @@ export class TabbyAgent extends EventEmitter implements Agent { if (this.status === "notInitialized") { throw new Error("Agent is not initialized"); } + this.completionProviderStats.addEvent(request.type); await this.post( "/v1/events", {