Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8608dbe
#RI-3816 prevent creating redis client for each command in the pipeli…
Nov 18, 2022
3ae485a
#RI-3790 Fix key name returned for keys list with search w\o glob pat…
Nov 18, 2022
4ba32f8
#RI-3736 rollback implementation
Nov 18, 2022
c607512
#RI-3736 reimplement functionality to send all commands in uppercase
Nov 18, 2022
dbaaea2
#RI-3822,3742,3788_fixed
AmirAllayarovSofteq Nov 21, 2022
abb8776
#RI-3822-fix check topnamespace
AmirAllayarovSofteq Nov 21, 2022
1880889
#RI-3844 throw gateway timeout error and close the client if no respo…
Nov 21, 2022
4de575b
Merge pull request #1426 from RedisInsight/be/bugfix/RI-3844-workarou…
Nov 21, 2022
83e67de
Merge pull request #1417 from RedisInsight/be/bugfix/RI-3790-key-not-…
Nov 21, 2022
f2d3621
Merge pull request #1419 from RedisInsight/be/bugfix/RI-3736-rework_i…
Nov 21, 2022
a9dd41c
Merge pull request #1418 from RedisInsight/be/bugfix/RI-3816-multiple…
Nov 21, 2022
92e2785
#RI-3822-fix topnamespace when total = 0
AmirAllayarovSofteq Nov 22, 2022
cda844b
Merge branch 'main' into bugfix/regresion-fixes
Nov 22, 2022
1aa596f
#RI-3788-fix monitor command in group mode
AmirAllayarovSofteq Nov 22, 2022
e7163b0
fix ITests
Nov 22, 2022
d7ae94a
#RI-3789 fix cli command parsing
Nov 22, 2022
9f939ad
remove comments
Nov 22, 2022
a9d52ba
Merge pull request #1432 from RedisInsight/be/bugfix/RI-3789-fix-cli-…
Nov 22, 2022
a783526
Merge branch 'bugfix/regresion-fixes' of https://github.com/RedisInsi…
AmirAllayarovSofteq Nov 22, 2022
e123588
#RI-3742-parse commands
AmirAllayarovSofteq Nov 22, 2022
972e854
#RI-3742-resolve comments
AmirAllayarovSofteq Nov 22, 2022
19f3ea6
Merge pull request #1435 from RedisInsight/be/bugfix/RI-3742_workbenc…
AmirAllayarovSofteq Nov 22, 2022
622aeaa
#RI-3742-update styles and error handling in worbench
AmirAllayarovSofteq Nov 22, 2022
093ca43
#RI-3822-fix tests
AmirAllayarovSofteq Nov 22, 2022
07dbaee
#RI-3844 - loading after canceling redisearch request
egor-zalenski Nov 23, 2022
7f1a0a7
Merge pull request #1421 from RedisInsight/bugfix/RI-3822/3742/3788_r…
AlenaSY Nov 23, 2022
a1a0ee0
#RI-3822-update styles
AmirAllayarovSofteq Nov 23, 2022
a8d16c5
#RI-3822-update styles
AmirAllayarovSofteq Nov 23, 2022
2866b5e
Merge pull request #1436 from RedisInsight/bugfix/RI-3822/3742/3788_r…
AmirAllayarovSofteq Nov 23, 2022
028f47f
#RI-3844 rework workaround for blocked client due to ft.search command
Nov 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class TimeoutInterceptor implements NestInterceptor {

private readonly message: string;

constructor(message?: string) {
constructor(message: string = 'Request timeout') {
this.message = message;
}

Expand Down
2 changes: 2 additions & 0 deletions redisinsight/api/src/constants/telemetry-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ export enum CommandType {
Core = 'core',
Module = 'module',
}

export const unknownCommand = 'unknown';
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ describe('TelemetryBaseService', () => {

describe('sendEvent', () => {
it('should emit event', () => {
service.sendEvent(TelemetryEvents.RedisInstanceAdded, { data: 'Some data' });
service.sendEvent(TelemetryEvents.RedisInstanceAdded, { data: 'Some data', command: 'lowercase' });

expect(eventEmitter.emit).toHaveBeenCalledWith(AppAnalyticsEvents.Track, {
event: TelemetryEvents.RedisInstanceAdded,
eventData: { data: 'Some data' },
eventData: { data: 'Some data', command: 'LOWERCASE' },
});
});
it('should emit event with empty event data', () => {
Expand Down Expand Up @@ -87,13 +87,18 @@ describe('TelemetryBaseService', () => {
});
});
it('should emit event with additional event data', () => {
service.sendFailedEvent(TelemetryEvents.RedisInstanceAddFailed, httpException, { data: 'Some data' });
service.sendFailedEvent(
TelemetryEvents.RedisInstanceAddFailed,
httpException,
{ data: 'Some data', command: 'lowercase' },
);

expect(eventEmitter.emit).toHaveBeenCalledWith(AppAnalyticsEvents.Track, {
event: TelemetryEvents.RedisInstanceAddFailed,
eventData: {
error: 'Internal Server Error',
data: 'Some data',
command: 'LOWERCASE',
},
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isString } from 'lodash';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { HttpException } from '@nestjs/common';
import { AppAnalyticsEvents } from 'src/constants';
Expand All @@ -13,7 +14,10 @@ export abstract class TelemetryBaseService {
try {
this.eventEmitter.emit(AppAnalyticsEvents.Track, {
event,
eventData,
eventData: {
...eventData,
command: isString(eventData['command']) ? eventData['command'].toUpperCase() : eventData['command'],
},
});
} catch (e) {
// continue regardless of error
Expand All @@ -27,6 +31,7 @@ export abstract class TelemetryBaseService {
eventData: {
error: exception.getResponse()['error'] || exception.message,
...eventData,
command: isString(eventData['command']) ? eventData['command'].toUpperCase() : eventData['command'],
},
});
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ describe('Cluster Scanner Strategy', () => {
scanned: 10,
},
]);
expect(strategy.getKeyInfo).toHaveBeenCalledWith(clusterClient, key);
expect(strategy.getKeyInfo).toHaveBeenCalledWith(clusterClient, Buffer.from(key));
expect(strategy.scanNodes).not.toHaveBeenCalled();
});
it('should find exact key when match is escaped glob patter', async () => {
Expand Down Expand Up @@ -973,7 +973,7 @@ describe('Cluster Scanner Strategy', () => {
scanned: 10,
},
]);
expect(strategy.getKeyInfo).toHaveBeenCalledWith(clusterClient, searchPattern);
expect(strategy.getKeyInfo).toHaveBeenCalledWith(clusterClient, Buffer.from(searchPattern));
expect(strategy.scanNodes).not.toHaveBeenCalled();
});
it('should find exact key with correct type', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ClusterStrategy extends AbstractStrategy {
await this.calculateNodesTotalKeys(clientOptions, currentDbIndex, nodes);

if (!isGlob(match, { strict: false })) {
const keyName = unescapeGlob(match);
const keyName = Buffer.from(unescapeGlob(match));
nodes.forEach((node) => {
// eslint-disable-next-line no-param-reassign
node.cursor = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ describe('Standalone Scanner Strategy', () => {
},
]);
expect(strategy.getKeysInfo).toHaveBeenCalledWith(nodeClient, [
key,
Buffer.from(key),
]);
expect(strategy.scan).not.toHaveBeenCalled();
});
Expand All @@ -497,7 +497,7 @@ describe('Standalone Scanner Strategy', () => {
keys: [{ ...getKeyInfoResponse, name: mockSearchPattern }],
},
]);
expect(strategy.getKeysInfo).toHaveBeenCalledWith(nodeClient, [mockSearchPattern]);
expect(strategy.getKeysInfo).toHaveBeenCalledWith(nodeClient, [Buffer.from(mockSearchPattern)]);
expect(strategy.scan).not.toHaveBeenCalled();
});
it('should find exact key with correct type', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class StandaloneStrategy extends AbstractStrategy {
}

if (!isGlob(match, { strict: false })) {
const keyName = unescapeGlob(match);
const keyName = Buffer.from(unescapeGlob(match));
node.cursor = 0;
node.scanned = isNull(node.total) ? 1 : node.total;
node.keys = await this.getKeysInfo(client, [keyName]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('RedisearchService', () => {
'LIMIT', `${mockSearchRedisearchDto.offset}`, `${mockSearchRedisearchDto.limit}`,
],
}));
expect(nodeClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining( {
expect(nodeClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining({
name: 'FT.CONFIG',
args: [
'GET',
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('RedisearchService', () => {
'LIMIT', `${mockSearchRedisearchDto.offset}`, `${mockSearchRedisearchDto.limit}`,
],
}));
expect(clusterClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining( {
expect(clusterClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining({
name: 'FT.CONFIG',
args: [
'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { toNumber, uniq } from 'lodash';
import {
BadRequestException,
ConflictException,
HttpException,
Injectable,
Logger,
} from '@nestjs/common';
Expand Down Expand Up @@ -147,11 +148,6 @@ export class RedisearchService {

const client = await this.browserTool.getRedisClient(clientOptions);

const [total, ...keyNames] = await client.sendCommand(
new Command('FT.SEARCH', [index, query, 'NOCONTENT', 'LIMIT', offset, limit]),
);


try {
const [[, maxSearchResults]] = await client.sendCommand(
// response: [ [ 'MAXSEARCHRESULTS', '10000' ] ]
Expand All @@ -165,19 +161,34 @@ export class RedisearchService {
maxResults = null;
}

// Workaround: recalculate limit to not query more then MAXSEARCHRESULTS
let safeLimit = limit;
if (maxResults && offset + limit > maxResults) {
safeLimit = offset <= maxResults ? maxResults - offset : limit;
}

const [total, ...keyNames] = await client.sendCommand(
new Command('FT.SEARCH', [index, query, 'NOCONTENT', 'LIMIT', offset, safeLimit]),
);

return plainToClass(GetKeysWithDetailsResponse, {
cursor: limit + offset,
total,
scanned: keyNames.length + offset,
keys: keyNames.map((name) => ({ name })),
maxResults,
});
} catch (error) {
this.logger.error('Failed to search keys using redisearch index', error);
if (error.message?.includes(RedisErrorCodes.RedisearchLimit)) {
} catch (e) {
this.logger.error('Failed to search keys using redisearch index', e);

if (e instanceof HttpException) {
throw e;
}

if (e.message?.includes(RedisErrorCodes.RedisearchLimit)) {
throw new BadRequestException(ERROR_MESSAGES.INCREASE_MINIMUM_LIMIT(numberWithSpaces(dto.limit)));
}
throw catchAclError(error);
throw catchAclError(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe('CliAnalyticsService', () => {
TelemetryEvents.CliCommandExecuted,
{
databaseId,
command: mockAdditionalData.command.toUpperCase(),
command: mockAdditionalData.command,
commandType: CommandType.Core,
moduleName: 'n/a',
capability: 'string',
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('CliAnalyticsService', () => {
{
databaseId,
error: ReplyError.name,
command: mockAdditionalData.command.toUpperCase(),
command: mockAdditionalData.command,
commandType: CommandType.Core,
moduleName: 'n/a',
capability: 'string',
Expand All @@ -246,7 +246,7 @@ describe('CliAnalyticsService', () => {
{
databaseId,
error: ReplyError.name,
command: 'sadd'.toUpperCase(),
command: 'sadd',
},
);
});
Expand All @@ -259,7 +259,7 @@ describe('CliAnalyticsService', () => {
{
databaseId,
error: CommandParsingError.name,
command: mockAdditionalData.command.toUpperCase(),
command: mockAdditionalData.command,
commandType: CommandType.Core,
moduleName: 'n/a',
capability: 'string',
Expand Down Expand Up @@ -312,7 +312,7 @@ describe('CliAnalyticsService', () => {
TelemetryEvents.CliClusterNodeCommandExecuted,
{
databaseId,
command: mockAdditionalData.command.toUpperCase(),
command: mockAdditionalData.command,
commandType: CommandType.Core,
moduleName: 'n/a',
capability: 'string',
Expand All @@ -335,7 +335,7 @@ describe('CliAnalyticsService', () => {
{
databaseId,
error: redisReplyError.name,
command: 'sadd'.toUpperCase(),
command: 'sadd',
},
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export class CliAnalyticsService extends CommandTelemetryBaseService {
databaseId,
...(await this.getCommandAdditionalInfo(additionalData['command'])),
...additionalData,
command: additionalData['command']?.toUpperCase() || undefined,
},
);
} catch (e) {
Expand All @@ -102,15 +101,14 @@ export class CliAnalyticsService extends CommandTelemetryBaseService {
additionalData: object = {},
): Promise<void> {
try {
const commandFromError = error?.command?.name?.toUpperCase() || undefined;
this.sendEvent(
TelemetryEvents.CliCommandErrorReceived,
{
databaseId,
error: error?.name,
command: error?.command?.name,
...(await this.getCommandAdditionalInfo(additionalData['command'])),
...additionalData,
command: additionalData['command']?.toUpperCase() || commandFromError,
},
);
} catch (e) {
Expand All @@ -132,20 +130,18 @@ export class CliAnalyticsService extends CommandTelemetryBaseService {
databaseId,
...(await this.getCommandAdditionalInfo(additionalData['command'])),
...additionalData,
command: additionalData['command']?.toUpperCase() || undefined,
},
);
}
if (status === CommandExecutionStatus.Fail) {
const commandFromError = error?.command?.name?.toUpperCase() || undefined;
this.sendEvent(
TelemetryEvents.CliCommandErrorReceived,
{
databaseId,
error: error.name,
command: error?.command?.name,
...(await this.getCommandAdditionalInfo(additionalData['command'])),
...additionalData,
command: additionalData['command']?.toUpperCase() || commandFromError,
},
);
}
Expand Down
Loading