Skip to content
Snippets Groups Projects
Commit 2a513b4a authored by Douglas Gubert's avatar Douglas Gubert
Browse files

wip

parent ca743968
No related tags found
No related merge requests found
import { Box, Pagination } from '@rocket.chat/fuselage';
import { useRef, type ReactElement } from 'react';
import { Box, Field, FieldLabel, FieldRow, Pagination, Select, type SelectOption } from '@rocket.chat/fuselage';
import { useRef, useState, type ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
import AppLogsItem from './AppLogsItem';
import { usePagination } from '../../../../../components/GenericTable/hooks/usePagination';
import { useFormatDateAndTime } from '../../../../../hooks/useFormatDateAndTime';
import DateRangePicker from '../../../../audit/components/forms/DateRangePicker';
import AccordionLoading from '../../../components/AccordionLoading';
import { useLogs } from '../../../hooks/useLogs';
import { type LogsFilters, useLogs } from '../../../hooks/useLogs';
const AppLogs = ({ id }: { id: string }): ReactElement => {
const { t } = useTranslation();
const scrollableRef = useRef<HTMLDivElement>(null);
const formatDateAndTime = useFormatDateAndTime();
const [filters, setFilters] = useState<LogsFilters>({ logLevel: '0' });
const { setCurrent, setItemsPerPage, ...pagination } = usePagination();
const { data, isSuccess, isError, isLoading } = useLogs({
filters,
appId: id,
count: pagination.itemsPerPage,
offset: pagination.current,
});
const logLevelOptions: SelectOption[] = [
['0', t('0_Errors_Only'), filters.logLevel === '0'],
['1', t('1_Errors_and_Information'), filters.logLevel === '1'],
['2', t('2_Erros_Information_and_Debug'), filters.logLevel === '2'],
];
return (
<>
{isLoading && <AccordionLoading />}
{isError && (
<Box maxWidth='x600' alignSelf='center'>
<Box maxWidth='x600' alignSelf='center' pi={24}>
{t('App_not_found')}
</Box>
)}
{isSuccess && (
<>
<Box is='form' paddingInline={24}>
<Field>
<FieldLabel>{t('Date')}</FieldLabel>
<FieldRow>
<DateRangePicker
display='flex'
flexDirection='row'
value={filters.dateRange}
onChange={(dateRange) => setFilters({ ...filters, dateRange })}
/>
</FieldRow>
</Field>
<Field>
<FieldLabel>{t('Log_Level')}</FieldLabel>
<FieldRow>
<Select
value={filters.logLevel}
options={logLevelOptions}
onChange={(key) => setFilters({ ...filters, logLevel: key as LogsFilters['logLevel'] })}
/>
</FieldRow>
</Field>
</Box>
<Box display='flex' flexDirection='column' overflow='hidden' height='100%' pi={24}>
<Box ref={scrollableRef} overflowY='scroll' height='100%'>
{data?.logs?.map((log) => (
......
......@@ -3,17 +3,29 @@ import { useEndpoint } from '@rocket.chat/ui-contexts';
import type { UseQueryResult } from '@tanstack/react-query';
import { useQuery } from '@tanstack/react-query';
import type { DateRange } from '../../audit/utils/dateRange';
export type LogsFilters = {
logLevel: '0' | '1' | '2';
dateRange?: DateRange;
method?: string;
};
type useLogsParams = {
appId: string;
count: number;
offset: number;
filters?: LogsFilters;
};
export const useLogs = ({ appId, count, offset }: useLogsParams): UseQueryResult<OperationResult<'GET', '/apps/:id/logs'>> => {
export const useLogs = ({ appId, count, offset, filters }: useLogsParams): UseQueryResult<OperationResult<'GET', '/apps/:id/logs'>> => {
const logs = useEndpoint('GET', '/apps/:id/logs', { id: appId });
const { logLevel, method, dateRange } = filters || {};
const startDate = dateRange?.start?.toJSON();
const endDate = dateRange?.end?.toJSON();
return useQuery({
queryKey: ['marketplace', 'apps', appId, 'logs', count, offset],
queryFn: () => logs({ count, offset }),
queryKey: ['marketplace', 'apps', appId, 'logs', count, offset, filters],
queryFn: () => logs({ count, offset, logLevel, method, startDate, endDate }),
});
};
......@@ -14,16 +14,20 @@ export const registerAppLogsHandler = ({ api, _manager, _orch }: AppsRestApi) =>
}
const { offset, count } = await getPaginationItems(this.queryParams);
const { sort, query } = await this.parseJsonQuery();
const { sort } = await this.parseJsonQuery();
console.log(this.queryParams)
const ourQuery = Object.assign({}, query, { appId: proxiedApp.getID() });
const options = {
sort: sort || { _updatedAt: -1 },
skip: offset,
limit: count,
};
const result = await _orch.getLogStorage().find(ourQuery, options);
const query = {
appId: this.urlParams.id,
};
const result = await _orch.getLogStorage().find(query, options);
return api.success({ offset, logs: result.logs, count: result.logs.length, total: result.total });
},
......
......@@ -169,6 +169,7 @@ export class AppServerOrchestrator {
}
async load() {
console.log('load called');
// Don't try to load it again if it has
// already been loaded
if (this.isLoaded()) {
......
......@@ -4,6 +4,7 @@ import { Apps } from './orchestrator';
import { settings, settingsRegistry } from '../../../app/settings/server';
Meteor.startup(async function _appServerOrchestrator() {
console.log('_appServerOrchestrator step 1')
await settingsRegistry.addGroup('General', async function () {
await this.section('Apps', async function () {
await this.add('Apps_Logs_TTL', '30_days', {
......@@ -85,6 +86,7 @@ Meteor.startup(async function _appServerOrchestrator() {
});
Apps.initialize();
console.log('_appServerOrchestrator step 2')
void Apps.load();
});
......@@ -5,6 +5,7 @@ import { Apps } from '../apps';
import { disableAppsWithAddonsCallback } from '../lib/apps/disableAppsWithAddonsCallback';
Meteor.startup(() => {
console.log('apps callbacks registration')
async function migratePrivateAppsCallback() {
if (!Apps.isInitialized) return;
......
......@@ -9,6 +9,8 @@ import { api } from '@rocket.chat/core-services';
import { isRunningMs } from '../../../server/lib/isRunningMs';
console.log('ee/server/startup/index.ts')
export const registerEEBroker = async (): Promise<void> => {
// only starts network broker if running in micro services mode
if (isRunningMs()) {
......
......@@ -16,9 +16,19 @@ import type {
} from '@rocket.chat/core-typings';
import type * as UiKit from '@rocket.chat/ui-kit';
import { ajv } from '../v1/Ajv';
import type { PaginatedRequest } from '../helpers/PaginatedRequest';
import type { PaginatedResult } from '../helpers/PaginatedResult';
type GETAppsLogsFilter = {
logLevel?: '0' | '1' | '2';
method?: string;
startDate?: string;
endDate?: string;
};
// export const isAppsLogsFilter;
export type AppsEndpoints = {
'/apps/count': {
GET: () => { totalMarketplaceEnabled: number; totalPrivateEnabled: number; maxMarketplaceApps: number; maxPrivateApps: number };
......@@ -100,7 +110,7 @@ export type AppsEndpoints = {
};
'/apps/:id/logs': {
GET: (params: PaginatedRequest) => PaginatedResult<{
GET: (params: PaginatedRequest<GETAppsLogsFilter>) => PaginatedResult<{
logs: ILogItem[];
}>;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment