Skip to content

Commit 3fdc300

Browse files
authored
Merge pull request #2711 from RedisInsight/feature/RI-4643-move-to-node-redis
Feature/ri 4643 move to node redis
2 parents 7c0f409 + fe55268 commit 3fdc300

File tree

559 files changed

+14643
-17428
lines changed

Some content is hidden

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

559 files changed

+14643
-17428
lines changed

.circleci/config.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ parameters:
201201
docker:
202202
type: string
203203
default: *ignore
204+
redis_client:
205+
type: string
206+
default: ""
204207

205208
jobs:
206209
# Test jobs
@@ -302,6 +305,10 @@ jobs:
302305
description: Send report for test run to slack
303306
type: boolean
304307
default: false
308+
redis_client:
309+
description: Library to use for redis connection
310+
type: string
311+
default: ""
305312
steps:
306313
- checkout
307314
- restore_cache:
@@ -319,6 +326,10 @@ jobs:
319326
- run:
320327
name: Run tests
321328
command: |
329+
if [ << parameters.redis_client >> != "" ]; then
330+
export RI_REDIS_CLIENTS_FORCE_STRATEGY=<< parameters.redis_client >>
331+
fi
332+
322333
./redisinsight/api/test/test-runs/start-test-run.sh -r << parameters.rte >> -t << parameters.build >>
323334
mkdir -p mkdir itest/coverages && mkdir -p itest/results
324335
cp ./redisinsight/api/test/test-runs/coverage/test-run-result.json ./itest/results/<< parameters.rte >>.result.json
@@ -1182,6 +1193,7 @@ workflows:
11821193
- /^be/feature.*/
11831194
- /^be/bugfix.*/
11841195
- integration-tests-run:
1196+
redis_client: << pipeline.parameters.redis_client >>
11851197
matrix:
11861198
alias: itest-code
11871199
parameters:
@@ -1258,6 +1270,8 @@ workflows:
12581270
alias: itest-code
12591271
parameters:
12601272
rte: *iTestsNames
1273+
redis_client:
1274+
- << pipeline.parameters.redis_client >>
12611275
name: ITest - << matrix.rte >> (code)
12621276
requires:
12631277
- Start All Tests
@@ -1494,6 +1508,8 @@ workflows:
14941508
alias: itest-code
14951509
parameters:
14961510
rte: *iTestsNames
1511+
redis_client:
1512+
- << pipeline.parameters.redis_client >>
14971513
name: ITest - << matrix.rte >> (code)
14981514
filters: *releaseAndLatestFilter
14991515
- integration-tests-coverage:

redisinsight/api/.eslintrc.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ module.exports = {
2020
},
2121
overrides: [
2222
{
23-
files: [ '**/*.spec.ts' ],
23+
files: [ '**/*.spec.ts', '**/__mocks__/**/*' ],
2424
rules: {
25-
'no-duplicate-string': 'off',
25+
'sonarjs/no-duplicate-string': 0,
26+
'sonarjs/no-identical-functions': 0,
27+
'import/first': 0,
2628
}
2729
}
2830
]

redisinsight/api/config/default.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export default {
7272
migrationsRun: process.env.RI_DB_MIGRATIONS ? process.env.RI_DB_MIGRATIONS === 'true' : true,
7373
},
7474
redis_clients: {
75+
forceStrategy: process.env.RI_REDIS_CLIENTS_FORCE_STRATEGY,
76+
idleThreshold: parseInt(process.env.RI_REDIS_CLIENTS_IDLE_THRESHOLD, 10) || 1000 * 60 * 60, // 1h
77+
syncInterval: parseInt(process.env.RI_REDIS_CLIENTS_SYNC_INTERVAL, 10) || 1000 * 60, // 1m
7578
idleSyncInterval: parseInt(process.env.RI_CLIENTS_IDLE_SYNC_INTERVAL, 10) || 1000 * 60 * 60, // 1hr
7679
maxIdleThreshold: parseInt(process.env.RI_CLIENTS_MAX_IDLE_THRESHOLD, 10) || 1000 * 60 * 60, // 1hr
7780
retryTimes: parseInt(process.env.RI_CLIENTS_RETRY_TIMES, 10) || 3,

redisinsight/api/config/features-config.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 2.3403,
2+
"version": 2.3405,
33
"features": {
44
"insightsRecommendations": {
55
"flag": true,
@@ -82,6 +82,13 @@
8282
}
8383
]
8484
}
85+
},
86+
"redisClient": {
87+
"flag": true,
88+
"perc": [[0, 100]],
89+
"data": {
90+
"strategy": "ioredis"
91+
}
8592
}
8693
}
8794
}

redisinsight/api/config/ormconfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import { CaCertificateEntity } from 'src/modules/certificate/entities/ca-certifi
1313
import { ClientCertificateEntity } from 'src/modules/certificate/entities/client-certificate.entity';
1414
import { DatabaseEntity } from 'src/modules/database/entities/database.entity';
1515
import { SshOptionsEntity } from 'src/modules/ssh/entities/ssh-options.entity';
16-
import { BrowserHistoryEntity } from 'src/modules/browser/entities/browser-history.entity';
16+
import { BrowserHistoryEntity } from 'src/modules/browser/browser-history/entities/browser-history.entity';
1717
import { CustomTutorialEntity } from 'src/modules/custom-tutorial/entities/custom-tutorial.entity';
1818
import { FeatureEntity } from 'src/modules/feature/entities/feature.entity';
1919
import { FeaturesConfigEntity } from 'src/modules/feature/entities/features-config.entity';
2020
import { CloudDatabaseDetailsEntity } from 'src/modules/cloud/database/entities/cloud-database-details.entity';
21+
import { CloudCapiKeyEntity } from 'src/modules/cloud/capi-key/entity/cloud-capi-key.entity';
2122
import migrations from '../migration';
2223
import * as config from '../src/utils/config';
23-
import { CloudCapiKeyEntity } from 'src/modules/cloud/capi-key/entity/cloud-capi-key.entity';
2424

2525
const dbConfig = config.get('db');
2626

redisinsight/api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@
7676
"nest-winston": "^1.4.0",
7777
"nestjs-form-data": "^1.8.7",
7878
"node-version-compare": "^1.0.3",
79+
"redis": "^4.6.10",
7980
"reflect-metadata": "^0.1.13",
8081
"rxjs": "^7.5.6",
8182
"socket.io": "^4.6.2",
8283
"source-map-support": "^0.5.19",
8384
"sqlite3": "5.1.6",
84-
"ssh2": "^1.14.0",
8585
"swagger-ui-express": "^4.1.4",
86+
"tunnel-ssh": "^5.1.2",
8687
"typeorm": "^0.3.9",
8788
"uuid": "^8.3.2",
8889
"winston": "^3.3.3",

redisinsight/api/src/__mocks__/analytics.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
import { EventEmitter2 } from '@nestjs/event-emitter';
2-
import { BulkActionsAnalyticsService } from 'src/modules/bulk-actions/bulk-actions-analytics.service';
3-
4-
const mockEmitter = new EventEmitter2();
5-
6-
class AnalyticsService extends BulkActionsAnalyticsService {
7-
constructor(protected eventEmitter: EventEmitter2) {
8-
super(eventEmitter);
9-
}
10-
}
11-
12-
export const mockInstancesAnalyticsService = () => ({
13-
sendInstanceListReceivedEvent: jest.fn(),
14-
sendInstanceAddedEvent: jest.fn(),
15-
sendInstanceAddFailedEvent: jest.fn(),
16-
sendInstanceEditedEvent: jest.fn(),
17-
sendInstanceDeletedEvent: jest.fn(),
18-
sendConnectionFailedEvent: jest.fn(),
19-
});
20-
211
export const mockCliAnalyticsService = () => ({
222
sendClientCreatedEvent: jest.fn(),
233
sendClientCreationFailedEvent: jest.fn(),
@@ -40,8 +20,6 @@ export const mockSettingsAnalyticsService = () => ({
4020
sendSettingsUpdatedEvent: jest.fn(),
4121
});
4222

43-
export const mockBulActionsAnalyticsService = new AnalyticsService(mockEmitter);
44-
4523
export const mockPubSubAnalyticsService = () => ({
4624
sendMessagePublishedEvent: jest.fn(),
4725
sendChannelSubscribeEvent: jest.fn(),

redisinsight/api/src/__mocks__/browser-history.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { plainToClass } from "class-transformer";
1+
import { plainToClass } from 'class-transformer';
22
import { v4 as uuidv4 } from 'uuid';
33
import {
44
mockDatabase,
55
} from 'src/__mocks__';
6-
import { BrowserHistoryMode } from "src/common/constants";
7-
import { RedisDataType } from "src/modules/browser/dto";
8-
import { CreateBrowserHistoryDto } from "src/modules/browser/dto/browser-history/create.browser-history.dto";
9-
import { BrowserHistory, ScanFilter } from "src/modules/browser/dto/browser-history/get.browser-history.dto";
10-
import { BrowserHistoryEntity } from "src/modules/browser/entities/browser-history.entity";
6+
import { BrowserHistoryMode } from 'src/common/constants';
7+
import { RedisDataType } from 'src/modules/browser/keys/dto';
8+
import { CreateBrowserHistoryDto, BrowserHistory, ScanFilter } from 'src/modules/browser/browser-history/dto';
9+
import { BrowserHistoryEntity } from 'src/modules/browser/browser-history/entities/browser-history.entity';
1110

1211
export const mockBrowserHistoryService = () => ({
1312
create: jest.fn(),
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { BulkActionStatus, BulkActionType } from 'src/modules/bulk-actions/constants';
2+
import { BulkActionFilter } from 'src/modules/bulk-actions/models/bulk-action-filter';
3+
import { BulkActionProgress } from 'src/modules/bulk-actions/models/bulk-action-progress';
4+
import { BulkActionSummary } from 'src/modules/bulk-actions/models/bulk-action-summary';
5+
6+
export const mockCreateBulkActionDto = {
7+
id: 'bulk-action-id',
8+
databaseId: 'database-id',
9+
type: BulkActionType.Delete,
10+
};
11+
12+
export const mockBulkActionOverview = {
13+
...mockCreateBulkActionDto,
14+
duration: 100,
15+
filter: { match: '*', type: null },
16+
progress: {
17+
scanned: 0,
18+
total: 0,
19+
},
20+
status: BulkActionStatus.Completed,
21+
summary: {
22+
failed: 0,
23+
processed: 0,
24+
succeed: 0,
25+
errors: [],
26+
},
27+
};
28+
29+
export const mockBulkActionOverviewMatcher = {
30+
...mockBulkActionOverview,
31+
duration: jasmine.any(Number),
32+
};
33+
34+
export const mockBulkActionFilter = new BulkActionFilter();
35+
36+
const mockKey = 'mockedKey';
37+
const mockKeyBuffer = Buffer.from(mockKey);
38+
const mockRESPError = 'Reply Error: NOPERM for delete.';
39+
const mockRESPErrorBuffer = Buffer.from(mockRESPError);
40+
41+
export const generateMockBulkActionErrors = (amount: number, raw = true): any => (
42+
new Array(amount).fill(1)
43+
).map(
44+
() => ({
45+
key: raw ? mockKeyBuffer : mockKey,
46+
error: raw ? mockRESPErrorBuffer : mockRESPError,
47+
}),
48+
);
49+
50+
export const generateMockBulkActionProgress = () => {
51+
const progress = new BulkActionProgress();
52+
53+
progress['total'] = 1_000_000;
54+
progress['scanned'] = 1_000_000;
55+
56+
return progress;
57+
};
58+
59+
export const generateMockBulkActionSummary = () => {
60+
const summary = new BulkActionSummary();
61+
62+
summary['processed'] = 1_000_000;
63+
summary['succeed'] = 900_000;
64+
summary['failed'] = 100_000;
65+
summary['errors'] = generateMockBulkActionErrors(500);
66+
67+
return summary;
68+
};
69+
70+
export const mockBulkActionsAnalytics = () => ({
71+
sendActionStarted: jest.fn(),
72+
sendActionStopped: jest.fn(),
73+
sendActionSucceed: jest.fn(),
74+
sendActionFailed: jest.fn(),
75+
});

redisinsight/api/src/__mocks__/common.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@ export type MockType<T> = {
66
[P in keyof T]: jest.Mock<any>;
77
};
88

9-
export const mockRedisConsumer = () => ({
10-
execCommand: jest.fn(),
11-
execPipeline: jest.fn(),
12-
execPipelineFromClient: jest.fn(),
13-
getRedisClient: jest.fn(),
14-
execMulti: jest.fn(),
15-
});
16-
17-
export const mockRedisClusterConsumer = () => ({
18-
execCommand: jest.fn(),
19-
execCommandFromNodes: jest.fn(),
20-
execCommandFromNode: jest.fn(),
21-
execPipeline: jest.fn(),
22-
getNodes: jest.fn(),
23-
getRedisClient: jest.fn(),
24-
});
25-
269
export const mockQueryBuilderWhere = jest.fn().mockReturnThis();
2710
export const mockQueryBuilderGetOne = jest.fn();
2811
export const mockQueryBuilderGetMany = jest.fn();

0 commit comments

Comments
 (0)