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
1 change: 1 addition & 0 deletions redisinsight/api/src/__mocks__/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const mockInstancesAnalyticsService = () => ({
sendInstanceListReceivedEvent: jest.fn(),
sendInstanceAddedEvent: jest.fn(),
sendInstanceAddFailedEvent: jest.fn(),
sendInstanceEditedEvent: jest.fn(),
Expand Down
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 @@ -11,6 +11,7 @@ export enum TelemetryEvents {
RedisInstanceDeleted = 'CONFIG_DATABASES_DATABASE_DELETED',
RedisInstanceEditedByUser = 'CONFIG_DATABASES_DATABASE_EDITED_BY_USER',
RedisInstanceConnectionFailed = 'DATABASE_CONNECTION_FAILED',
RedisInstanceListReceived = 'CONFIG_DATABASES_DATABASE_LIST_DISPLAYED',

// Events for autodiscovery flows
REClusterDiscoverySucceed = 'CONFIG_DATABASES_RE_CLUSTER_AUTODISCOVERY_SUCCEEDED',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,51 @@ describe('InstancesAnalytics', () => {
);
});

describe('sendInstanceListReceivedEvent', () => {
const instance = mockDatabaseInstanceDto;
it('should emit event with one db in the list', () => {
service.sendInstanceListReceivedEvent([instance]);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.RedisInstanceListReceived,
{
numberOfDatabases: 1,
},
);
});
it('should emit event with several dbs in the list', () => {
service.sendInstanceListReceivedEvent([instance, instance, instance]);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.RedisInstanceListReceived,
{
numberOfDatabases: 3,
},
);
});
it('should emit event with several empty in the list', () => {
service.sendInstanceListReceivedEvent([]);

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.RedisInstanceListReceived,
{
numberOfDatabases: 0,
},
);
});
it('should emit event with additional data', () => {
service.sendInstanceListReceivedEvent([], { data: 'data' });

expect(sendEventMethod).toHaveBeenCalledWith(
TelemetryEvents.RedisInstanceListReceived,
{
numberOfDatabases: 0,
data: 'data',
},
);
});
});

describe('sendInstanceAddedEvent', () => {
it('should emit event with enabled tls', () => {
const instance = mockDatabaseInstanceDto;
Expand All @@ -72,6 +117,8 @@ describe('InstancesAnalytics', () => {
numberOfKeysRange: '0 - 500 000',
totalMemory: mockRedisGeneralInfo.usedMemory,
numberedDatabases: mockRedisGeneralInfo.databases,
numberOfModules: 0,
modules: [],
},
);
});
Expand All @@ -96,11 +143,13 @@ describe('InstancesAnalytics', () => {
numberOfKeysRange: '0 - 500 000',
totalMemory: mockRedisGeneralInfo.usedMemory,
numberedDatabases: mockRedisGeneralInfo.databases,
numberOfModules: 0,
modules: [],
},
);
});
it('should emit event without additional info', () => {
const instance = mockDatabaseInstanceDto;
const instance = { ...mockDatabaseInstanceDto, modules: [{ name: 'search', version: 20000 }] };
service.sendInstanceAddedEvent(instance, {
version: mockRedisGeneralInfo.version,
});
Expand All @@ -119,6 +168,8 @@ describe('InstancesAnalytics', () => {
numberOfKeysRange: undefined,
totalMemory: undefined,
numberedDatabases: undefined,
numberOfModules: 1,
modules: [{ name: 'search', version: 20000 }],
},
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ export class InstancesAnalyticsService extends TelemetryBaseService {
super(eventEmitter);
}

sendInstanceListReceivedEvent(
instances: DatabaseInstanceResponse[],
additionalData: object = {},
): void {
try {
this.sendEvent(
TelemetryEvents.RedisInstanceListReceived,
{
numberOfDatabases: instances.length,
...additionalData,
},
);
} catch (e) {
// continue regardless of error
}
}

sendInstanceAddedEvent(
instance: DatabaseInstanceResponse,
additionalInfo: RedisDatabaseInfoResponse,
Expand All @@ -35,6 +52,8 @@ export class InstancesAnalyticsService extends TelemetryBaseService {
numberOfKeysRange: getRangeForNumber(additionalInfo.totalKeys, TOTAL_KEYS_BREAKPOINTS),
totalMemory: additionalInfo.usedMemory,
numberedDatabases: additionalInfo.databases,
numberOfModules: instance.modules.length,
modules: instance.modules,
},
);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export class InstancesBusinessService {

async getAll(): Promise<DatabaseInstanceResponse[]> {
try {
return (await this.databasesProvider.getAll()).map(convertEntityToDto);
const result = (await this.databasesProvider.getAll()).map(convertEntityToDto);
this.instancesAnalyticsService.sendInstanceListReceivedEvent(result);
return result;
} catch (error) {
this.logger.error('Failed to get database instance list.', error);
throw new InternalServerErrorException();
Expand Down