Skip to content

Commit d8eff52

Browse files
authored
Merge pull request #3757 from RedisInsight/be/bugfix/RI-6051-scan-threshold-fix
fix scan threshold
2 parents 0c8c4c1 + 38cb1c9 commit d8eff52

File tree

11 files changed

+34
-31
lines changed

11 files changed

+34
-31
lines changed

redisinsight/api/config/default.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export default {
114114
},
115115
redis_scan: {
116116
countDefault: parseInt(process.env.RI_SCAN_COUNT_DEFAULT, 10) || 200,
117-
countThreshold: parseInt(process.env.RI_SCAN_COUNT_THRESHOLD, 10) || 10000,
118-
countThresholdMax: parseInt(process.env.RI_SCAN_COUNT_THRESHOLD_MAX, 10) || Number.MAX_VALUE,
117+
scanThreshold: parseInt(process.env.RI_SCAN_THRESHOLD, 10) || 10000,
118+
scanThresholdMax: parseInt(process.env.RI_SCAN_THRESHOLD_MAX, 10) || Number.MAX_VALUE,
119119
},
120120
modules: {
121121
json: {

redisinsight/api/src/modules/browser/keys/dto/get.keys.dto.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import config, { Config } from 'src/utils/config';
77
import { RedisDataType } from './key.dto';
88

99
const scanConfig = config.get('redis_scan') as Config['redis_scan'];
10-
const { countThreshold, countThresholdMax } = scanConfig;
10+
const { scanThreshold, scanThresholdMax } = scanConfig;
1111

1212
export class GetKeysDto {
1313
@ApiProperty({
@@ -67,12 +67,12 @@ export class GetKeysDto {
6767
keysInfo?: boolean = true;
6868

6969
@ApiPropertyOptional({
70-
description: 'The maximum number of iterations when performing a Redis SCAN operation.',
70+
description: 'The maximum number of keys to scan',
7171
type: Number,
7272
default: true,
7373
})
7474
@IsOptional()
7575
@IsInt()
76-
@Max(countThresholdMax)
77-
countThreshold: number = countThreshold;
76+
@Max(scanThresholdMax)
77+
scanThreshold: number = scanThreshold;
7878
}

redisinsight/api/src/modules/browser/keys/keys.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ describe('KeysService', () => {
212212
});
213213

214214
describe('getKeys', () => {
215-
const getKeysDto: GetKeysDto = { cursor: '0', count: 15, countThreshold: 10000 };
215+
const getKeysDto: GetKeysDto = { cursor: '0', count: 15, scanThreshold: 10000 };
216216
it('should return appropriate value for standalone database', async () => {
217217
mockScannerStrategy.getKeys.mockResolvedValue([mockGetKeysWithDetailsResponse]);
218218

redisinsight/api/src/modules/browser/keys/scanner/scanner.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface IScannerGetKeysArgs {
88
match?: string;
99
type?: RedisDataType;
1010
keysInfo?: boolean;
11-
countThreshold: number;
11+
scanThreshold: number;
1212
}
1313

1414
export interface IScannerNodeKeys {

redisinsight/api/src/modules/browser/keys/scanner/strategies/cluster.scanner.strategy.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ describe('Cluster Scanner Strategy', () => {
8787
});
8888

8989
describe('getKeys', () => {
90-
const getKeysDto: GetKeysDto = { cursor: '0', count: 15, keysInfo: true, countThreshold: 1000 };
90+
const getKeysDto: GetKeysDto = {
91+
cursor: '0', count: 15, keysInfo: true, scanThreshold: 1000,
92+
};
9193

9294
it('should return appropriate value with filter by type', async () => {
9395
const args = { ...getKeysDto, type: RedisDataType.String, match: 'pattern*' };
@@ -330,7 +332,7 @@ describe('Cluster Scanner Strategy', () => {
330332
const expectedNode3CallsBeforeThreshold = Math.trunc(
331333
// -5 is number of scans for node1 (3) and node2 (2)
332334
// since threshold applied for sum of all nodes scanned
333-
getKeysDto.countThreshold / args.count - 5,
335+
getKeysDto.scanThreshold / args.count - 5,
334336
);
335337

336338
jest.spyOn(Utils, 'getTotalKeys').mockResolvedValueOnce(mockGetTotalResponse3000);
@@ -393,7 +395,7 @@ describe('Cluster Scanner Strategy', () => {
393395
total: mockGetTotalResponse1000000,
394396
cursor: 1,
395397
scanned:
396-
Math.trunc(getKeysDto.countThreshold / args.count)
398+
Math.trunc(getKeysDto.scanThreshold / args.count)
397399
* args.count
398400
- 5 * args.count, // 5 = scan for other shards (3 and 2)
399401
keys: [],

redisinsight/api/src/modules/browser/keys/scanner/strategies/cluster.scanner.strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class ClusterScannerStrategy extends ScannerStrategy {
108108
public async getKeys(client: RedisClient, args: IScannerGetKeysArgs): Promise<GetKeysWithDetailsResponse[]> {
109109
const match = args.match !== undefined ? args.match : '*';
110110
const count = args.count || REDIS_SCAN_CONFIG.countDefault;
111-
const scanThreshold = args.countThreshold || REDIS_SCAN_CONFIG.countThreshold;
111+
const scanThreshold = args.scanThreshold || REDIS_SCAN_CONFIG.scanThreshold;
112112
const nodes = await this.getNodesToScan(client, args.cursor);
113113

114114
await this.calculateNodesTotalKeys(nodes);

redisinsight/api/src/modules/browser/keys/scanner/strategies/standalone.scanner.strategy.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ describe('StandaloneScannerStrategy', () => {
5555
});
5656

5757
describe('getKeys', () => {
58-
const getKeysDto: GetKeysDto = { cursor: '0', count: 15, keysInfo: true, countThreshold: 1000 };
58+
const getKeysDto: GetKeysDto = {
59+
cursor: '0', count: 15, keysInfo: true, scanThreshold: 1000,
60+
};
5961
it('should return appropriate value with filter by type', async () => {
6062
const args = { ...getKeysDto, type: RedisDataType.String, match: 'pattern*' };
6163
jest.spyOn(Utils, 'getTotalKeys').mockResolvedValue(mockGetTotalResponse1);
@@ -212,7 +214,7 @@ describe('StandaloneScannerStrategy', () => {
212214
cursor: 1,
213215
total: 1000000,
214216
scanned:
215-
Math.trunc(getKeysDto.countThreshold / getKeysDto.count)
217+
Math.trunc(getKeysDto.scanThreshold / getKeysDto.count)
216218
* getKeysDto.count
217219
+ getKeysDto.count,
218220
keys: [],
@@ -237,7 +239,7 @@ describe('StandaloneScannerStrategy', () => {
237239
cursor: 1,
238240
total: null,
239241
scanned:
240-
Math.trunc(getKeysDto.countThreshold / getKeysDto.count)
242+
Math.trunc(getKeysDto.scanThreshold / getKeysDto.count)
241243
* getKeysDto.count
242244
+ getKeysDto.count,
243245
keys: [],
@@ -254,7 +256,7 @@ describe('StandaloneScannerStrategy', () => {
254256
const result = await strategy.getKeys(mockStandaloneRedisClient, {
255257
cursor: '0',
256258
type: RedisDataType.String,
257-
countThreshold: 1000,
259+
scanThreshold: 1000,
258260
});
259261

260262
expect(strategy['scan']).toHaveBeenLastCalledWith(

redisinsight/api/src/modules/browser/keys/scanner/strategies/standalone.scanner.strategy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class StandaloneScannerStrategy extends ScannerStrategy {
111111
public async getKeys(client: RedisClient, args: IScannerGetKeysArgs): Promise<GetKeysWithDetailsResponse[]> {
112112
const match = args.match !== undefined ? args.match : '*';
113113
const count = args.count || REDIS_SCAN_CONFIG.countDefault;
114+
const scanThreshold = args.scanThreshold || REDIS_SCAN_CONFIG.scanThreshold;
114115

115116
const node = {
116117
total: 0,
@@ -138,7 +139,7 @@ export class StandaloneScannerStrategy extends ScannerStrategy {
138139
return [node];
139140
}
140141

141-
await this.scan(client, node, match, count, args.countThreshold, args.type);
142+
await this.scan(client, node, match, count, scanThreshold, args.type);
142143

143144
if (node.keys.length && args.keysInfo) {
144145
node.keys = await this.getKeysInfo(client, node.keys, args.type);

redisinsight/api/src/modules/settings/dto/settings.dto.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export class GetAppSettingsResponse {
7676
example: 10000,
7777
})
7878
@Expose()
79-
@Default(REDIS_SCAN_CONFIG.countThreshold)
80-
scanThreshold: number = REDIS_SCAN_CONFIG.countThreshold;
79+
@Default(REDIS_SCAN_CONFIG.scanThreshold)
80+
scanThreshold: number = REDIS_SCAN_CONFIG.scanThreshold;
8181

8282
@ApiProperty({
8383
description: 'Applied the batch of the commands for workbench.',

redisinsight/api/src/modules/settings/settings.service.spec.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
mockAgreementsRepository, mockAppSettings,
66
mockEncryptionStrategyInstance, mockKeyEncryptionStrategyInstance, mockSessionMetadata, mockSettings,
77
mockSettingsAnalyticsService, mockSettingsRepository,
8-
MockType, mockUserId,
8+
MockType,
99
} from 'src/__mocks__';
1010
import { UpdateSettingsDto } from 'src/modules/settings/dto/settings.dto';
1111
import * as AGREEMENTS_SPEC from 'src/constants/agreements-spec.json';
@@ -38,7 +38,6 @@ describe('SettingsService', () => {
3838
let settingsRepository: MockType<SettingsRepository>;
3939
let analyticsService: SettingsAnalytics;
4040
let keytarStrategy: MockType<KeytarEncryptionStrategy>;
41-
let keyStrategy: MockType<KeyEncryptionStrategy>;
4241
let eventEmitter: EventEmitter2;
4342

4443
beforeEach(async () => {
@@ -75,13 +74,12 @@ describe('SettingsService', () => {
7574
],
7675
}).compile();
7776

78-
agreementsRepository = await module.get(AgreementsRepository);
79-
settingsRepository = await module.get(SettingsRepository);
80-
keytarStrategy = await module.get(KeytarEncryptionStrategy);
81-
keyStrategy = await module.get(KeyEncryptionStrategy);
82-
analyticsService = await module.get<SettingsAnalytics>(SettingsAnalytics);
83-
service = await module.get(SettingsService);
84-
eventEmitter = await module.get(EventEmitter2);
77+
agreementsRepository = module.get(AgreementsRepository);
78+
settingsRepository = module.get(SettingsRepository);
79+
keytarStrategy = module.get(KeytarEncryptionStrategy);
80+
analyticsService = module.get(SettingsAnalytics);
81+
service = module.get(SettingsService);
82+
eventEmitter = module.get(EventEmitter2);
8583
});
8684

8785
describe('getAppSettings', () => {
@@ -93,7 +91,7 @@ describe('SettingsService', () => {
9391

9492
expect(result).toEqual({
9593
theme: null,
96-
scanThreshold: REDIS_SCAN_CONFIG.countThreshold,
94+
scanThreshold: REDIS_SCAN_CONFIG.scanThreshold,
9795
batchSize: WORKBENCH_CONFIG.countBatch,
9896
agreements: null,
9997
});
@@ -212,7 +210,7 @@ describe('SettingsService', () => {
212210
expect(analyticsService.sendAnalyticsAgreementChange).not.toHaveBeenCalled();
213211
expect(analyticsService.sendSettingsUpdatedEvent).toHaveBeenCalledWith(mockAppSettings, {
214212
...mockAppSettings,
215-
scanThreshold: REDIS_SCAN_CONFIG.countThreshold,
213+
scanThreshold: REDIS_SCAN_CONFIG.scanThreshold,
216214
batchSize: WORKBENCH_CONFIG.countBatch,
217215
theme: null,
218216
});

0 commit comments

Comments
 (0)