Skip to content

Commit c992529

Browse files
Merge branch 'main' into feature/e2e-automatically-update
2 parents 14a4e77 + 386cb38 commit c992529

File tree

85 files changed

+3218
-1300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3218
-1300
lines changed

redisinsight/api/config/default.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { join } from 'path';
2+
import * as os from 'os';
23

34
const homedir = join(__dirname, '..');
45

@@ -15,6 +16,7 @@ const defaultsDir = process.env.BUILD_TYPE === 'ELECTRON' && process['resourcesP
1516

1617
export default {
1718
dir_path: {
19+
tmpDir: os.tmpdir(),
1820
homedir,
1921
prevHomedir: homedir,
2022
staticDir,
@@ -87,10 +89,14 @@ export default {
8789
redis_cli: {
8890
unsupportedCommands: JSON.parse(process.env.CLI_UNSUPPORTED_COMMANDS || '[]'),
8991
},
92+
profiler: {
93+
logFileIdleThreshold: parseInt(process.env.PROFILER_LOG_FILE_IDLE_THRESHOLD, 10) || 1000 * 60, // 1min
94+
},
9095
analytics: {
9196
writeKey: process.env.SEGMENT_WRITE_KEY || 'SOURCE_WRITE_KEY',
9297
},
9398
logger: {
99+
logLevel: process.env.LOG_LEVEL || 'info', // log level
94100
stdout: process.env.STDOUT_LOGGER ? process.env.STDOUT_LOGGER === 'true' : false, // disabled by default
95101
files: process.env.FILES_LOGGER ? process.env.FILES_LOGGER === 'true' : true, // enabled by default
96102
omitSensitiveData: process.env.LOGGER_OMIT_DATA ? process.env.LOGGER_OMIT_DATA === 'true' : true,

redisinsight/api/config/development.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default {
1010
migrationsRun: process.env.DB_MIGRATIONS ? process.env.DB_MIGRATIONS === 'true' : false,
1111
},
1212
logger: {
13+
logLevel: process.env.LOG_LEVEL || 'debug',
1314
stdout: process.env.STDOUT_LOGGER ? process.env.STDOUT_LOGGER === 'true' : true, // enabled by default
1415
omitSensitiveData: process.env.LOGGER_OMIT_DATA ? process.env.LOGGER_OMIT_DATA === 'true' : false,
1516
},

redisinsight/api/config/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ if (LOGGER_CONFIG.files) {
5858
const logger: WinstonModuleOptions = {
5959
format: format.errors({ stack: true }),
6060
transports: transportsConfig,
61+
level: LOGGER_CONFIG.logLevel,
6162
};
6263

6364
export default logger;

redisinsight/api/config/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ export default {
33
env: 'test',
44
requestTimeout: 1000,
55
},
6+
profiler: {
7+
logFileIdleThreshold: parseInt(process.env.PROFILER_LOG_FILE_IDLE_THRESHOLD, 10) || 1000 * 3, // 3sec
8+
},
69
};

redisinsight/api/src/__mocks__/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './redis-info';
88
export * from './app-settings';
99
export * from './autodiscovery-tools';
1010
export * from './analytics';
11+
export * from './profiler';

redisinsight/api/src/__mocks__/monitor.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { ILogsEmitter } from 'src/modules/profiler/interfaces/logs-emitter.interface';
2+
import { ProfilerClient } from 'src/modules/profiler/models/profiler.client';
3+
import { RedisObserver } from 'src/modules/profiler/models/redis.observer';
4+
import { IShardObserver } from 'src/modules/profiler/interfaces/shard-observer.interface';
5+
import { LogFile } from 'src/modules/profiler/models/log-file';
6+
import { ProfilerAnalyticsService } from 'src/modules/profiler/profiler-analytics.service';
7+
import { MockType } from 'src/__mocks__/common';
8+
import { TelemetryEvents } from 'src/constants';
9+
import * as MockedSocket from 'socket.io-mock';
10+
import { IMonitorData } from 'src/modules/profiler/interfaces/monitor-data.interface';
11+
12+
export const mockMonitorDataItemEmitted = {
13+
time: '14239988881.12341',
14+
source: '127.0.0.1',
15+
database: 0,
16+
args: ['set', 'foo', 'bar'],
17+
};
18+
19+
export const mockMonitorDataItem: IMonitorData = {
20+
...mockMonitorDataItemEmitted,
21+
shardOptions: null,
22+
};
23+
24+
export const mockSocket = new MockedSocket();
25+
mockSocket['emit'] = jest.fn();
26+
//
27+
// export const mockProfilerClient: MockType<ProfilerClient> = {
28+
// id: uuidv4(),
29+
// handleOnData: jest.fn(),
30+
// handleOnDisconnect: jest.fn(),
31+
// addLogsEmitter: jest.fn(),
32+
// flushLogs: jest.fn(),
33+
// destroy: jest.fn(),
34+
// };
35+
36+
export const mockRedisObserver: Partial<RedisObserver> = {
37+
// status: RedisObserverStatus.Wait,
38+
init: jest.fn(),
39+
subscribe: jest.fn(),
40+
unsubscribe: jest.fn(),
41+
getProfilerClientsSize: jest.fn(),
42+
clear: jest.fn(),
43+
removeShardsListeners: jest.fn(),
44+
};
45+
46+
export const mockRedisShardObserver: IShardObserver = {
47+
addListener: jest.fn(),
48+
eventNames: jest.fn(),
49+
getMaxListeners: jest.fn(),
50+
listenerCount: jest.fn(),
51+
listeners: jest.fn(),
52+
prependListener: jest.fn(),
53+
prependOnceListener: jest.fn(),
54+
removeAllListeners: jest.fn(),
55+
removeListener: jest.fn(),
56+
rawListeners: jest.fn(),
57+
setMaxListeners: jest.fn(),
58+
on: jest.fn(),
59+
emit: jest.fn(),
60+
off: jest.fn(),
61+
once: jest.fn(),
62+
disconnect: jest.fn(),
63+
};
64+
65+
export const mockProfilerAnalyticsEvents = new Map();
66+
mockProfilerAnalyticsEvents.set(TelemetryEvents.ProfilerLogDownloaded, jest.fn());
67+
mockProfilerAnalyticsEvents.set(TelemetryEvents.ProfilerLogDeleted, jest.fn());
68+
69+
export const mockProfilerAnalyticsService: MockType<ProfilerAnalyticsService> = {
70+
sendLogDeleted: jest.fn(),
71+
sendLogDownloaded: jest.fn(),
72+
getEventsEmitters: jest.fn().mockImplementation(() => mockProfilerAnalyticsEvents),
73+
};
74+
75+
export const mockLogEmitter: ILogsEmitter = {
76+
id: 'test',
77+
emit: jest.fn(),
78+
addProfilerClient: jest.fn(),
79+
removeProfilerClient: jest.fn(),
80+
flushLogs: jest.fn(),
81+
};
82+
83+
export const mockWriteStream = {
84+
write: jest.fn(),
85+
};
86+
export const testLogFileId = 'test-log-file-id';
87+
export const mockLogFile: LogFile = new LogFile('instanceid', testLogFileId, mockProfilerAnalyticsEvents);
88+
mockLogFile['getWriteStream'] = jest.fn();
89+
mockLogFile['addProfilerClient'] = jest.fn();
90+
mockLogFile['removeProfilerClient'] = jest.fn();
91+
mockLogFile['destroy'] = jest.fn();
92+
93+
export const mockProfilerClientId = 'profiler-client-id';
94+
export const mockProfilerClient: ProfilerClient = new ProfilerClient(mockProfilerClientId, mockSocket);

redisinsight/api/src/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { InstancesModule } from './modules/instances/instances.module';
1616
import { BrowserModule } from './modules/browser/browser.module';
1717
import { RedisEnterpriseModule } from './modules/redis-enterprise/redis-enterprise.module';
1818
import { RedisSentinelModule } from './modules/redis-sentinel/redis-sentinel.module';
19-
import { MonitorModule } from './modules/monitor/monitor.module';
19+
import { ProfilerModule } from './modules/profiler/profiler.module';
2020
import { CliModule } from './modules/cli/cli.module';
2121
import { StaticsManagementModule } from './modules/statics-management/statics-management.module';
2222
import { SettingsController } from './controllers/settings.controller';
@@ -41,7 +41,7 @@ const PATH_CONFIG = config.get('dir_path');
4141
WorkbenchModule,
4242
PluginModule,
4343
CommandsModule,
44-
MonitorModule,
44+
ProfilerModule,
4545
EventEmitterModule.forRoot(),
4646
...(SERVER_CONFIG.staticContent
4747
? [

redisinsight/api/src/constants/error-messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export default {
33
INVALID_DATABASE_INSTANCE_ID: 'Invalid database instance id.',
44
COMMAND_EXECUTION_NOT_FOUND: 'Command execution was not found.',
5+
PROFILER_LOG_FILE_NOT_FOUND: 'Profiler log file was not found.',
56
PLUGIN_STATE_NOT_FOUND: 'Plugin state was not found.',
67
UNDEFINED_INSTANCE_ID: 'Undefined redis database instance id.',
78
NO_CONNECTION_TO_REDIS_DB: 'No connection to the Redis Database.',

redisinsight/api/src/constants/telemetry-events.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ export enum TelemetryEvents {
3737
WorkbenchCommandExecuted = 'WORKBENCH_COMMAND_EXECUTED',
3838
WorkbenchCommandErrorReceived = 'WORKBENCH_COMMAND_ERROR_RECEIVED',
3939
WorkbenchCommandDeleted = 'WORKBENCH_COMMAND_DELETE_COMMAND',
40+
41+
// Profiler
42+
ProfilerLogDownloaded = 'PROFILER_LOG_DOWNLOADED',
43+
ProfilerLogDeleted = 'PROFILER_LOG_DELETED',
4044
}

0 commit comments

Comments
 (0)