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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class BulkActionsAnalyticsService extends TelemetryBaseService {
TelemetryEvents.BulkActionsStarted,
{
databaseId: overview.databaseId,
type: overview.type,
action: overview.type,
duration: overview.duration,
filter: {
match: overview.filter?.match === '*' ? '*' : 'PATTERN',
Expand All @@ -56,7 +56,7 @@ export class BulkActionsAnalyticsService extends TelemetryBaseService {
TelemetryEvents.BulkActionsStopped,
{
databaseId: overview.databaseId,
type: overview.type,
action: overview.type,
duration: overview.duration,
filter: {
match: overview.filter?.match === '*' ? '*' : 'PATTERN',
Expand Down Expand Up @@ -89,18 +89,12 @@ export class BulkActionsAnalyticsService extends TelemetryBaseService {
TelemetryEvents.BulkActionsSucceed,
{
databaseId: overview.databaseId,
type: overview.type,
action: overview.type,
duration: overview.duration,
filter: {
match: overview.filter?.match === '*' ? '*' : 'PATTERN',
type: overview.filter?.type,
},
progress: {
scanned: overview.progress?.scanned,
scannedRange: getRangeForNumber(overview.progress?.scanned, BULK_ACTIONS_BREAKPOINTS),
total: overview.progress?.total,
totalRange: getRangeForNumber(overview.progress?.total, BULK_ACTIONS_BREAKPOINTS),
},
summary: {
processed: overview.summary?.processed,
processedRange: getRangeForNumber(overview.summary?.processed, BULK_ACTIONS_BREAKPOINTS),
Expand All @@ -122,7 +116,7 @@ export class BulkActionsAnalyticsService extends TelemetryBaseService {
TelemetryEvents.BulkActionsFailed,
{
databaseId: overview.databaseId,
type: overview.type,
action: overview.type,
error,
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ mockBulkAction['getOverview'] = jest.fn().mockReturnValue(mockOverview);
describe('BulkActionsService', () => {
let service: BulkActionsService;
let bulkActionProvider: MockType<BulkActionsProvider>;
let analyticsService: MockType<BulkActionsAnalyticsService>;

beforeEach(async () => {
jest.clearAllMocks();
Expand Down Expand Up @@ -83,12 +84,14 @@ describe('BulkActionsService', () => {

service = module.get(BulkActionsService);
bulkActionProvider = module.get(BulkActionsProvider);
analyticsService = module.get(BulkActionsAnalyticsService);
});

describe('create', () => {
it('should create and return overview', async () => {
expect(await service.create(mockCreateBulkActionDto, mockSocket1)).toEqual(mockOverview);
expect(bulkActionProvider.create).toHaveBeenCalledTimes(1);
expect(analyticsService.sendActionStarted).toHaveBeenCalledTimes(1);
});
});
describe('get', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ export class BulkActionsService {

async abort(dto: BulkActionIdDto) {
const bulkAction = await this.bulkActionsProvider.abort(dto.id);
const overview = bulkAction.getOverview();

this.analyticsService.sendActionStopped(overview);

return overview;
return bulkAction.getOverview();
}

disconnect(socketId: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,12 @@ describe('AbstractBulkActionSimpleRunner', () => {
let sendOverviewSpy;
let sendActionSucceedSpy;
let sendActionFailedSpy;
let sendActionStoppedSpy;

beforeEach(() => {
sendActionSucceedSpy = jest.spyOn(bulkAction['analyticsService'], 'sendActionSucceed');
sendActionFailedSpy = jest.spyOn(bulkAction['analyticsService'], 'sendActionFailed');
sendActionStoppedSpy = jest.spyOn(bulkAction['analyticsService'], 'sendActionStopped');
sendOverviewSpy = jest.spyOn(bulkAction, 'sendOverview');
});

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

expect(sendOverviewSpy).toHaveBeenCalledTimes(1);
expect(sendActionFailedSpy).not.toHaveBeenCalled();
expect(sendActionStoppedSpy).not.toHaveBeenCalled();
expect(sendActionSucceedSpy).toHaveBeenCalledWith(mockOverview);
});

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

expect(sendOverviewSpy).toHaveBeenCalledTimes(1);
expect(sendActionSucceedSpy).not.toHaveBeenCalled();
expect(sendActionStoppedSpy).not.toHaveBeenCalled();
expect(sendActionFailedSpy).toHaveBeenCalledWith(
{
...mockOverview,
Expand All @@ -374,6 +378,24 @@ describe('AbstractBulkActionSimpleRunner', () => {
'some error',
);
});

it('Should call sendActionStopped', () => {
mockSocket.emit.mockReturnValue();

bulkAction['status'] = BulkActionStatus.Aborted;

bulkAction.sendOverview();

expect(sendOverviewSpy).toHaveBeenCalledTimes(1);
expect(sendActionSucceedSpy).not.toHaveBeenCalled();
expect(sendActionFailedSpy).not.toHaveBeenCalled();
expect(sendActionStoppedSpy).toHaveBeenCalledWith(
{
...mockOverview,
status: 'aborted',
},
);
});
});
describe('Other', () => {
it('getters', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ export class BulkAction implements IBulkAction {
if (overview.status === BulkActionStatus.Failed) {
this.analyticsService.sendActionFailed(overview, this.error);
}
if (overview.status === BulkActionStatus.Aborted) {
this.analyticsService.sendActionStopped(overview);
}
try {
this.socket.emit('overview', overview);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion redisinsight/ui/src/constants/bulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export enum BulkActionsServerEvent {

export enum BulkActionsType {
Delete = 'delete',
Upload = 'upload',
Import = 'import',
}

export enum BulkActionsStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('BulkActions', () => {
fireEvent.click(screen.getByTestId('bulk-action-tab-upload'))
})

const expectedActions = [setBulkActionType(BulkActionsType.Upload)]
const expectedActions = [setBulkActionType(BulkActionsType.Import)]
expect(store.getActions()).toEqual(expectedActions)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const BulkActions = (props: Props) => {
<div className="eui-yScroll">
<div className={styles.contentActions} data-testid="bulk-actions-content">
<BulkActionsTabs onChangeType={handleChangeType} />
{type === BulkActionsType.Upload && (<BulkUpload onCancel={closePanel} />)}
{type === BulkActionsType.Import && (<BulkUpload onCancel={closePanel} />)}
{type === BulkActionsType.Delete && (<BulkDelete onCancel={closePanel} />)}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('BulkActionsTabs', () => {
event: TelemetryEvent.BULK_ACTIONS_OPENED,
eventData: {
databaseId: '',
action: BulkActionsType.Upload,
action: BulkActionsType.Import,
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('BulkUpload', () => {
expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.BULK_ACTIONS_WARNING,
eventData: {
action: BulkActionsType.Upload,
action: BulkActionsType.Import,
databaseId: ''
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const BulkUpload = (props: Props) => {
event: TelemetryEvent.BULK_ACTIONS_WARNING,
eventData: {
databaseId: instanceId,
action: BulkActionsType.Upload
action: BulkActionsType.Import
}
})
}
Expand Down Expand Up @@ -135,7 +135,7 @@ const BulkUpload = (props: Props) => {
subTitle={(<div className="truncateText" style={{ paddingTop: 6 }}>{fileName}</div>)}
>
<BulkActionSummary
type={BulkActionsType.Upload}
type={BulkActionsType.Import}
succeed={succeed}
processed={processed}
failed={failed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const bulkActionsTypeTabs: BulkActionsTabs[] = [
label: <><EuiIcon type="trash" />Delete Keys</>,
},
{
id: BulkActionsType.Upload,
id: BulkActionsType.Import,
label: <><EuiIcon type={BulkUpload} />Upload Data</>,
},
]