Skip to content

Commit f2d3621

Browse files
author
arthosofteq
authored
Merge pull request #1419 from RedisInsight/be/bugfix/RI-3736-rework_implementation
#RI-3736 rework implementation
2 parents 83e67de + c607512 commit f2d3621

File tree

10 files changed

+77
-74
lines changed

10 files changed

+77
-74
lines changed

redisinsight/api/src/modules/analytics/telemetry.base.service.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ describe('TelemetryBaseService', () => {
3333

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

3838
expect(eventEmitter.emit).toHaveBeenCalledWith(AppAnalyticsEvents.Track, {
3939
event: TelemetryEvents.RedisInstanceAdded,
40-
eventData: { data: 'Some data' },
40+
eventData: { data: 'Some data', command: 'LOWERCASE' },
4141
});
4242
});
4343
it('should emit event with empty event data', () => {
@@ -87,13 +87,18 @@ describe('TelemetryBaseService', () => {
8787
});
8888
});
8989
it('should emit event with additional event data', () => {
90-
service.sendFailedEvent(TelemetryEvents.RedisInstanceAddFailed, httpException, { data: 'Some data' });
90+
service.sendFailedEvent(
91+
TelemetryEvents.RedisInstanceAddFailed,
92+
httpException,
93+
{ data: 'Some data', command: 'lowercase' },
94+
);
9195

9296
expect(eventEmitter.emit).toHaveBeenCalledWith(AppAnalyticsEvents.Track, {
9397
event: TelemetryEvents.RedisInstanceAddFailed,
9498
eventData: {
9599
error: 'Internal Server Error',
96100
data: 'Some data',
101+
command: 'LOWERCASE',
97102
},
98103
});
99104
});

redisinsight/api/src/modules/analytics/telemetry.base.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isString } from 'lodash';
12
import { EventEmitter2 } from '@nestjs/event-emitter';
23
import { HttpException } from '@nestjs/common';
34
import { AppAnalyticsEvents } from 'src/constants';
@@ -13,7 +14,10 @@ export abstract class TelemetryBaseService {
1314
try {
1415
this.eventEmitter.emit(AppAnalyticsEvents.Track, {
1516
event,
16-
eventData,
17+
eventData: {
18+
...eventData,
19+
command: isString(eventData['command']) ? eventData['command'].toUpperCase() : eventData['command'],
20+
},
1721
});
1822
} catch (e) {
1923
// continue regardless of error
@@ -27,6 +31,7 @@ export abstract class TelemetryBaseService {
2731
eventData: {
2832
error: exception.getResponse()['error'] || exception.message,
2933
...eventData,
34+
command: isString(eventData['command']) ? eventData['command'].toUpperCase() : eventData['command'],
3035
},
3136
});
3237
} catch (e) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ describe('CliAnalyticsService', () => {
203203
TelemetryEvents.CliCommandExecuted,
204204
{
205205
databaseId,
206-
command: mockAdditionalData.command.toUpperCase(),
206+
command: mockAdditionalData.command,
207207
commandType: CommandType.Core,
208208
moduleName: 'n/a',
209209
capability: 'string',
@@ -231,7 +231,7 @@ describe('CliAnalyticsService', () => {
231231
{
232232
databaseId,
233233
error: ReplyError.name,
234-
command: mockAdditionalData.command.toUpperCase(),
234+
command: mockAdditionalData.command,
235235
commandType: CommandType.Core,
236236
moduleName: 'n/a',
237237
capability: 'string',
@@ -246,7 +246,7 @@ describe('CliAnalyticsService', () => {
246246
{
247247
databaseId,
248248
error: ReplyError.name,
249-
command: 'sadd'.toUpperCase(),
249+
command: 'sadd',
250250
},
251251
);
252252
});
@@ -259,7 +259,7 @@ describe('CliAnalyticsService', () => {
259259
{
260260
databaseId,
261261
error: CommandParsingError.name,
262-
command: mockAdditionalData.command.toUpperCase(),
262+
command: mockAdditionalData.command,
263263
commandType: CommandType.Core,
264264
moduleName: 'n/a',
265265
capability: 'string',
@@ -312,7 +312,7 @@ describe('CliAnalyticsService', () => {
312312
TelemetryEvents.CliClusterNodeCommandExecuted,
313313
{
314314
databaseId,
315-
command: mockAdditionalData.command.toUpperCase(),
315+
command: mockAdditionalData.command,
316316
commandType: CommandType.Core,
317317
moduleName: 'n/a',
318318
capability: 'string',
@@ -335,7 +335,7 @@ describe('CliAnalyticsService', () => {
335335
{
336336
databaseId,
337337
error: redisReplyError.name,
338-
command: 'sadd'.toUpperCase(),
338+
command: 'sadd',
339339
},
340340
);
341341
});

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export class CliAnalyticsService extends CommandTelemetryBaseService {
8888
databaseId,
8989
...(await this.getCommandAdditionalInfo(additionalData['command'])),
9090
...additionalData,
91-
command: additionalData['command']?.toUpperCase() || undefined,
9291
},
9392
);
9493
} catch (e) {
@@ -102,15 +101,14 @@ export class CliAnalyticsService extends CommandTelemetryBaseService {
102101
additionalData: object = {},
103102
): Promise<void> {
104103
try {
105-
const commandFromError = error?.command?.name?.toUpperCase() || undefined;
106104
this.sendEvent(
107105
TelemetryEvents.CliCommandErrorReceived,
108106
{
109107
databaseId,
110108
error: error?.name,
109+
command: error?.command?.name,
111110
...(await this.getCommandAdditionalInfo(additionalData['command'])),
112111
...additionalData,
113-
command: additionalData['command']?.toUpperCase() || commandFromError,
114112
},
115113
);
116114
} catch (e) {
@@ -132,20 +130,18 @@ export class CliAnalyticsService extends CommandTelemetryBaseService {
132130
databaseId,
133131
...(await this.getCommandAdditionalInfo(additionalData['command'])),
134132
...additionalData,
135-
command: additionalData['command']?.toUpperCase() || undefined,
136133
},
137134
);
138135
}
139136
if (status === CommandExecutionStatus.Fail) {
140-
const commandFromError = error?.command?.name?.toUpperCase() || undefined;
141137
this.sendEvent(
142138
TelemetryEvents.CliCommandErrorReceived,
143139
{
144140
databaseId,
145141
error: error.name,
142+
command: error?.command?.name,
146143
...(await this.getCommandAdditionalInfo(additionalData['command'])),
147144
...additionalData,
148-
command: additionalData['command']?.toUpperCase() || commandFromError,
149145
},
150146
);
151147
}

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ describe('CliBusinessService', () => {
257257
expect(analyticsService.sendCommandExecutedEvent).toHaveBeenCalledWith(
258258
mockClientOptions.instanceId,
259259
{
260-
command: 'memory'.toUpperCase(),
260+
command: 'memory',
261261
outputFormat: CliOutputFormatterTypes.Raw,
262262
},
263263
);
@@ -283,7 +283,7 @@ describe('CliBusinessService', () => {
283283
expect(analyticsService.sendCommandExecutedEvent).toHaveBeenCalledWith(
284284
mockClientOptions.instanceId,
285285
{
286-
command: 'memory'.toUpperCase(),
286+
command: 'memory',
287287
outputFormat: CliOutputFormatterTypes.Raw,
288288
},
289289
);
@@ -307,7 +307,7 @@ describe('CliBusinessService', () => {
307307
ERROR_MESSAGES.CLI_COMMAND_NOT_SUPPORTED(command.toUpperCase()),
308308
),
309309
{
310-
command: 'script'.toUpperCase(),
310+
command: 'script',
311311
outputFormat: CliOutputFormatterTypes.Raw,
312312
},
313313
);
@@ -355,7 +355,7 @@ describe('CliBusinessService', () => {
355355
mockClientOptions.instanceId,
356356
replyError,
357357
{
358-
command: 'get'.toUpperCase(),
358+
command: 'get',
359359
outputFormat: CliOutputFormatterTypes.Raw,
360360
},
361361
);
@@ -374,7 +374,7 @@ describe('CliBusinessService', () => {
374374
mockClientOptions.instanceId,
375375
new Error(mockENotFoundMessage),
376376
{
377-
command: 'get'.toUpperCase(),
377+
command: 'get',
378378
outputFormat: CliOutputFormatterTypes.Raw,
379379
},
380380
);
@@ -394,7 +394,7 @@ describe('CliBusinessService', () => {
394394
mockClientOptions.instanceId,
395395
new KeytarUnavailableException(),
396396
{
397-
command: 'get'.toUpperCase(),
397+
command: 'get',
398398
outputFormat: CliOutputFormatterTypes.Raw,
399399
},
400400
);
@@ -416,7 +416,7 @@ describe('CliBusinessService', () => {
416416
expect(analyticsService.sendCommandExecutedEvent).toHaveBeenCalledWith(
417417
mockClientOptions.instanceId,
418418
{
419-
command: 'info'.toUpperCase(),
419+
command: 'info',
420420
outputFormat: CliOutputFormatterTypes.Raw,
421421
},
422422
);
@@ -491,7 +491,7 @@ describe('CliBusinessService', () => {
491491
...mockNode,
492492
},
493493
{
494-
command: 'memory'.toUpperCase(),
494+
command: 'memory',
495495
outputFormat: CliOutputFormatterTypes.Raw,
496496
},
497497
);
@@ -535,7 +535,7 @@ describe('CliBusinessService', () => {
535535
...mockNode,
536536
},
537537
{
538-
command: 'info'.toUpperCase(),
538+
command: 'info',
539539
outputFormat: CliOutputFormatterTypes.Raw,
540540
},
541541
);
@@ -565,7 +565,7 @@ describe('CliBusinessService', () => {
565565
command.toUpperCase(),
566566
)),
567567
{
568-
command: 'script'.toUpperCase(),
568+
command: 'script',
569569
outputFormat: CliOutputFormatterTypes.Raw,
570570
},
571571
);
@@ -699,7 +699,7 @@ describe('CliBusinessService', () => {
699699
status: CommandExecutionStatus.Success,
700700
},
701701
{
702-
command: 'memory'.toUpperCase(),
702+
command: 'memory',
703703
outputFormat: CliOutputFormatterTypes.Raw,
704704
},
705705
);
@@ -740,7 +740,7 @@ describe('CliBusinessService', () => {
740740
status: CommandExecutionStatus.Success,
741741
},
742742
{
743-
command: 'info'.toUpperCase(),
743+
command: 'info',
744744
outputFormat: CliOutputFormatterTypes.Raw,
745745
},
746746
);
@@ -786,7 +786,7 @@ describe('CliBusinessService', () => {
786786
status: CommandExecutionStatus.Success,
787787
},
788788
{
789-
command: 'set'.toUpperCase(),
789+
command: 'set',
790790
outputFormat: CliOutputFormatterTypes.Raw,
791791
},
792792
);
@@ -831,7 +831,7 @@ describe('CliBusinessService', () => {
831831
status: CommandExecutionStatus.Success,
832832
},
833833
{
834-
command: 'set'.toUpperCase(),
834+
command: 'set',
835835
outputFormat: CliOutputFormatterTypes.Text,
836836
},
837837
);
@@ -868,7 +868,7 @@ describe('CliBusinessService', () => {
868868
status: CommandExecutionStatus.Fail,
869869
},
870870
{
871-
command: 'set'.toUpperCase(),
871+
command: 'set',
872872
outputFormat: CliOutputFormatterTypes.Raw,
873873
},
874874
);
@@ -896,7 +896,7 @@ describe('CliBusinessService', () => {
896896
command.toUpperCase(),
897897
)),
898898
{
899-
command: 'script'.toUpperCase(),
899+
command: 'script',
900900
outputFormat: CliOutputFormatterTypes.Raw,
901901
},
902902
);
@@ -945,7 +945,7 @@ describe('CliBusinessService', () => {
945945
mockClientOptions.instanceId,
946946
new WrongDatabaseTypeError(ERROR_MESSAGES.WRONG_DATABASE_TYPE),
947947
{
948-
command: 'get'.toUpperCase(),
948+
command: 'get',
949949
outputFormat: CliOutputFormatterTypes.Raw,
950950
},
951951
);
@@ -975,7 +975,7 @@ describe('CliBusinessService', () => {
975975
ERROR_MESSAGES.CLUSTER_NODE_NOT_FOUND('127.0.0.1:7002'),
976976
),
977977
{
978-
command: 'get'.toUpperCase(),
978+
command: 'get',
979979
outputFormat: CliOutputFormatterTypes.Raw,
980980
},
981981
);
@@ -999,7 +999,7 @@ describe('CliBusinessService', () => {
999999
mockClientOptions.instanceId,
10001000
new Error(mockENotFoundMessage),
10011001
{
1002-
command: 'get'.toUpperCase(),
1002+
command: 'get',
10031003
outputFormat: CliOutputFormatterTypes.Raw,
10041004
},
10051005
);
@@ -1023,7 +1023,7 @@ describe('CliBusinessService', () => {
10231023
mockClientOptions.instanceId,
10241024
new KeytarUnavailableException(),
10251025
{
1026-
command: 'get'.toUpperCase(),
1026+
command: 'get',
10271027
outputFormat: CliOutputFormatterTypes.Raw,
10281028
},
10291029
);

0 commit comments

Comments
 (0)