-
Notifications
You must be signed in to change notification settings - Fork 13k
feat: improve apps logs #35416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: improve apps logs #35416
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
3403131
Refactor some endpoints out of the rest.ts file
d-gubert ec3c6c0
Make logs endpoint return paginated data
d-gubert a2aeb6d
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 03bc0d9
Add pagination to logs screen
d-gubert 29d4f18
Remove deprecated fields from endpoint
d-gubert 5caf4fe
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert f51cddd
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert bc07107
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert ca74396
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 2a513b4
wip
d-gubert 7ba49e0
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 541a4d3
Fix lint
d-gubert 0373e94
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 6b0d9f6
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 042690a
Remove debugs
d-gubert 763a9ad
Fix app languages endpoint type
d-gubert 2e9e9cf
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 71ba4c2
Add simple filters to logs endpoint
d-gubert 149d966
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 9f78c99
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert dff7b09
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 4ca76c9
Make the endpoint expect date-time instead of just date for the appro…
d-gubert b191a4e
Extract query building to function for future reuse
d-gubert f0848e9
Fix tests
d-gubert ba8a26f
makeAppLogsQuery comment/doc
d-gubert 77e3ada
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 148527b
Revert UI changes extracted to another branch
d-gubert f11094d
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 604770a
Add tests to the logs endpoint
d-gubert 0b84d82
Refactor test
d-gubert 2d9d0bd
Improve app logs prop schema
d-gubert 06f91b2
Fix typecheck
d-gubert 2fdf136
Refactor makeAppLogsQuery signature
d-gubert d91794c
Remove dangling console
d-gubert b0edb7d
Add changeset
d-gubert b4704af
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert dfcc9e6
Refactor rest types and adapt makeAppLogsQuery function
d-gubert c785883
Add new endpoint to fetch logs from all apps
d-gubert 84783aa
Improve endpoint tests
d-gubert 5a08819
Add changeset
d-gubert 16ee104
Merge branch 'develop' into feat/apps-logs-improvement
d-gubert 1b889bc
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 7ea674b
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert 63eee7c
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert c2e3e61
Add indexes to logs model
d-gubert a222878
Merge remote-tracking branch 'origin' into feat/apps-logs-improvement
d-gubert b4a13fa
Merge branch 'develop' into feat/apps-logs-improvement
d-gubert 8bf2ae0
Merge branch 'develop' into feat/apps-logs-improvement
d-gubert 69a8209
Merge branch 'develop' into feat/apps-logs-improvement
d-gubert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@rocket.chat/rest-typings': minor | ||
| '@rocket.chat/apps-engine': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Improve the `/api/apps/:id/logs` endpoint to accept filters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@rocket.chat/rest-typings': minor | ||
| '@rocket.chat/apps-engine': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Add a new endpoint `/api/apps/logs` that allows for fetching logs without a filter for app id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 7 additions & 12 deletions
19
apps/meteor/ee/server/apps/communication/endpoints/actionButtonsHandler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,15 @@ | ||
| import type { AppManager } from '@rocket.chat/apps-engine/server/AppManager'; | ||
|
|
||
| import { API } from '../../../../../app/api/server'; | ||
| import type { AppsRestApi } from '../rest'; | ||
|
|
||
| export const actionButtonsHandler = (apiManager: AppsRestApi) => | ||
| [ | ||
| { | ||
| authRequired: false, | ||
| }, | ||
| export const registerActionButtonsHandler = ({ api, _manager }: AppsRestApi) => | ||
| void api.addRoute( | ||
| 'actionButtons', | ||
| { authRequired: false }, | ||
| { | ||
| get(): any { | ||
| const manager = apiManager._manager as AppManager; | ||
|
|
||
| const buttons = manager.getUIActionButtonManager().getAllActionButtons(); | ||
| get() { | ||
| const buttons = _manager.getUIActionButtonManager().getAllActionButtons(); | ||
|
|
||
| return API.v1.success(buttons); | ||
| }, | ||
d-gubert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| ] as const; | ||
| ); | ||
35 changes: 35 additions & 0 deletions
35
apps/meteor/ee/server/apps/communication/endpoints/appGeneralLogsHandler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { isAppLogsProps } from '@rocket.chat/rest-typings'; | ||
|
|
||
| import { getPaginationItems } from '../../../../../app/api/server/helpers/getPaginationItems'; | ||
| import type { AppsRestApi } from '../rest'; | ||
| import { makeAppLogsQuery } from './lib/makeAppLogsQuery'; | ||
|
|
||
| export const registerAppGeneralLogsHandler = ({ api, _orch }: AppsRestApi) => | ||
| void api.addRoute( | ||
| 'logs', | ||
| { authRequired: true, permissionRequired: ['manage-apps'], validateParams: isAppLogsProps }, | ||
| { | ||
| async get() { | ||
| const { offset, count } = await getPaginationItems(this.queryParams); | ||
| const { sort } = await this.parseJsonQuery(); | ||
|
|
||
| const options = { | ||
| sort: sort || { _updatedAt: -1 }, | ||
| skip: offset, | ||
| limit: count, | ||
| }; | ||
|
|
||
| let query: Record<string, any>; | ||
|
|
||
| try { | ||
| query = makeAppLogsQuery(this.queryParams); | ||
| } catch (error) { | ||
| return api.failure({ error: error instanceof Error ? error.message : 'Unknown error' }); | ||
| } | ||
|
|
||
| const result = await _orch.getLogStorage().find(query, options); | ||
|
|
||
| return api.success({ offset, logs: result.logs, count: result.logs.length, total: result.total }); | ||
| }, | ||
| }, | ||
| ); |
45 changes: 45 additions & 0 deletions
45
apps/meteor/ee/server/apps/communication/endpoints/appLogsHandler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { isAppLogsProps } from '@rocket.chat/rest-typings'; | ||
|
|
||
| import { getPaginationItems } from '../../../../../app/api/server/helpers/getPaginationItems'; | ||
| import type { AppsRestApi } from '../rest'; | ||
| import { makeAppLogsQuery } from './lib/makeAppLogsQuery'; | ||
|
|
||
| export const registerAppLogsHandler = ({ api, _manager, _orch }: AppsRestApi) => | ||
| void api.addRoute( | ||
| ':id/logs', | ||
| { authRequired: true, permissionRequired: ['manage-apps'], validateParams: isAppLogsProps }, | ||
| { | ||
| async get() { | ||
| const proxiedApp = _manager.getOneById(this.urlParams.id); | ||
|
|
||
| if (!proxiedApp) { | ||
| return api.notFound(`No App found by the id of: ${this.urlParams.id}`); | ||
| } | ||
|
|
||
| if (this.queryParams.appId && this.queryParams.appId !== this.urlParams.id) { | ||
| return api.notFound(`Invalid query parameter "appId": ${this.queryParams.appId}`); | ||
| } | ||
|
|
||
| const { offset, count } = await getPaginationItems(this.queryParams); | ||
| const { sort } = await this.parseJsonQuery(); | ||
d-gubert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const options = { | ||
| sort: sort || { _updatedAt: -1 }, | ||
| skip: offset, | ||
| limit: count, | ||
| }; | ||
|
|
||
| let query: Record<string, any>; | ||
|
|
||
| try { | ||
| query = makeAppLogsQuery(this.queryParams); | ||
| } catch (error) { | ||
| return api.failure({ error: error instanceof Error ? error.message : 'Unknown error' }); | ||
| } | ||
|
|
||
| const result = await _orch.getLogStorage().find(query, options); | ||
d-gubert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return api.success({ offset, logs: result.logs, count: result.logs.length, total: result.total }); | ||
| }, | ||
| }, | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
apps/meteor/ee/server/apps/communication/endpoints/lib/makeAppLogsQuery.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import type { AppLogsProps } from '@rocket.chat/rest-typings'; | ||
|
|
||
| /** | ||
| * Creates a query object for fetching app logs based on provided parameters. | ||
| * | ||
| * NOTE: This function expects that all values are in the correct format, as it is | ||
| * used by an endpoint handler which has query parameter validation. | ||
| * | ||
| * @param queryParams - The query parameters. | ||
| * @returns A query object for fetching app logs. | ||
| * @throws {Error} If the date range is invalid. | ||
| */ | ||
| export function makeAppLogsQuery(queryParams: AppLogsProps) { | ||
d-gubert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const query: Record<string, any> = {}; | ||
|
|
||
| if (queryParams.appId) { | ||
| query.appId = queryParams.appId; | ||
| } | ||
|
|
||
| if (queryParams.logLevel) { | ||
| const queryLogLevel = Number(queryParams.logLevel); | ||
| const logLevel = ['error']; | ||
|
|
||
| if (queryLogLevel >= 1) { | ||
| logLevel.push('warn', 'info', 'log'); | ||
| } | ||
|
|
||
| if (queryLogLevel >= 2) { | ||
| logLevel.push('debug', 'success'); | ||
| } | ||
|
|
||
| query['entries.severity'] = { $in: logLevel }; | ||
| } | ||
|
|
||
| if (queryParams.method) { | ||
| query.method = queryParams.method; | ||
| } | ||
|
|
||
| if (queryParams.startDate) { | ||
| query._updatedAt = { | ||
| $gte: new Date(queryParams.startDate), | ||
| }; | ||
| } | ||
|
|
||
| if (queryParams.endDate) { | ||
| const endDate = new Date(queryParams.endDate); | ||
| endDate.setDate(endDate.getDate() + 1); | ||
|
|
||
| if (query._updatedAt?.$gte && query._updatedAt.$gte >= endDate) { | ||
| throw new Error('Invalid date range'); | ||
| } | ||
|
|
||
| query._updatedAt = { | ||
| ...(query._updatedAt || {}), | ||
| $lte: endDate, | ||
| }; | ||
| } | ||
|
|
||
| return query; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.