Skip to content

Commit

Permalink
feat: new apps logger deno-runtime (#31136)
Browse files Browse the repository at this point in the history
* refactor: convert to typescript

* feat: change storeEntries to receive logEntries instead appconsole instance

* refactor: remove `logs-storage.js`

* refactor: remove type `any`

* fix: type errors

* fix: implement correct method

* chore: use apps engine with deno vm

* Fix import

---------

Co-authored-by: Douglas Gubert <[email protected]>
  • Loading branch information
tapiarafael and d-gubert committed Jan 30, 2024
1 parent c77bad5 commit 41b7359
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
4 changes: 2 additions & 2 deletions apps/meteor/ee/server/apps/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { AppThreadsConverter } from '../../../app/apps/server/converters/threads
import { settings } from '../../../app/settings/server';
import { canEnableApp } from '../../app/license/server/canEnableApp';
import { AppServerNotifier, AppsRestApi, AppUIKitInteractionApi } from './communication';
import { AppRealLogsStorage, AppRealStorage, ConfigurableAppSourceStorage } from './storage';
import { AppRealLogStorage, AppRealStorage, ConfigurableAppSourceStorage } from './storage';

function isTesting() {
return process.env.TEST_MODE === 'true';
Expand Down Expand Up @@ -54,7 +54,7 @@ export class AppServerOrchestrator {
this._logModel = AppLogs;
this._persistModel = AppsPersistence;
this._storage = new AppRealStorage(this._model);
this._logStorage = new AppRealLogsStorage(this._logModel);
this._logStorage = new AppRealLogStorage(this._logModel);
this._appSourceStorage = new ConfigurableAppSourceStorage(appsSourceStorageType, appsSourceStorageFilesystemPath);

this._converters = new Map();
Expand Down
36 changes: 36 additions & 0 deletions apps/meteor/ee/server/apps/storage/AppRealLogStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { ILoggerStorageEntry } from '@rocket.chat/apps-engine/server/logging';
import type { IAppLogStorageFindOptions } from '@rocket.chat/apps-engine/server/storage';
import { AppLogStorage } from '@rocket.chat/apps-engine/server/storage';
import { InstanceStatus } from '@rocket.chat/instance-status';
import type { AppLogs } from '@rocket.chat/models';

export class AppRealLogStorage extends AppLogStorage {
constructor(private db: typeof AppLogs) {
super('mongodb');
}

async find(
query: {
[field: string]: any;
},
options?: IAppLogStorageFindOptions,
): Promise<ILoggerStorageEntry[]> {
return this.db.find({ ...options, ...query }).toArray();
}

async storeEntries(logEntry: ILoggerStorageEntry): Promise<ILoggerStorageEntry> {
logEntry.instanceId = InstanceStatus.id();

const id = (await this.db.insertOne(logEntry)).insertedId;

return this.db.findOneById(id);
}

async getEntriesFor(appId: string): Promise<ILoggerStorageEntry[]> {
return this.db.find({ appId }).toArray();
}

async removeEntriesFor(appId: string): Promise<void> {
await this.db.deleteOne({ appId });
}
}
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/apps/storage/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './AppFileSystemSourceStorage';
import './AppGridFSSourceStorage';

export { AppRealLogsStorage } from './logs-storage';
export { AppRealLogStorage } from './AppRealLogStorage';
export { AppRealStorage } from './AppRealStorage';
export { ConfigurableAppSourceStorage } from './ConfigurableAppSourceStorage';
32 changes: 0 additions & 32 deletions apps/meteor/ee/server/apps/storage/logs-storage.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/model-typings/src/models/IAppLogsModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { DeleteResult, Filter } from 'mongodb';

import type { IBaseModel } from './IBaseModel';

// TODO: type for AppLogs
export interface IAppLogsModel extends IBaseModel<any> {
resetTTLIndex(expireAfterSeconds: number): Promise<void>;
remove(query: Filter<any>): Promise<DeleteResult>;
}

0 comments on commit 41b7359

Please sign in to comment.