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
2 changes: 1 addition & 1 deletion redisinsight/api/data/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"path": "search",
"modules": ["search"]
"modules": ["search", "searchlight", "ft", "ftl"]
}
]
}
1 change: 1 addition & 0 deletions redisinsight/api/src/__mocks__/bulk-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ export const mockBulkActionsAnalytics = () => ({
sendActionStopped: jest.fn(),
sendActionSucceed: jest.fn(),
sendActionFailed: jest.fn(),
sendImportSamplesUploaded: jest.fn(),
});
1 change: 1 addition & 0 deletions redisinsight/api/src/constants/telemetry-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export enum TelemetryEvents {
BulkActionsStopped = 'BULK_ACTIONS_STOPPED',
BulkActionsSucceed = 'BULK_ACTIONS_SUCCEED',
BulkActionsFailed = 'BULK_ACTIONS_FAILED',
ImportSamplesUploaded = 'IMPORT_SAMPLES_UPLOADED',

// Feature
FeatureFlagConfigUpdated = 'FEATURE_FLAG_CONFIG_UPDATED',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isString } from 'lodash';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { HttpException } from '@nestjs/common';
import { HttpException, Injectable } from '@nestjs/common';
import { AppAnalyticsEvents } from 'src/constants';

@Injectable()
export abstract class TelemetryBaseService {
constructor(
protected readonly eventEmitter: EventEmitter2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,48 @@ describe('BulkActionsAnalytics', () => {
expect(sendFailedEventSpy).not.toHaveBeenCalled();
});
});

describe('sendImportSamplesUploaded', () => {
it('should emit event when action succeed (without progress)', () => {
service.sendImportSamplesUploaded(mockBulkActionOverview);

expect(sendEventSpy).toHaveBeenCalledWith(
TelemetryEvents.ImportSamplesUploaded,
{
databaseId: mockBulkActionOverview.databaseId,
action: mockBulkActionOverview.type,
duration: mockBulkActionOverview.duration,
summary: {
processed: mockBulkActionOverview.summary.processed,
processedRange: '0 - 5 000',
succeed: mockBulkActionOverview.summary.succeed,
succeedRange: '0 - 5 000',
failed: mockBulkActionOverview.summary.failed,
failedRange: '0 - 5 000',
},
},
);
});
it('should emit event when action succeed without filter and summary', () => {
service.sendImportSamplesUploaded({
...mockBulkActionOverview,
filter: undefined,
summary: undefined,
});

expect(sendEventSpy).toHaveBeenCalledWith(
TelemetryEvents.ImportSamplesUploaded,
{
databaseId: mockBulkActionOverview.databaseId,
action: mockBulkActionOverview.type,
duration: mockBulkActionOverview.duration,
summary: {},
},
);
});
it('should not emit event in case of an error and should not fail', () => {
service.sendImportSamplesUploaded(undefined);
expect(sendEventSpy).not.toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,27 @@ export class BulkActionsAnalytics extends TelemetryBaseService {
// continue regardless of error
}
}

sendImportSamplesUploaded(overview: IBulkActionOverview): void {
try {
this.sendEvent(
TelemetryEvents.ImportSamplesUploaded,
{
databaseId: overview.databaseId,
action: overview.type,
duration: overview.duration,
summary: {
processed: overview.summary?.processed,
processedRange: getRangeForNumber(overview.summary?.processed, BULK_ACTIONS_BREAKPOINTS),
succeed: overview.summary?.succeed,
succeedRange: getRangeForNumber(overview.summary?.succeed, BULK_ACTIONS_BREAKPOINTS),
failed: overview.summary?.failed,
failedRange: getRangeForNumber(overview.summary?.failed, BULK_ACTIONS_BREAKPOINTS),
},
},
);
} catch (e) {
// continue regardless of error
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,60 @@ describe('BulkImportService', () => {
expect(spy).toHaveBeenCalledWith(mockClientMetadata, mockCombinedStream);
});

it('should import default data for search module', async () => {
mockedFs.readFileSync.mockImplementationOnce(() => Buffer.from(JSON.stringify({
files: [
{
path: 'some-path',
modules: ['search', 'searchlight', 'ft', 'ftl'],
},
],
})));

mockedFs.createReadStream.mockImplementationOnce(() => new fs.ReadStream());
deviceService.get.mockResolvedValue({
...mockDatabase,
modules: [{
name: 'search',
version: 999999,
semanticVersion: '99.99.99',
}],
});

await service.importDefaultData(mockClientMetadata);

expect(mockCombinedStream.append).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(mockClientMetadata, mockCombinedStream);
});

it('should import default data for searchlight module', async () => {
mockedFs.readFileSync.mockImplementationOnce(() => Buffer.from(JSON.stringify({
files: [
{
path: 'some-path',
modules: ['search', 'searchlight', 'ft', 'ftl'],
},
],
})));

mockedFs.createReadStream.mockImplementationOnce(() => new fs.ReadStream());
deviceService.get.mockResolvedValue({
...mockDatabase,
modules: [{
name: 'searchlight',
version: 999999,
semanticVersion: '99.99.99',
}],
});

await service.importDefaultData(mockClientMetadata);

expect(mockCombinedStream.append).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(mockClientMetadata, mockCombinedStream);
});

it('should import default data for core module only', async () => {
mockedFs.readFileSync.mockImplementationOnce(() => Buffer.from(JSON.stringify(mockDefaultDataManifest)));
mockedFs.createReadStream.mockImplementationOnce(() => new fs.ReadStream());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ export class BulkImportService {
commandsStream.append('\r\n');
});

return this.import(clientMetadata, commandsStream);
const result = await this.import(clientMetadata, commandsStream);

this.analytics.sendImportSamplesUploaded(result);

return result;
} catch (e) {
this.logger.error('Unable to process an import file path from tutorial', e);
throw new InternalServerErrorException(ERROR_MESSAGES.COMMON_DEFAULT_IMPORT_ERROR);
Expand Down