Skip to content

Commit 0f2153b

Browse files
#RI-4538-4539-4540 - fix telemetry in bulk actions (#2113)
* #RI-4538-4539-4540 - fix telemetry in bulk actions
1 parent 5ab3e4b commit 0f2153b

File tree

12 files changed

+41
-22
lines changed

12 files changed

+41
-22
lines changed

redisinsight/api/src/modules/bulk-actions/bulk-actions-analytics.service.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class BulkActionsAnalyticsService extends TelemetryBaseService {
3131
TelemetryEvents.BulkActionsStarted,
3232
{
3333
databaseId: overview.databaseId,
34-
type: overview.type,
34+
action: overview.type,
3535
duration: overview.duration,
3636
filter: {
3737
match: overview.filter?.match === '*' ? '*' : 'PATTERN',
@@ -56,7 +56,7 @@ export class BulkActionsAnalyticsService extends TelemetryBaseService {
5656
TelemetryEvents.BulkActionsStopped,
5757
{
5858
databaseId: overview.databaseId,
59-
type: overview.type,
59+
action: overview.type,
6060
duration: overview.duration,
6161
filter: {
6262
match: overview.filter?.match === '*' ? '*' : 'PATTERN',
@@ -89,18 +89,12 @@ export class BulkActionsAnalyticsService extends TelemetryBaseService {
8989
TelemetryEvents.BulkActionsSucceed,
9090
{
9191
databaseId: overview.databaseId,
92-
type: overview.type,
92+
action: overview.type,
9393
duration: overview.duration,
9494
filter: {
9595
match: overview.filter?.match === '*' ? '*' : 'PATTERN',
9696
type: overview.filter?.type,
9797
},
98-
progress: {
99-
scanned: overview.progress?.scanned,
100-
scannedRange: getRangeForNumber(overview.progress?.scanned, BULK_ACTIONS_BREAKPOINTS),
101-
total: overview.progress?.total,
102-
totalRange: getRangeForNumber(overview.progress?.total, BULK_ACTIONS_BREAKPOINTS),
103-
},
10498
summary: {
10599
processed: overview.summary?.processed,
106100
processedRange: getRangeForNumber(overview.summary?.processed, BULK_ACTIONS_BREAKPOINTS),
@@ -122,7 +116,7 @@ export class BulkActionsAnalyticsService extends TelemetryBaseService {
122116
TelemetryEvents.BulkActionsFailed,
123117
{
124118
databaseId: overview.databaseId,
125-
type: overview.type,
119+
action: overview.type,
126120
error,
127121
},
128122
);

redisinsight/api/src/modules/bulk-actions/bulk-actions.service.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ mockBulkAction['getOverview'] = jest.fn().mockReturnValue(mockOverview);
5353
describe('BulkActionsService', () => {
5454
let service: BulkActionsService;
5555
let bulkActionProvider: MockType<BulkActionsProvider>;
56+
let analyticsService: MockType<BulkActionsAnalyticsService>;
5657

5758
beforeEach(async () => {
5859
jest.clearAllMocks();
@@ -83,12 +84,14 @@ describe('BulkActionsService', () => {
8384

8485
service = module.get(BulkActionsService);
8586
bulkActionProvider = module.get(BulkActionsProvider);
87+
analyticsService = module.get(BulkActionsAnalyticsService);
8688
});
8789

8890
describe('create', () => {
8991
it('should create and return overview', async () => {
9092
expect(await service.create(mockCreateBulkActionDto, mockSocket1)).toEqual(mockOverview);
9193
expect(bulkActionProvider.create).toHaveBeenCalledTimes(1);
94+
expect(analyticsService.sendActionStarted).toHaveBeenCalledTimes(1);
9295
});
9396
});
9497
describe('get', () => {

redisinsight/api/src/modules/bulk-actions/bulk-actions.service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ export class BulkActionsService {
2828

2929
async abort(dto: BulkActionIdDto) {
3030
const bulkAction = await this.bulkActionsProvider.abort(dto.id);
31-
const overview = bulkAction.getOverview();
32-
33-
this.analyticsService.sendActionStopped(overview);
3431

35-
return overview;
32+
return bulkAction.getOverview();
3633
}
3734

3835
disconnect(socketId: string) {

redisinsight/api/src/modules/bulk-actions/models/bulk-action.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,12 @@ describe('AbstractBulkActionSimpleRunner', () => {
324324
let sendOverviewSpy;
325325
let sendActionSucceedSpy;
326326
let sendActionFailedSpy;
327+
let sendActionStoppedSpy;
327328

328329
beforeEach(() => {
329330
sendActionSucceedSpy = jest.spyOn(bulkAction['analyticsService'], 'sendActionSucceed');
330331
sendActionFailedSpy = jest.spyOn(bulkAction['analyticsService'], 'sendActionFailed');
332+
sendActionStoppedSpy = jest.spyOn(bulkAction['analyticsService'], 'sendActionStopped');
331333
sendOverviewSpy = jest.spyOn(bulkAction, 'sendOverview');
332334
});
333335

@@ -353,6 +355,7 @@ describe('AbstractBulkActionSimpleRunner', () => {
353355

354356
expect(sendOverviewSpy).toHaveBeenCalledTimes(1);
355357
expect(sendActionFailedSpy).not.toHaveBeenCalled();
358+
expect(sendActionStoppedSpy).not.toHaveBeenCalled();
356359
expect(sendActionSucceedSpy).toHaveBeenCalledWith(mockOverview);
357360
});
358361

@@ -366,6 +369,7 @@ describe('AbstractBulkActionSimpleRunner', () => {
366369

367370
expect(sendOverviewSpy).toHaveBeenCalledTimes(1);
368371
expect(sendActionSucceedSpy).not.toHaveBeenCalled();
372+
expect(sendActionStoppedSpy).not.toHaveBeenCalled();
369373
expect(sendActionFailedSpy).toHaveBeenCalledWith(
370374
{
371375
...mockOverview,
@@ -374,6 +378,24 @@ describe('AbstractBulkActionSimpleRunner', () => {
374378
'some error',
375379
);
376380
});
381+
382+
it('Should call sendActionStopped', () => {
383+
mockSocket.emit.mockReturnValue();
384+
385+
bulkAction['status'] = BulkActionStatus.Aborted;
386+
387+
bulkAction.sendOverview();
388+
389+
expect(sendOverviewSpy).toHaveBeenCalledTimes(1);
390+
expect(sendActionSucceedSpy).not.toHaveBeenCalled();
391+
expect(sendActionFailedSpy).not.toHaveBeenCalled();
392+
expect(sendActionStoppedSpy).toHaveBeenCalledWith(
393+
{
394+
...mockOverview,
395+
status: 'aborted',
396+
},
397+
);
398+
});
377399
});
378400
describe('Other', () => {
379401
it('getters', () => {

redisinsight/api/src/modules/bulk-actions/models/bulk-action.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ export class BulkAction implements IBulkAction {
214214
if (overview.status === BulkActionStatus.Failed) {
215215
this.analyticsService.sendActionFailed(overview, this.error);
216216
}
217+
if (overview.status === BulkActionStatus.Aborted) {
218+
this.analyticsService.sendActionStopped(overview);
219+
}
217220
try {
218221
this.socket.emit('overview', overview);
219222
} catch (e) {

redisinsight/ui/src/constants/bulkActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export enum BulkActionsServerEvent {
88

99
export enum BulkActionsType {
1010
Delete = 'delete',
11-
Upload = 'upload',
11+
Import = 'import',
1212
}
1313

1414
export enum BulkActionsStatus {

redisinsight/ui/src/pages/browser/components/bulk-actions/BulkActions.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('BulkActions', () => {
112112
fireEvent.click(screen.getByTestId('bulk-action-tab-upload'))
113113
})
114114

115-
const expectedActions = [setBulkActionType(BulkActionsType.Upload)]
115+
const expectedActions = [setBulkActionType(BulkActionsType.Import)]
116116
expect(store.getActions()).toEqual(expectedActions)
117117
})
118118

redisinsight/ui/src/pages/browser/components/bulk-actions/BulkActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const BulkActions = (props: Props) => {
125125
<div className="eui-yScroll">
126126
<div className={styles.contentActions} data-testid="bulk-actions-content">
127127
<BulkActionsTabs onChangeType={handleChangeType} />
128-
{type === BulkActionsType.Upload && (<BulkUpload onCancel={closePanel} />)}
128+
{type === BulkActionsType.Import && (<BulkUpload onCancel={closePanel} />)}
129129
{type === BulkActionsType.Delete && (<BulkDelete onCancel={closePanel} />)}
130130
</div>
131131
</div>

redisinsight/ui/src/pages/browser/components/bulk-actions/BulkActionsTabs/BulkActionsTabs.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('BulkActionsTabs', () => {
4747
event: TelemetryEvent.BULK_ACTIONS_OPENED,
4848
eventData: {
4949
databaseId: '',
50-
action: BulkActionsType.Upload,
50+
action: BulkActionsType.Import,
5151
}
5252
});
5353

redisinsight/ui/src/pages/browser/components/bulk-actions/BulkUpload/BulkUpload.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('BulkUpload', () => {
131131
expect(sendEventTelemetry).toBeCalledWith({
132132
event: TelemetryEvent.BULK_ACTIONS_WARNING,
133133
eventData: {
134-
action: BulkActionsType.Upload,
134+
action: BulkActionsType.Import,
135135
databaseId: ''
136136
}
137137
})

0 commit comments

Comments
 (0)