Skip to content

Commit a56a3ba

Browse files
author
arthosofteq
committed
add telemetry events for default data upload
1 parent 3b4bd6d commit a56a3ba

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

redisinsight/api/src/__mocks__/bulk-actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,5 @@ export const mockBulkActionsAnalytics = () => ({
9292
sendActionStopped: jest.fn(),
9393
sendActionSucceed: jest.fn(),
9494
sendActionFailed: jest.fn(),
95+
sendImportSamplesUploaded: jest.fn(),
9596
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export enum TelemetryEvents {
7878
BulkActionsStopped = 'BULK_ACTIONS_STOPPED',
7979
BulkActionsSucceed = 'BULK_ACTIONS_SUCCEED',
8080
BulkActionsFailed = 'BULK_ACTIONS_FAILED',
81+
ImportSamplesUploaded = 'IMPORT_SAMPLES_UPLOADED',
8182

8283
// Feature
8384
FeatureFlagConfigUpdated = 'FEATURE_FLAG_CONFIG_UPDATED',

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,48 @@ describe('BulkActionsAnalytics', () => {
223223
expect(sendFailedEventSpy).not.toHaveBeenCalled();
224224
});
225225
});
226+
227+
describe('sendImportSamplesUploaded', () => {
228+
it('should emit event when action succeed (without progress)', () => {
229+
service.sendImportSamplesUploaded(mockBulkActionOverview);
230+
231+
expect(sendEventSpy).toHaveBeenCalledWith(
232+
TelemetryEvents.ImportSamplesUploaded,
233+
{
234+
databaseId: mockBulkActionOverview.databaseId,
235+
action: mockBulkActionOverview.type,
236+
duration: mockBulkActionOverview.duration,
237+
summary: {
238+
processed: mockBulkActionOverview.summary.processed,
239+
processedRange: '0 - 5 000',
240+
succeed: mockBulkActionOverview.summary.succeed,
241+
succeedRange: '0 - 5 000',
242+
failed: mockBulkActionOverview.summary.failed,
243+
failedRange: '0 - 5 000',
244+
},
245+
},
246+
);
247+
});
248+
it('should emit event when action succeed without filter and summary', () => {
249+
service.sendImportSamplesUploaded({
250+
...mockBulkActionOverview,
251+
filter: undefined,
252+
summary: undefined,
253+
});
254+
255+
expect(sendEventSpy).toHaveBeenCalledWith(
256+
TelemetryEvents.ImportSamplesUploaded,
257+
{
258+
databaseId: mockBulkActionOverview.databaseId,
259+
action: mockBulkActionOverview.type,
260+
duration: mockBulkActionOverview.duration,
261+
summary: {},
262+
},
263+
);
264+
});
265+
it('should not emit event in case of an error and should not fail', () => {
266+
service.sendImportSamplesUploaded(undefined);
267+
expect(sendEventSpy).not.toHaveBeenCalled();
268+
});
269+
});
226270
});

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,27 @@ export class BulkActionsAnalytics extends TelemetryBaseService {
105105
// continue regardless of error
106106
}
107107
}
108+
109+
sendImportSamplesUploaded(overview: IBulkActionOverview): void {
110+
try {
111+
this.sendEvent(
112+
TelemetryEvents.ImportSamplesUploaded,
113+
{
114+
databaseId: overview.databaseId,
115+
action: overview.type,
116+
duration: overview.duration,
117+
summary: {
118+
processed: overview.summary?.processed,
119+
processedRange: getRangeForNumber(overview.summary?.processed, BULK_ACTIONS_BREAKPOINTS),
120+
succeed: overview.summary?.succeed,
121+
succeedRange: getRangeForNumber(overview.summary?.succeed, BULK_ACTIONS_BREAKPOINTS),
122+
failed: overview.summary?.failed,
123+
failedRange: getRangeForNumber(overview.summary?.failed, BULK_ACTIONS_BREAKPOINTS),
124+
},
125+
},
126+
);
127+
} catch (e) {
128+
// continue regardless of error
129+
}
130+
}
108131
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ export class BulkImportService {
212212
commandsStream.append('\r\n');
213213
});
214214

215-
return this.import(clientMetadata, commandsStream);
215+
const result = await this.import(clientMetadata, commandsStream);
216+
217+
this.analytics.sendImportSamplesUploaded(result);
218+
219+
return result;
216220
} catch (e) {
217221
this.logger.error('Unable to process an import file path from tutorial', e);
218222
throw new InternalServerErrorException(ERROR_MESSAGES.COMMON_DEFAULT_IMPORT_ERROR);

0 commit comments

Comments
 (0)