feat: add copilot metrics (#8455)

fix CLOUD-73
This commit is contained in:
darkskygit
2024-10-18 03:30:02 +00:00
parent 4122cec096
commit fa554b1054
14 changed files with 198 additions and 112 deletions
+2 -2
View File
@@ -3,7 +3,7 @@ import { Cron, CronExpression, SchedulerRegistry } from '@nestjs/schedule';
import { PrismaClient } from '@prisma/client';
import {
CallTimer,
CallMetric,
Config,
type EventPayload,
metrics,
@@ -47,7 +47,7 @@ export class DocStorageCronJob implements OnModuleInit {
}
}
@CallTimer('doc', 'auto_merge_pending_doc_updates')
@CallMetric('doc', 'auto_merge_pending_doc_updates')
async autoMergePendingDocUpdates() {
try {
const randomDoc = await this.workspace.randomDoc();
@@ -3,7 +3,7 @@ import { chunk } from 'lodash-es';
import * as Y from 'yjs';
import {
CallTimer,
CallMetric,
Config,
mergeUpdatesInApplyWay as yotcoMergeUpdates,
metrics,
@@ -89,12 +89,12 @@ export class DocStorageOptions implements IDocStorageOptions {
return this.config.doc.history.interval;
};
@CallTimer('doc', 'yjs_merge_updates')
@CallMetric('doc', 'yjs_merge_updates')
private simpleMergeUpdates(updates: Uint8Array[]) {
return Y.mergeUpdates(updates);
}
@CallTimer('doc', 'yjs_recover_updates_to_doc')
@CallMetric('doc', 'yjs_recover_updates_to_doc')
private recoverDoc(updates: Uint8Array[]): Promise<Y.Doc> {
const doc = new Y.Doc();
const chunks = chunk(updates, 10);
@@ -7,7 +7,7 @@ import {
UndoManager,
} from 'yjs';
import { CallTimer } from '../../../fundamentals';
import { CallMetric } from '../../../fundamentals';
import { Connection } from './connection';
import { SingletonLocker } from './lock';
@@ -165,7 +165,7 @@ export abstract class DocStorageAdapter extends Connection {
force?: boolean
): Promise<boolean>;
@CallTimer('doc', 'squash')
@CallMetric('doc', 'squash')
protected async squash(updates: DocUpdate[]): Promise<DocUpdate> {
const merge = this.options?.mergeUpdates ?? mergeUpdates;
const lastUpdate = updates.at(-1);
@@ -12,7 +12,7 @@ import { diffUpdate, encodeStateVectorFromUpdate } from 'yjs';
import {
AlreadyInSpace,
CallTimer,
CallMetric,
Config,
DocNotFound,
GatewayErrorWrapper,
@@ -33,7 +33,7 @@ import { DocID } from '../utils/doc';
const SubscribeMessage = (event: string) =>
applyDecorators(
GatewayErrorWrapper(event),
CallTimer('socketio', 'event_duration', { event }),
CallMetric('socketio', 'event_duration', undefined, { event }),
RawSubscribeMessage(event)
);
@@ -6,7 +6,7 @@ import {
AccessDenied,
ActionForbidden,
BlobNotFound,
CallTimer,
CallMetric,
DocHistoryNotFound,
DocNotFound,
InvalidHistoryTimestamp,
@@ -32,7 +32,7 @@ export class WorkspacesController {
// NOTE: because graphql can't represent a File, so we have to use REST API to get blob
@Public()
@Get('/:id/blobs/:name')
@CallTimer('controllers', 'workspace_get_blob')
@CallMetric('controllers', 'workspace_get_blob')
async blob(
@CurrentUser() user: CurrentUser | undefined,
@Param('id') workspaceId: string,
@@ -76,7 +76,7 @@ export class WorkspacesController {
// get doc binary
@Public()
@Get('/:id/docs/:guid')
@CallTimer('controllers', 'workspace_get_doc')
@CallMetric('controllers', 'workspace_get_doc')
async doc(
@CurrentUser() user: CurrentUser | undefined,
@Param('id') ws: string,
@@ -128,7 +128,7 @@ export class WorkspacesController {
}
@Get('/:id/docs/:guid/histories/:timestamp')
@CallTimer('controllers', 'workspace_get_history')
@CallMetric('controllers', 'workspace_get_history')
async history(
@CurrentUser() user: CurrentUser,
@Param('id') ws: string,