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
16 changes: 8 additions & 8 deletions redisinsight/api/src/__mocks__/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export const mockBrowserAnalyticsService = () => ({
});

export const mockCliAnalyticsService = () => ({
sendCliClientCreatedEvent: jest.fn(),
sendCliClientCreationFailedEvent: jest.fn(),
sendCliClientDeletedEvent: jest.fn(),
sendCliClientRecreatedEvent: jest.fn(),
sendCliCommandExecutedEvent: jest.fn(),
sendCliCommandErrorEvent: jest.fn(),
sendCliClusterCommandExecutedEvent: jest.fn(),
sendCliConnectionErrorEvent: jest.fn(),
sendClientCreatedEvent: jest.fn(),
sendClientCreationFailedEvent: jest.fn(),
sendClientDeletedEvent: jest.fn(),
sendClientRecreatedEvent: jest.fn(),
sendCommandExecutedEvent: jest.fn(),
sendCommandErrorEvent: jest.fn(),
sendClusterCommandExecutedEvent: jest.fn(),
sendConnectionErrorEvent: jest.fn(),
});

export const mockSettingsAnalyticsService = () => ({
Expand Down
16 changes: 8 additions & 8 deletions redisinsight/api/src/constants/telemetry-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export enum TelemetryEvents {
BrowserJSONPropertyDeleted = 'BROWSER_JSON_PROPERTY_DELETED',

// Events for cli tool
CliClientCreated = 'CLI_CLIENT_CREATED',
CliClientCreationFailed = 'CLI_CLIENT_CREATION_FAILED',
CliClientConnectionError = 'CLI_CLIENT_CONNECTION_ERROR',
CliClientDeleted = 'CLI_CLIENT_DELETED',
CliClientRecreated = 'CLI_CLIENT_RECREATED',
CliCommandExecuted = 'CLI_COMMAND_EXECUTED',
CliClusterNodeCommandExecuted = 'CLI_CLUSTER_COMMAND_EXECUTED',
CliCommandErrorReceived = 'CLI_COMMAND_ERROR_RECEIVED',
ClientCreated = 'CLIENT_CREATED',
ClientCreationFailed = 'CLIENT_CREATION_FAILED',
ClientConnectionError = 'CLIENT_CONNECTION_ERROR',
ClientDeleted = 'CLIENT_DELETED',
ClientRecreated = 'CLIENT_RECREATED',
CommandExecuted = 'COMMAND_EXECUTED',
ClusterNodeCommandExecuted = 'CLUSTER_COMMAND_EXECUTED',
CommandErrorReceived = 'COMMAND_ERROR_RECEIVED',
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ export class CliController {
async reCreateClient(
@Param('dbInstance') dbInstance: string,
@Param('uuid') uuid: string,
@Body() dto: CreateCliClientDto,
): Promise<CreateCliClientResponse> {
return this.service.reCreateClient(dbInstance, uuid);
return this.service.reCreateClient(dbInstance, uuid, dto.namespace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
import { InternalServerErrorException } from '@nestjs/common';
import { mockRedisWrongTypeError, mockStandaloneDatabaseEntity } from 'src/__mocks__';
import { TelemetryEvents } from 'src/constants';
import { ReplyError } from 'src/models';
import { AppTool, ReplyError } from 'src/models';
import { CliParsingError } from 'src/modules/cli/constants/errors';
import { ICliExecResultFromNode } from 'src/modules/cli/services/cli-tool/cli-tool.service';
import { CommandExecutionStatus } from 'src/modules/cli/dto/cli.dto';
Expand Down Expand Up @@ -42,21 +42,21 @@ describe('CliAnalyticsService', () => {

describe('sendCliClientCreatedEvent', () => {
it('should emit CliClientCreated event', () => {
service.sendCliClientCreatedEvent(instanceId, { data: 'Some data' });
service.sendClientCreatedEvent(instanceId, AppTool.CLI, { data: 'Some data' });

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClientCreated,
`CLI_${TelemetryEvents.ClientCreated}`,
{
databaseId: instanceId,
data: 'Some data',
},
);
});
it('should emit CliClientCreated event without additional data', () => {
service.sendCliClientCreatedEvent(instanceId);
service.sendClientCreatedEvent(instanceId, AppTool.CLI);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClientCreated,
`CLI_${TelemetryEvents.ClientCreated}`,
{
databaseId: instanceId,
},
Expand All @@ -66,10 +66,10 @@ describe('CliAnalyticsService', () => {

describe('sendCliClientCreationFailedEvent', () => {
it('should emit CliClientCreationFailed event', () => {
service.sendCliClientCreationFailedEvent(instanceId, httpException, { data: 'Some data' });
service.sendClientCreationFailedEvent(instanceId, AppTool.CLI, httpException, { data: 'Some data' });

expect(sendFailedEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClientCreationFailed,
`CLI_${TelemetryEvents.ClientCreationFailed}`,
httpException,
{
databaseId: instanceId,
Expand All @@ -78,10 +78,10 @@ describe('CliAnalyticsService', () => {
);
});
it('should emit CliClientCreationFailed event without additional data', () => {
service.sendCliClientCreationFailedEvent(instanceId, httpException);
service.sendClientCreationFailedEvent(instanceId, AppTool.CLI, httpException);

expect(sendFailedEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClientCreationFailed,
`CLI_${TelemetryEvents.ClientCreationFailed}`,
httpException,
{
databaseId: instanceId,
Expand All @@ -92,21 +92,21 @@ describe('CliAnalyticsService', () => {

describe('sendCliClientRecreatedEvent', () => {
it('should emit CliClientRecreated event', () => {
service.sendCliClientRecreatedEvent(instanceId, { data: 'Some data' });
service.sendClientRecreatedEvent(instanceId, AppTool.CLI, { data: 'Some data' });

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClientRecreated,
`CLI_${TelemetryEvents.ClientRecreated}`,
{
databaseId: instanceId,
data: 'Some data',
},
);
});
it('should emit CliClientRecreated event without additional data', () => {
service.sendCliClientRecreatedEvent(instanceId);
service.sendClientRecreatedEvent(instanceId, AppTool.CLI);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClientRecreated,
`CLI_${TelemetryEvents.ClientRecreated}`,
{
databaseId: instanceId,
},
Expand All @@ -116,57 +116,89 @@ describe('CliAnalyticsService', () => {

describe('sendCliClientDeletedEvent', () => {
it('should emit CliClientDeleted event', () => {
service.sendCliClientDeletedEvent(1, instanceId, { data: 'Some data' });
service.sendClientDeletedEvent(1, instanceId, AppTool.CLI, { data: 'Some data' });

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClientDeleted,
`CLI_${TelemetryEvents.ClientDeleted}`,
{
databaseId: instanceId,
data: 'Some data',
},
);
});
it('should emit CliClientDeleted event without additional data', () => {
service.sendCliClientDeletedEvent(1, instanceId);
service.sendClientDeletedEvent(1, instanceId, AppTool.CLI);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClientDeleted,
`CLI_${TelemetryEvents.ClientDeleted}`,
{
databaseId: instanceId,
},
);
});
it('should not emit event', () => {
service.sendCliClientDeletedEvent(0, instanceId);
service.sendClientDeletedEvent(0, instanceId, AppTool.CLI);

expect(sendEventMethod).not.toHaveBeenCalled();
});
it('should not emit event on invalid input values', () => {
const input: any = {};
service.sendCliClientDeletedEvent(input, instanceId);
service.sendClientDeletedEvent(input, instanceId, AppTool.CLI);

expect(() => service.sendCliClientDeletedEvent(input, instanceId)).not.toThrow();
expect(() => service.sendClientDeletedEvent(input, instanceId, AppTool.CLI)).not.toThrow();
expect(sendEventMethod).not.toHaveBeenCalled();
});
});

describe('sendCliCommandExecutedEvent', () => {
it('should emit CliCommandExecuted event', () => {
service.sendCliCommandExecutedEvent(instanceId, { command: 'info' });
service.sendCommandExecutedEvent(instanceId, AppTool.CLI, { command: 'info' });

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliCommandExecuted,
`CLI_${TelemetryEvents.CommandExecuted}`,
{
databaseId: instanceId,
command: 'info',
},
);
});
it('should emit CliCommandExecuted event without additional data', () => {
service.sendCliCommandExecutedEvent(instanceId);
service.sendCommandExecutedEvent(instanceId, AppTool.CLI);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliCommandExecuted,
`CLI_${TelemetryEvents.CommandExecuted}`,
{
databaseId: instanceId,
},
);
});
it('should emit CliCommandExecuted for undefined namespace', () => {
service.sendCommandExecutedEvent(instanceId, undefined, { command: 'info' });

expect(sendEventMethod).toHaveBeenCalledWith(
`CLI_${TelemetryEvents.CommandExecuted}`,
{
databaseId: instanceId,
command: 'info',
},
);
});
it('should emit WorkbenchCommandExecuted event', () => {
service.sendCommandExecutedEvent(instanceId, 'workbench', { command: 'info' });

expect(sendEventMethod).toHaveBeenCalledWith(
`WORKBENCH_${TelemetryEvents.CommandExecuted}`,
{
databaseId: instanceId,
command: 'info',
},
);
});
it('should emit WorkbenchCommandExecuted event without additional data', () => {
service.sendCommandExecutedEvent(instanceId, 'workbench');

expect(sendEventMethod).toHaveBeenCalledWith(
`WORKBENCH_${TelemetryEvents.CommandExecuted}`,
{
databaseId: instanceId,
},
Expand All @@ -176,10 +208,10 @@ describe('CliAnalyticsService', () => {

describe('sendCliCommandErrorEvent', () => {
it('should emit CliCommandError event', () => {
service.sendCliCommandErrorEvent(instanceId, redisReplyError, { data: 'Some data' });
service.sendCommandErrorEvent(instanceId, AppTool.CLI, redisReplyError, { data: 'Some data' });

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliCommandErrorReceived,
`CLI_${TelemetryEvents.CommandErrorReceived}`,
{
databaseId: instanceId,
error: ReplyError.name,
Expand All @@ -189,10 +221,10 @@ describe('CliAnalyticsService', () => {
);
});
it('should emit CliCommandError event without additional data', () => {
service.sendCliCommandErrorEvent(instanceId, redisReplyError);
service.sendCommandErrorEvent(instanceId, AppTool.CLI, redisReplyError);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliCommandErrorReceived,
`CLI_${TelemetryEvents.CommandErrorReceived}`,
{
databaseId: instanceId,
error: ReplyError.name,
Expand All @@ -202,10 +234,10 @@ describe('CliAnalyticsService', () => {
});
it('should emit event for custom error', () => {
const error: any = CliParsingError;
service.sendCliCommandErrorEvent(instanceId, error);
service.sendCommandErrorEvent(instanceId, AppTool.CLI, error);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliCommandErrorReceived,
`CLI_${TelemetryEvents.CommandErrorReceived}`,
{
databaseId: instanceId,
error: CliParsingError.name,
Expand All @@ -216,10 +248,10 @@ describe('CliAnalyticsService', () => {

describe('sendCliClientCreationFailedEvent', () => {
it('should emit CliConnectionError event', () => {
service.sendCliConnectionErrorEvent(instanceId, httpException, { data: 'Some data' });
service.sendConnectionErrorEvent(instanceId, AppTool.CLI, httpException, { data: 'Some data' });

expect(sendFailedEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClientConnectionError,
`CLI_${TelemetryEvents.ClientConnectionError}`,
httpException,
{
databaseId: instanceId,
Expand All @@ -228,10 +260,10 @@ describe('CliAnalyticsService', () => {
);
});
it('should emit CliConnectionError event without additional data', () => {
service.sendCliConnectionErrorEvent(instanceId, httpException);
service.sendConnectionErrorEvent(instanceId, AppTool.CLI, httpException);

expect(sendFailedEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClientConnectionError,
`CLI_${TelemetryEvents.ClientConnectionError}`,
httpException,
{
databaseId: instanceId,
Expand All @@ -249,10 +281,10 @@ describe('CliAnalyticsService', () => {
status: CommandExecutionStatus.Success,
};

service.sendCliClusterCommandExecutedEvent(instanceId, nodExecResult, { command: 'sadd' });
service.sendClusterCommandExecutedEvent(instanceId, AppTool.CLI, nodExecResult, { command: 'sadd' });

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliClusterNodeCommandExecuted,
`CLI_${TelemetryEvents.ClusterNodeCommandExecuted}`,
{
databaseId: instanceId,
command: 'sadd',
Expand All @@ -268,10 +300,10 @@ describe('CliAnalyticsService', () => {
status: CommandExecutionStatus.Fail,
};

service.sendCliClusterCommandExecutedEvent(instanceId, nodExecResult);
service.sendClusterCommandExecutedEvent(instanceId, AppTool.CLI, nodExecResult);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliCommandErrorReceived,
`CLI_${TelemetryEvents.CommandErrorReceived}`,
{
databaseId: instanceId,
error: redisReplyError.name,
Expand All @@ -288,10 +320,10 @@ describe('CliAnalyticsService', () => {
status: CommandExecutionStatus.Fail,
};

service.sendCliClusterCommandExecutedEvent(instanceId, nodExecResult);
service.sendClusterCommandExecutedEvent(instanceId, AppTool.CLI, nodExecResult);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.CliCommandErrorReceived,
`CLI_${TelemetryEvents.CommandErrorReceived}`,
{
databaseId: instanceId,
error: CliParsingError.name,
Expand All @@ -305,7 +337,7 @@ describe('CliAnalyticsService', () => {
port: 7002,
status: 'undefined status',
};
service.sendCliClusterCommandExecutedEvent(instanceId, nodExecResult);
service.sendClusterCommandExecutedEvent(instanceId, AppTool.CLI, nodExecResult);

expect(sendEventMethod).not.toHaveBeenCalled();
});
Expand Down
Loading