Skip to content

Commit aa5d267

Browse files
Merge pull request #50 from RedisInsight/improve/RI-1608_update-databases-events
Improve/ Databases events
2 parents 68a91ef + 21be64f commit aa5d267

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

redisinsight/api/src/__mocks__/analytics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const mockInstancesAnalyticsService = () => ({
2+
sendInstanceListReceivedEvent: jest.fn(),
23
sendInstanceAddedEvent: jest.fn(),
34
sendInstanceAddFailedEvent: jest.fn(),
45
sendInstanceEditedEvent: jest.fn(),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export enum TelemetryEvents {
1111
RedisInstanceDeleted = 'CONFIG_DATABASES_DATABASE_DELETED',
1212
RedisInstanceEditedByUser = 'CONFIG_DATABASES_DATABASE_EDITED_BY_USER',
1313
RedisInstanceConnectionFailed = 'DATABASE_CONNECTION_FAILED',
14+
RedisInstanceListReceived = 'CONFIG_DATABASES_DATABASE_LIST_DISPLAYED',
1415

1516
// Events for autodiscovery flows
1617
REClusterDiscoverySucceed = 'CONFIG_DATABASES_RE_CLUSTER_AUTODISCOVERY_SUCCEEDED',

redisinsight/api/src/modules/shared/services/instances-business/instances-analytics.service.spec.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,51 @@ describe('InstancesAnalytics', () => {
5353
);
5454
});
5555

56+
describe('sendInstanceListReceivedEvent', () => {
57+
const instance = mockDatabaseInstanceDto;
58+
it('should emit event with one db in the list', () => {
59+
service.sendInstanceListReceivedEvent([instance]);
60+
61+
expect(sendEventMethod).toHaveBeenCalledWith(
62+
TelemetryEvents.RedisInstanceListReceived,
63+
{
64+
numberOfDatabases: 1,
65+
},
66+
);
67+
});
68+
it('should emit event with several dbs in the list', () => {
69+
service.sendInstanceListReceivedEvent([instance, instance, instance]);
70+
71+
expect(sendEventMethod).toHaveBeenCalledWith(
72+
TelemetryEvents.RedisInstanceListReceived,
73+
{
74+
numberOfDatabases: 3,
75+
},
76+
);
77+
});
78+
it('should emit event with several empty in the list', () => {
79+
service.sendInstanceListReceivedEvent([]);
80+
81+
expect(sendEventMethod).toHaveBeenCalledWith(
82+
TelemetryEvents.RedisInstanceListReceived,
83+
{
84+
numberOfDatabases: 0,
85+
},
86+
);
87+
});
88+
it('should emit event with additional data', () => {
89+
service.sendInstanceListReceivedEvent([], { data: 'data' });
90+
91+
expect(sendEventMethod).toHaveBeenCalledWith(
92+
TelemetryEvents.RedisInstanceListReceived,
93+
{
94+
numberOfDatabases: 0,
95+
data: 'data',
96+
},
97+
);
98+
});
99+
});
100+
56101
describe('sendInstanceAddedEvent', () => {
57102
it('should emit event with enabled tls', () => {
58103
const instance = mockDatabaseInstanceDto;
@@ -72,6 +117,8 @@ describe('InstancesAnalytics', () => {
72117
numberOfKeysRange: '0 - 500 000',
73118
totalMemory: mockRedisGeneralInfo.usedMemory,
74119
numberedDatabases: mockRedisGeneralInfo.databases,
120+
numberOfModules: 0,
121+
modules: [],
75122
},
76123
);
77124
});
@@ -96,11 +143,13 @@ describe('InstancesAnalytics', () => {
96143
numberOfKeysRange: '0 - 500 000',
97144
totalMemory: mockRedisGeneralInfo.usedMemory,
98145
numberedDatabases: mockRedisGeneralInfo.databases,
146+
numberOfModules: 0,
147+
modules: [],
99148
},
100149
);
101150
});
102151
it('should emit event without additional info', () => {
103-
const instance = mockDatabaseInstanceDto;
152+
const instance = { ...mockDatabaseInstanceDto, modules: [{ name: 'search', version: 20000 }] };
104153
service.sendInstanceAddedEvent(instance, {
105154
version: mockRedisGeneralInfo.version,
106155
});
@@ -119,6 +168,8 @@ describe('InstancesAnalytics', () => {
119168
numberOfKeysRange: undefined,
120169
totalMemory: undefined,
121170
numberedDatabases: undefined,
171+
numberOfModules: 1,
172+
modules: [{ name: 'search', version: 20000 }],
122173
},
123174
);
124175
});

redisinsight/api/src/modules/shared/services/instances-business/instances-analytics.service.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ export class InstancesAnalyticsService extends TelemetryBaseService {
1212
super(eventEmitter);
1313
}
1414

15+
sendInstanceListReceivedEvent(
16+
instances: DatabaseInstanceResponse[],
17+
additionalData: object = {},
18+
): void {
19+
try {
20+
this.sendEvent(
21+
TelemetryEvents.RedisInstanceListReceived,
22+
{
23+
numberOfDatabases: instances.length,
24+
...additionalData,
25+
},
26+
);
27+
} catch (e) {
28+
// continue regardless of error
29+
}
30+
}
31+
1532
sendInstanceAddedEvent(
1633
instance: DatabaseInstanceResponse,
1734
additionalInfo: RedisDatabaseInfoResponse,
@@ -35,6 +52,8 @@ export class InstancesAnalyticsService extends TelemetryBaseService {
3552
numberOfKeysRange: getRangeForNumber(additionalInfo.totalKeys, TOTAL_KEYS_BREAKPOINTS),
3653
totalMemory: additionalInfo.usedMemory,
3754
numberedDatabases: additionalInfo.databases,
55+
numberOfModules: instance.modules.length,
56+
modules: instance.modules,
3857
},
3958
);
4059
} catch (e) {

redisinsight/api/src/modules/shared/services/instances-business/instances-business.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ export class InstancesBusinessService {
9292

9393
async getAll(): Promise<DatabaseInstanceResponse[]> {
9494
try {
95-
return (await this.databasesProvider.getAll()).map(convertEntityToDto);
95+
const result = (await this.databasesProvider.getAll()).map(convertEntityToDto);
96+
this.instancesAnalyticsService.sendInstanceListReceivedEvent(result);
97+
return result;
9698
} catch (error) {
9799
this.logger.error('Failed to get database instance list.', error);
98100
throw new InternalServerErrorException();

0 commit comments

Comments
 (0)