Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion redisinsight/api/src/constants/error-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default {
'Key with this name does not exist or does not have an associated timeout.',
SERVER_NOT_AVAILABLE: 'Server is not available. Please try again later.',
REDIS_CLOUD_FORBIDDEN: 'Error fetching account details.',
NO_INFO_COMMAND_PERMISSION: 'has no permissions to run the \'info\' command',

DATABASE_IS_INACTIVE: 'The database is inactive.',
DATABASE_ALREADY_EXISTS: 'The database already exists.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ describe('DatabaseConnectionService', () => {
expect(databaseInfoProvider.getClientListInfo).toHaveBeenCalled();
expect(analytics.sendDatabaseConnectedClientListEvent).toHaveBeenCalledWith(
mockSessionMetadata,
mockDatabase.id,
{
databaseId: mockDatabase.id,
clients: mockRedisClientListResult.map((c) => ({
version: mockRedisGeneralInfo.version,
resp: get(c, 'resp', 'n/a'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ export class DatabaseConnectionService {

this.analytics.sendDatabaseConnectedClientListEvent(
clientMetadata.sessionMetadata,
clientMetadata.databaseId,
{
databaseId: clientMetadata.databaseId,
...(client.isInfoCommandDisabled ? { info_command_is_disabled: true } : {}),
clients: clients.map((c) => ({
version: version || 'n/a',
resp: intVersion < 7 ? undefined : c?.['resp'] || 'n/a',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ describe('DatabaseAnalytics', () => {
it('should emit event', () => {
service.sendDatabaseConnectedClientListEvent(
mockSessionMetadata,
mockDatabase.id,
{
databaseId: mockDatabase.id,
version: mockDatabase.version,
resp: '2',
},
Expand Down
6 changes: 1 addition & 5 deletions redisinsight/api/src/modules/database/database.analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,13 @@ export class DatabaseAnalytics extends TelemetryBaseService {

sendDatabaseConnectedClientListEvent(
sessionMetadata: SessionMetadata,
databaseId: string,
additionalData: object = {},
): void {
try {
this.sendEvent(
sessionMetadata,
TelemetryEvents.DatabaseConnectedClientList,
{
databaseId,
...additionalData,
},
additionalData,
);
} catch (e) {
// continue regardless of error
Expand Down
29 changes: 18 additions & 11 deletions redisinsight/api/src/modules/redis/client/redis.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { convertRedisInfoReplyToObject } from 'src/utils';
import { convertArrayReplyToObject } from '../utils';
import * as semverCompare from 'node-version-compare';
import { RedisDatabaseHelloResponse } from 'src/modules/database/dto/redis-info.dto';
import ERROR_MESSAGES from 'src/constants/error-messages';
import { plainToClass } from 'class-transformer';

const REDIS_CLIENTS_CONFIG = apiConfig.get('redis_clients');
Expand Down Expand Up @@ -52,6 +51,7 @@ export abstract class RedisClient extends EventEmitter2 {
public readonly id: string;

protected _redisVersion: string | undefined;
protected _isInfoCommandDisabled: boolean | undefined;

protected lastTimeUsed: number;

Expand Down Expand Up @@ -83,6 +83,10 @@ export abstract class RedisClient extends EventEmitter2 {
return Date.now() - this.lastTimeUsed > REDIS_CLIENTS_CONFIG.idleThreshold;
}

public get isInfoCommandDisabled() {
return this._isInfoCommandDisabled;
}

/**
* Checks if client has established connection
*/
Expand Down Expand Up @@ -168,28 +172,31 @@ export abstract class RedisClient extends EventEmitter2 {

/**
* Get redis database info
* Uses cache by default
* If INFO fails, it will try to get info from HELLO command, which provides limited data
* If HELLO fails, it will return a static object
* @param force
* @param infoSection - e.g. server, clients, memory, etc.
*/
public async getInfo(infoSection?: string) {
let infoData: any; // TODO: we should ideally type this

try {
return convertRedisInfoReplyToObject(await this.call(
infoData = convertRedisInfoReplyToObject(await this.call(
infoSection ? ['info', infoSection] : ['info'],
{ replyEncoding: 'utf8' },
) as string);
this._isInfoCommandDisabled = false;
} catch (error) {
if (error.message.includes(ERROR_MESSAGES.NO_INFO_COMMAND_PERMISSION)) {
try {
// Fallback to getting basic information from `hello` command
return await this.getRedisHelloInfo();
} catch (_error) {
// Ignore: hello is not available pre redis version 6
}
this._isInfoCommandDisabled = true;
try {
// Fallback to getting basic information from `hello` command
infoData = await this.getRedisHelloInfo();
} catch (_error) {
// Ignore: hello is not available pre redis version 6
}
}

return UNKNOWN_REDIS_INFO;
return infoData ?? UNKNOWN_REDIS_INFO;
}

private async getRedisHelloInfo() {
Expand Down