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.
r0.4
Zhiming Ma 2023-10-19 00:08:14 +08:00 committed by GitHub
parent 4a87bcf431
commit 85109daea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -65,6 +65,8 @@ export class CompletionProviderStats {
private cacheHitCount = 0; private cacheHitCount = 0;
private cacheMissCount = 0; private cacheMissCount = 0;
private eventMap = new Map<string, number>();
private completionRequestLatencyStats = new Univariate(); private completionRequestLatencyStats = new Univariate();
private completionRequestCanceledStats = new Average(); private completionRequestCanceledStats = new Average();
private completionRequestTimeoutCount = 0; 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() { reset() {
this.autoCompletionCount = 0; this.autoCompletionCount = 0;
this.manualCompletionCount = 0; this.manualCompletionCount = 0;
this.cacheHitCount = 0; this.cacheHitCount = 0;
this.cacheMissCount = 0; this.cacheMissCount = 0;
this.eventMap = new Map<string, number>();
this.completionRequestLatencyStats = new Univariate(); this.completionRequestLatencyStats = new Univariate();
this.completionRequestCanceledStats = new Average(); this.completionRequestCanceledStats = new Average();
this.completionRequestTimeoutCount = 0; this.completionRequestTimeoutCount = 0;
@ -115,12 +125,16 @@ export class CompletionProviderStats {
// stats for anonymous usage report // stats for anonymous usage report
stats() { stats() {
const eventCount = Object.fromEntries(
Array.from(this.eventMap.entries()).map(([key, value]) => ["count_" + key, value]),
);
return { return {
completion: { completion: {
count_auto: this.autoCompletionCount, count_auto: this.autoCompletionCount,
count_manual: this.manualCompletionCount, count_manual: this.manualCompletionCount,
cache_hit: this.cacheHitCount, cache_hit: this.cacheHitCount,
cache_miss: this.cacheMissCount, cache_miss: this.cacheMissCount,
...eventCount,
}, },
completion_request: { completion_request: {
count: this.completionRequestLatencyStats.count(), count: this.completionRequestLatencyStats.count(),

View File

@ -594,6 +594,7 @@ export class TabbyAgent extends EventEmitter implements Agent {
if (this.status === "notInitialized") { if (this.status === "notInitialized") {
throw new Error("Agent is not initialized"); throw new Error("Agent is not initialized");
} }
this.completionProviderStats.addEvent(request.type);
await this.post( await this.post(
"/v1/events", "/v1/events",
{ {