Skip to content

Commit 5fe2699

Browse files
author
Artyom Podymov
committed
#RI-1100 - add telemetry events for the workbench
1 parent a9ac08c commit 5fe2699

File tree

13 files changed

+313
-118
lines changed

13 files changed

+313
-118
lines changed

redisinsight/api/src/__mocks__/analytics.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export const mockBrowserAnalyticsService = () => ({
2323
});
2424

2525
export const mockCliAnalyticsService = () => ({
26-
sendCliClientCreatedEvent: jest.fn(),
27-
sendCliClientCreationFailedEvent: jest.fn(),
28-
sendCliClientDeletedEvent: jest.fn(),
29-
sendCliClientRecreatedEvent: jest.fn(),
30-
sendCliCommandExecutedEvent: jest.fn(),
31-
sendCliCommandErrorEvent: jest.fn(),
32-
sendCliClusterCommandExecutedEvent: jest.fn(),
33-
sendCliConnectionErrorEvent: jest.fn(),
26+
sendClientCreatedEvent: jest.fn(),
27+
sendClientCreationFailedEvent: jest.fn(),
28+
sendClientDeletedEvent: jest.fn(),
29+
sendClientRecreatedEvent: jest.fn(),
30+
sendCommandExecutedEvent: jest.fn(),
31+
sendCommandErrorEvent: jest.fn(),
32+
sendClusterCommandExecutedEvent: jest.fn(),
33+
sendConnectionErrorEvent: jest.fn(),
3434
});
3535

3636
export const mockSettingsAnalyticsService = () => ({

redisinsight/api/src/constants/telemetry-events.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ export enum TelemetryEvents {
3838
BrowserJSONPropertyDeleted = 'BROWSER_JSON_PROPERTY_DELETED',
3939

4040
// Events for cli tool
41-
CliClientCreated = 'CLI_CLIENT_CREATED',
42-
CliClientCreationFailed = 'CLI_CLIENT_CREATION_FAILED',
43-
CliClientConnectionError = 'CLI_CLIENT_CONNECTION_ERROR',
44-
CliClientDeleted = 'CLI_CLIENT_DELETED',
45-
CliClientRecreated = 'CLI_CLIENT_RECREATED',
46-
CliCommandExecuted = 'CLI_COMMAND_EXECUTED',
47-
CliClusterNodeCommandExecuted = 'CLI_CLUSTER_COMMAND_EXECUTED',
48-
CliCommandErrorReceived = 'CLI_COMMAND_ERROR_RECEIVED',
41+
ClientCreated = 'CLIENT_CREATED',
42+
ClientCreationFailed = 'CLIENT_CREATION_FAILED',
43+
ClientConnectionError = 'CLIENT_CONNECTION_ERROR',
44+
ClientDeleted = 'CLIENT_DELETED',
45+
ClientRecreated = 'CLIENT_RECREATED',
46+
CommandExecuted = 'COMMAND_EXECUTED',
47+
ClusterNodeCommandExecuted = 'CLUSTER_COMMAND_EXECUTED',
48+
CommandErrorReceived = 'COMMAND_ERROR_RECEIVED',
4949
}

redisinsight/api/src/modules/cli/controllers/cli.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ export class CliController {
132132
async reCreateClient(
133133
@Param('dbInstance') dbInstance: string,
134134
@Param('uuid') uuid: string,
135+
@Body() dto: CreateCliClientDto,
135136
): Promise<CreateCliClientResponse> {
136-
return this.service.reCreateClient(dbInstance, uuid);
137+
return this.service.reCreateClient(dbInstance, uuid, dto.namespace);
137138
}
138139
}

redisinsight/api/src/modules/cli/services/cli-analytics/cli-analytics.service.spec.ts

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
33
import { InternalServerErrorException } from '@nestjs/common';
44
import { mockRedisWrongTypeError, mockStandaloneDatabaseEntity } from 'src/__mocks__';
55
import { TelemetryEvents } from 'src/constants';
6-
import { ReplyError } from 'src/models';
6+
import { AppTool, ReplyError } from 'src/models';
77
import { CliParsingError } from 'src/modules/cli/constants/errors';
88
import { ICliExecResultFromNode } from 'src/modules/cli/services/cli-tool/cli-tool.service';
99
import { CommandExecutionStatus } from 'src/modules/cli/dto/cli.dto';
@@ -42,21 +42,21 @@ describe('CliAnalyticsService', () => {
4242

4343
describe('sendCliClientCreatedEvent', () => {
4444
it('should emit CliClientCreated event', () => {
45-
service.sendCliClientCreatedEvent(instanceId, { data: 'Some data' });
45+
service.sendClientCreatedEvent(instanceId, 'cli', { data: 'Some data' });
4646

4747
expect(sendEventMethod).toHaveBeenCalledWith(
48-
TelemetryEvents.CliClientCreated,
48+
`CLI_${TelemetryEvents.ClientCreated}`,
4949
{
5050
databaseId: instanceId,
5151
data: 'Some data',
5252
},
5353
);
5454
});
5555
it('should emit CliClientCreated event without additional data', () => {
56-
service.sendCliClientCreatedEvent(instanceId);
56+
service.sendClientCreatedEvent(instanceId, AppTool.CLI);
5757

5858
expect(sendEventMethod).toHaveBeenCalledWith(
59-
TelemetryEvents.CliClientCreated,
59+
`CLI_${TelemetryEvents.ClientCreated}`,
6060
{
6161
databaseId: instanceId,
6262
},
@@ -66,10 +66,10 @@ describe('CliAnalyticsService', () => {
6666

6767
describe('sendCliClientCreationFailedEvent', () => {
6868
it('should emit CliClientCreationFailed event', () => {
69-
service.sendCliClientCreationFailedEvent(instanceId, httpException, { data: 'Some data' });
69+
service.sendClientCreationFailedEvent(instanceId, 'cli', httpException, { data: 'Some data' });
7070

7171
expect(sendFailedEventMethod).toHaveBeenCalledWith(
72-
TelemetryEvents.CliClientCreationFailed,
72+
`CLI_${TelemetryEvents.ClientCreationFailed}`,
7373
httpException,
7474
{
7575
databaseId: instanceId,
@@ -78,10 +78,10 @@ describe('CliAnalyticsService', () => {
7878
);
7979
});
8080
it('should emit CliClientCreationFailed event without additional data', () => {
81-
service.sendCliClientCreationFailedEvent(instanceId, httpException);
81+
service.sendClientCreationFailedEvent(instanceId, 'cli', httpException);
8282

8383
expect(sendFailedEventMethod).toHaveBeenCalledWith(
84-
TelemetryEvents.CliClientCreationFailed,
84+
`CLI_${TelemetryEvents.ClientCreationFailed}`,
8585
httpException,
8686
{
8787
databaseId: instanceId,
@@ -92,21 +92,21 @@ describe('CliAnalyticsService', () => {
9292

9393
describe('sendCliClientRecreatedEvent', () => {
9494
it('should emit CliClientRecreated event', () => {
95-
service.sendCliClientRecreatedEvent(instanceId, { data: 'Some data' });
95+
service.sendClientRecreatedEvent(instanceId, 'cli', { data: 'Some data' });
9696

9797
expect(sendEventMethod).toHaveBeenCalledWith(
98-
TelemetryEvents.CliClientRecreated,
98+
`CLI_${TelemetryEvents.ClientRecreated}`,
9999
{
100100
databaseId: instanceId,
101101
data: 'Some data',
102102
},
103103
);
104104
});
105105
it('should emit CliClientRecreated event without additional data', () => {
106-
service.sendCliClientRecreatedEvent(instanceId);
106+
service.sendClientRecreatedEvent(instanceId, 'cli');
107107

108108
expect(sendEventMethod).toHaveBeenCalledWith(
109-
TelemetryEvents.CliClientRecreated,
109+
`CLI_${TelemetryEvents.ClientRecreated}`,
110110
{
111111
databaseId: instanceId,
112112
},
@@ -116,57 +116,89 @@ describe('CliAnalyticsService', () => {
116116

117117
describe('sendCliClientDeletedEvent', () => {
118118
it('should emit CliClientDeleted event', () => {
119-
service.sendCliClientDeletedEvent(1, instanceId, { data: 'Some data' });
119+
service.sendClientDeletedEvent(1, instanceId, 'cli', { data: 'Some data' });
120120

121121
expect(sendEventMethod).toHaveBeenCalledWith(
122-
TelemetryEvents.CliClientDeleted,
122+
`CLI_${TelemetryEvents.ClientDeleted}`,
123123
{
124124
databaseId: instanceId,
125125
data: 'Some data',
126126
},
127127
);
128128
});
129129
it('should emit CliClientDeleted event without additional data', () => {
130-
service.sendCliClientDeletedEvent(1, instanceId);
130+
service.sendClientDeletedEvent(1, instanceId, 'cli');
131131

132132
expect(sendEventMethod).toHaveBeenCalledWith(
133-
TelemetryEvents.CliClientDeleted,
133+
`CLI_${TelemetryEvents.ClientDeleted}`,
134134
{
135135
databaseId: instanceId,
136136
},
137137
);
138138
});
139139
it('should not emit event', () => {
140-
service.sendCliClientDeletedEvent(0, instanceId);
140+
service.sendClientDeletedEvent(0, instanceId, 'cli');
141141

142142
expect(sendEventMethod).not.toHaveBeenCalled();
143143
});
144144
it('should not emit event on invalid input values', () => {
145145
const input: any = {};
146-
service.sendCliClientDeletedEvent(input, instanceId);
146+
service.sendClientDeletedEvent(input, instanceId, 'cli');
147147

148-
expect(() => service.sendCliClientDeletedEvent(input, instanceId)).not.toThrow();
148+
expect(() => service.sendClientDeletedEvent(input, instanceId, 'cli')).not.toThrow();
149149
expect(sendEventMethod).not.toHaveBeenCalled();
150150
});
151151
});
152152

153153
describe('sendCliCommandExecutedEvent', () => {
154154
it('should emit CliCommandExecuted event', () => {
155-
service.sendCliCommandExecutedEvent(instanceId, { command: 'info' });
155+
service.sendCommandExecutedEvent(instanceId, 'cli', { command: 'info' });
156156

157157
expect(sendEventMethod).toHaveBeenCalledWith(
158-
TelemetryEvents.CliCommandExecuted,
158+
`CLI_${TelemetryEvents.CommandExecuted}`,
159159
{
160160
databaseId: instanceId,
161161
command: 'info',
162162
},
163163
);
164164
});
165165
it('should emit CliCommandExecuted event without additional data', () => {
166-
service.sendCliCommandExecutedEvent(instanceId);
166+
service.sendCommandExecutedEvent(instanceId, 'cli');
167167

168168
expect(sendEventMethod).toHaveBeenCalledWith(
169-
TelemetryEvents.CliCommandExecuted,
169+
`CLI_${TelemetryEvents.CommandExecuted}`,
170+
{
171+
databaseId: instanceId,
172+
},
173+
);
174+
});
175+
it('should emit CliCommandExecuted for undefined namespace', () => {
176+
service.sendCommandExecutedEvent(instanceId, undefined, { command: 'info' });
177+
178+
expect(sendEventMethod).toHaveBeenCalledWith(
179+
`CLI_${TelemetryEvents.CommandExecuted}`,
180+
{
181+
databaseId: instanceId,
182+
command: 'info',
183+
},
184+
);
185+
});
186+
it('should emit WorkbenchCommandExecuted event', () => {
187+
service.sendCommandExecutedEvent(instanceId, 'workbench', { command: 'info' });
188+
189+
expect(sendEventMethod).toHaveBeenCalledWith(
190+
`WORKBENCH_${TelemetryEvents.CommandExecuted}`,
191+
{
192+
databaseId: instanceId,
193+
command: 'info',
194+
},
195+
);
196+
});
197+
it('should emit WorkbenchCommandExecuted event without additional data', () => {
198+
service.sendCommandExecutedEvent(instanceId, 'workbench');
199+
200+
expect(sendEventMethod).toHaveBeenCalledWith(
201+
`WORKBENCH_${TelemetryEvents.CommandExecuted}`,
170202
{
171203
databaseId: instanceId,
172204
},
@@ -176,10 +208,10 @@ describe('CliAnalyticsService', () => {
176208

177209
describe('sendCliCommandErrorEvent', () => {
178210
it('should emit CliCommandError event', () => {
179-
service.sendCliCommandErrorEvent(instanceId, redisReplyError, { data: 'Some data' });
211+
service.sendCommandErrorEvent(instanceId, 'cli', redisReplyError, { data: 'Some data' });
180212

181213
expect(sendEventMethod).toHaveBeenCalledWith(
182-
TelemetryEvents.CliCommandErrorReceived,
214+
`CLI_${TelemetryEvents.CommandErrorReceived}`,
183215
{
184216
databaseId: instanceId,
185217
error: ReplyError.name,
@@ -189,10 +221,10 @@ describe('CliAnalyticsService', () => {
189221
);
190222
});
191223
it('should emit CliCommandError event without additional data', () => {
192-
service.sendCliCommandErrorEvent(instanceId, redisReplyError);
224+
service.sendCommandErrorEvent(instanceId, 'cli', redisReplyError);
193225

194226
expect(sendEventMethod).toHaveBeenCalledWith(
195-
TelemetryEvents.CliCommandErrorReceived,
227+
`CLI_${TelemetryEvents.CommandErrorReceived}`,
196228
{
197229
databaseId: instanceId,
198230
error: ReplyError.name,
@@ -202,10 +234,10 @@ describe('CliAnalyticsService', () => {
202234
});
203235
it('should emit event for custom error', () => {
204236
const error: any = CliParsingError;
205-
service.sendCliCommandErrorEvent(instanceId, error);
237+
service.sendCommandErrorEvent(instanceId, 'cli', error);
206238

207239
expect(sendEventMethod).toHaveBeenCalledWith(
208-
TelemetryEvents.CliCommandErrorReceived,
240+
`CLI_${TelemetryEvents.CommandErrorReceived}`,
209241
{
210242
databaseId: instanceId,
211243
error: CliParsingError.name,
@@ -216,10 +248,10 @@ describe('CliAnalyticsService', () => {
216248

217249
describe('sendCliClientCreationFailedEvent', () => {
218250
it('should emit CliConnectionError event', () => {
219-
service.sendCliConnectionErrorEvent(instanceId, httpException, { data: 'Some data' });
251+
service.sendConnectionErrorEvent(instanceId, 'cli', httpException, { data: 'Some data' });
220252

221253
expect(sendFailedEventMethod).toHaveBeenCalledWith(
222-
TelemetryEvents.CliClientConnectionError,
254+
`CLI_${TelemetryEvents.ClientConnectionError}`,
223255
httpException,
224256
{
225257
databaseId: instanceId,
@@ -228,10 +260,10 @@ describe('CliAnalyticsService', () => {
228260
);
229261
});
230262
it('should emit CliConnectionError event without additional data', () => {
231-
service.sendCliConnectionErrorEvent(instanceId, httpException);
263+
service.sendConnectionErrorEvent(instanceId, 'cli', httpException);
232264

233265
expect(sendFailedEventMethod).toHaveBeenCalledWith(
234-
TelemetryEvents.CliClientConnectionError,
266+
`CLI_${TelemetryEvents.ClientConnectionError}`,
235267
httpException,
236268
{
237269
databaseId: instanceId,
@@ -249,10 +281,10 @@ describe('CliAnalyticsService', () => {
249281
status: CommandExecutionStatus.Success,
250282
};
251283

252-
service.sendCliClusterCommandExecutedEvent(instanceId, nodExecResult, { command: 'sadd' });
284+
service.sendClusterCommandExecutedEvent(instanceId, 'cli', nodExecResult, { command: 'sadd' });
253285

254286
expect(sendEventMethod).toHaveBeenCalledWith(
255-
TelemetryEvents.CliClusterNodeCommandExecuted,
287+
`CLI_${TelemetryEvents.ClusterNodeCommandExecuted}`,
256288
{
257289
databaseId: instanceId,
258290
command: 'sadd',
@@ -268,10 +300,10 @@ describe('CliAnalyticsService', () => {
268300
status: CommandExecutionStatus.Fail,
269301
};
270302

271-
service.sendCliClusterCommandExecutedEvent(instanceId, nodExecResult);
303+
service.sendClusterCommandExecutedEvent(instanceId, 'cli', nodExecResult);
272304

273305
expect(sendEventMethod).toHaveBeenCalledWith(
274-
TelemetryEvents.CliCommandErrorReceived,
306+
`CLI_${TelemetryEvents.CommandErrorReceived}`,
275307
{
276308
databaseId: instanceId,
277309
error: redisReplyError.name,
@@ -288,10 +320,10 @@ describe('CliAnalyticsService', () => {
288320
status: CommandExecutionStatus.Fail,
289321
};
290322

291-
service.sendCliClusterCommandExecutedEvent(instanceId, nodExecResult);
323+
service.sendClusterCommandExecutedEvent(instanceId, 'cli', nodExecResult);
292324

293325
expect(sendEventMethod).toHaveBeenCalledWith(
294-
TelemetryEvents.CliCommandErrorReceived,
326+
`CLI_${TelemetryEvents.CommandErrorReceived}`,
295327
{
296328
databaseId: instanceId,
297329
error: CliParsingError.name,
@@ -305,7 +337,7 @@ describe('CliAnalyticsService', () => {
305337
port: 7002,
306338
status: 'undefined status',
307339
};
308-
service.sendCliClusterCommandExecutedEvent(instanceId, nodExecResult);
340+
service.sendClusterCommandExecutedEvent(instanceId, 'cli', nodExecResult);
309341

310342
expect(sendEventMethod).not.toHaveBeenCalled();
311343
});

0 commit comments

Comments
 (0)