Skip to content

Commit

Permalink
feat: rename old decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Oct 11, 2024
1 parent b138611 commit 25e8bb9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions packages/backend/server/src/core/doc/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Cron, CronExpression, SchedulerRegistry } from '@nestjs/schedule';
import { PrismaClient } from '@prisma/client';

import {
CallTimer,
CallMetric,
Config,
type EventPayload,
metrics,
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/server/src/core/doc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { chunk } from 'lodash-es';
import * as Y from 'yjs';

import {
CallTimer,
CallMetric,
Config,
mergeUpdatesInApplyWay as yotcoMergeUpdates,
metrics,
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/server/src/core/doc/storage/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
UndoManager,
} from 'yjs';

import { CallTimer } from '../../../fundamentals';
import { CallMetric } from '../../../fundamentals';
import { Connection } from './connection';
import { SingletonLocker } from './lock';

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/server/src/core/sync/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { diffUpdate, encodeStateVectorFromUpdate } from 'yjs';

import {
AlreadyInSpace,
CallTimer,
CallMetric,
Config,
DocNotFound,
GatewayErrorWrapper,
Expand All @@ -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', { event }),
RawSubscribeMessage(event)
);

Expand Down
8 changes: 4 additions & 4 deletions packages/backend/server/src/core/workspaces/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
AccessDenied,
ActionForbidden,
BlobNotFound,
CallTimer,
CallMetric,
DocHistoryNotFound,
DocNotFound,
InvalidHistoryTimestamp,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions packages/backend/server/src/plugins/copilot/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import {
import { CurrentUser, Public } from '../../core/auth';
import {
BlobNotFound,
CallThrowableCounter,
CallTimer,
CallMetric,
Config,
CopilotFailedToGenerateText,
CopilotSessionNotFound,
Expand Down Expand Up @@ -180,7 +179,7 @@ export class CopilotController {
return merge(source$.pipe(finalize(() => subject$.next(null))), ping$);
}

@CallTimer('ai', 'chat_duration')
@CallMetric('ai', 'chat')
@Get('/chat/:sessionId')
async chat(
@CurrentUser() user: CurrentUser,
Expand Down Expand Up @@ -224,7 +223,7 @@ export class CopilotController {
}

@Sse('/chat/:sessionId/stream')
@CallTimer('ai', 'chat_stream_duration')
@CallMetric('ai', 'chat_stream')
async chatStream(
@CurrentUser() user: CurrentUser,
@Req() req: Request,
Expand Down Expand Up @@ -286,7 +285,7 @@ export class CopilotController {
}

@Sse('/chat/:sessionId/workflow')
@CallTimer('ai', 'chat_workflow_duration')
@CallMetric('ai', 'chat_workflow')
async chatWorkflow(
@CurrentUser() user: CurrentUser,
@Req() req: Request,
Expand Down Expand Up @@ -378,7 +377,7 @@ export class CopilotController {
}

@Sse('/chat/:sessionId/images')
@CallTimer('ai', 'chat_images_duration')
@CallMetric('ai', 'chat_images')
async chatImagesStream(
@CurrentUser() user: CurrentUser,
@Req() req: Request,
Expand Down Expand Up @@ -463,8 +462,7 @@ export class CopilotController {
}
}

@CallThrowableCounter('ai', 'unsplash')
@CallTimer('ai', 'unsplash_duration')
@CallMetric('ai', 'unsplash')
@Get('/unsplash/photos')
async unsplashPhotos(
@Req() req: Request,
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/server/src/plugins/copilot/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Admin } from '../../core/common';
import { PermissionService } from '../../core/permission';
import { UserType } from '../../core/user';
import {
CallThrowableCounter,
CallMetric,
CopilotFailedToCreateMessage,
FileUpload,
RequestMutex,
Expand Down Expand Up @@ -309,7 +309,7 @@ export class CopilotResolver {
}

@ResolveField(() => [CopilotHistoriesType], {})
@CallThrowableCounter('ai', 'histories')
@CallMetric('ai', 'histories')
async histories(
@Parent() copilot: CopilotType,
@CurrentUser() user: CurrentUser,
Expand Down Expand Up @@ -347,7 +347,7 @@ export class CopilotResolver {
@Mutation(() => String, {
description: 'Create a chat session',
})
@CallThrowableCounter('ai', 'chat_session_create')
@CallMetric('ai', 'chat_session_create')
async createCopilotSession(
@CurrentUser() user: CurrentUser,
@Args({ name: 'options', type: () => CreateChatSessionInput })
Expand Down Expand Up @@ -375,7 +375,7 @@ export class CopilotResolver {
@Mutation(() => String, {
description: 'Create a chat session',
})
@CallThrowableCounter('ai', 'chat_session_fork')
@CallMetric('ai', 'chat_session_fork')
async forkCopilotSession(
@CurrentUser() user: CurrentUser,
@Args({ name: 'options', type: () => ForkChatSessionInput })
Expand Down Expand Up @@ -403,7 +403,7 @@ export class CopilotResolver {
@Mutation(() => [String], {
description: 'Cleanup sessions',
})
@CallThrowableCounter('ai', 'chat_session_cleanup')
@CallMetric('ai', 'chat_session_cleanup')
async cleanupCopilotSession(
@CurrentUser() user: CurrentUser,
@Args({ name: 'options', type: () => DeleteSessionInput })
Expand Down Expand Up @@ -432,7 +432,7 @@ export class CopilotResolver {
@Mutation(() => String, {
description: 'Create a chat message',
})
@CallThrowableCounter('ai', 'chat_message_create')
@CallMetric('ai', 'chat_message_create')
async createCopilotMessage(
@CurrentUser() user: CurrentUser,
@Args({ name: 'options', type: () => CreateChatMessageInput })
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/server/src/plugins/copilot/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { QuotaManagementService } from '../../core/quota';
import {
type BlobInputType,
BlobQuotaExceeded,
CallThrowableCounter,
CallMetric,
Config,
type FileUpload,
type StorageProvider,
Expand All @@ -29,7 +29,7 @@ export class CopilotStorage {
);
}

@CallThrowableCounter('ai', 'blob_put')
@CallMetric('ai', 'blob_put')
async put(
userId: string,
workspaceId: string,
Expand All @@ -45,17 +45,17 @@ export class CopilotStorage {
return this.url.link(`/api/copilot/blob/${name}`);
}

@CallThrowableCounter('ai', 'blob_get')
@CallMetric('ai', 'blob_get')
async get(userId: string, workspaceId: string, key: string) {
return this.provider.get(`${userId}/${workspaceId}/${key}`);
}

@CallThrowableCounter('ai', 'blob_delete')
@CallMetric('ai', 'blob_delete')
async delete(userId: string, workspaceId: string, key: string) {
await this.provider.delete(`${userId}/${workspaceId}/${key}`);
}

@CallThrowableCounter('ai', 'blob_upload')
@CallMetric('ai', 'blob_upload')
async handleUpload(userId: string, blob: FileUpload) {
const checkExceeded = await this.quota.getQuotaCalculator(userId);

Expand Down Expand Up @@ -93,7 +93,7 @@ export class CopilotStorage {
};
}

@CallThrowableCounter('ai', 'blob_proxy_remote_url')
@CallMetric('ai', 'blob_proxy_remote_url')
async handleRemoteLink(userId: string, workspaceId: string, link: string) {
const response = await fetch(link);
const buffer = new Uint8Array(await response.arrayBuffer());
Expand Down

0 comments on commit 25e8bb9

Please sign in to comment.