Skip to content

Commit 5d68ab0

Browse files
author
arthosofteq
authored
Merge pull request #786 from RedisInsight/feature/RI-2524-build_type_for_telemetry
#RI-2524 add build type to all telemetry events
2 parents 95b316d + f8641f0 commit 5d68ab0

File tree

6 files changed

+53
-16
lines changed

6 files changed

+53
-16
lines changed

redisinsight/api/src/modules/core/models/server-provider.interface.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ export enum BuildType {
66
DockerOnPremise = 'DOCKER_ON_PREMISE',
77
}
88

9+
export enum AppType {
10+
RedisStackWeb = 'REDIS_STACK_WEB',
11+
RedisStackApp = 'REDIS_STACK_ELECTRON',
12+
Electron = 'ELECTRON',
13+
Docker = 'DOCKER',
14+
Unknown = 'UNKNOWN',
15+
}
16+
917
export interface IServerProvider {
1018
getInfo(): Promise<GetServerInfoResponse>;
1119
}

redisinsight/api/src/modules/core/providers/server-on-premise/server-on-premise.service.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('ServerOnPremiseService', () => {
9494
expect(eventEmitter.emit).toHaveBeenNthCalledWith(
9595
1,
9696
AppAnalyticsEvents.Initialize,
97-
{ anonymousId: mockServerEntity.id, sessionId },
97+
{ anonymousId: mockServerEntity.id, sessionId, appType: SERVER_CONFIG.buildType },
9898
);
9999
expect(eventEmitter.emit).toHaveBeenNthCalledWith(
100100
2,
@@ -113,7 +113,7 @@ describe('ServerOnPremiseService', () => {
113113
expect(eventEmitter.emit).toHaveBeenNthCalledWith(
114114
1,
115115
AppAnalyticsEvents.Initialize,
116-
{ anonymousId: mockServerEntity.id, sessionId },
116+
{ anonymousId: mockServerEntity.id, sessionId, appType: SERVER_CONFIG.buildType },
117117
);
118118
expect(eventEmitter.emit).toHaveBeenNthCalledWith(
119119
2,
@@ -140,6 +140,7 @@ describe('ServerOnPremiseService', () => {
140140
appVersion: SERVER_CONFIG.appVersion,
141141
osPlatform: process.platform,
142142
buildType: SERVER_CONFIG.buildType,
143+
appType: SERVER_CONFIG.buildType,
143144
encryptionStrategies: [
144145
EncryptionStrategy.PLAIN,
145146
EncryptionStrategy.KEYTAR,

redisinsight/api/src/modules/core/providers/server-on-premise/server-on-premise.service.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import {
2-
Injectable,
3-
InternalServerErrorException,
4-
Logger,
5-
OnApplicationBootstrap,
6-
} from '@nestjs/common';
1+
import { Injectable, InternalServerErrorException, Logger, OnApplicationBootstrap } from '@nestjs/common';
72
import { EventEmitter2 } from '@nestjs/event-emitter';
83
import config from 'src/utils/config';
94
import { AppAnalyticsEvents } from 'src/constants/app-events';
105
import { TelemetryEvents } from 'src/constants/telemetry-events';
116
import { GetServerInfoResponse } from 'src/dto/server.dto';
127
import { ServerRepository } from 'src/modules/core/repositories/server.repository';
13-
import { IServerProvider } from 'src/modules/core/models/server-provider.interface';
8+
import { AppType, BuildType, IServerProvider } from 'src/modules/core/models/server-provider.interface';
149
import { ServerInfoNotFoundException } from 'src/constants/exceptions';
1510
import { EncryptionService } from 'src/modules/core/encryption/encryption.service';
1611

@@ -49,7 +44,11 @@ implements OnApplicationBootstrap, IServerProvider {
4944
// Create default server info on first application launch
5045
serverInfo = this.repository.create({});
5146
await this.repository.save(serverInfo);
52-
this.eventEmitter.emit(AppAnalyticsEvents.Initialize, { anonymousId: serverInfo.id, sessionId: this.sessionId });
47+
this.eventEmitter.emit(AppAnalyticsEvents.Initialize, {
48+
anonymousId: serverInfo.id,
49+
sessionId: this.sessionId,
50+
appType: this.getAppType(SERVER_CONFIG.buildType),
51+
});
5352
this.eventEmitter.emit(AppAnalyticsEvents.Track, {
5453
event: TelemetryEvents.ApplicationFirstStart,
5554
eventData: {
@@ -61,7 +60,11 @@ implements OnApplicationBootstrap, IServerProvider {
6160
});
6261
} else {
6362
this.logger.log('Application started.');
64-
this.eventEmitter.emit(AppAnalyticsEvents.Initialize, { anonymousId: serverInfo.id, sessionId: this.sessionId });
63+
this.eventEmitter.emit(AppAnalyticsEvents.Initialize, {
64+
anonymousId: serverInfo.id,
65+
sessionId: this.sessionId,
66+
appType: this.getAppType(SERVER_CONFIG.buildType),
67+
});
6568
this.eventEmitter.emit(AppAnalyticsEvents.Track, {
6669
event: TelemetryEvents.ApplicationStarted,
6770
eventData: {
@@ -90,6 +93,7 @@ implements OnApplicationBootstrap, IServerProvider {
9093
appVersion: SERVER_CONFIG.appVersion,
9194
osPlatform: process.platform,
9295
buildType: SERVER_CONFIG.buildType,
96+
appType: this.getAppType(SERVER_CONFIG.buildType),
9397
encryptionStrategies: await this.encryptionService.getAvailableEncryptionStrategies(),
9498
fixedDatabaseId: REDIS_STACK_CONFIG?.id,
9599
};
@@ -100,4 +104,17 @@ implements OnApplicationBootstrap, IServerProvider {
100104
throw new InternalServerErrorException();
101105
}
102106
}
107+
108+
getAppType(buildType: string): AppType {
109+
switch (buildType) {
110+
case BuildType.DockerOnPremise:
111+
return AppType.Docker;
112+
case BuildType.Electron:
113+
return AppType.Electron;
114+
case BuildType.RedisStack:
115+
return AppType.RedisStackWeb;
116+
default:
117+
return AppType.Unknown;
118+
}
119+
}
103120
}

redisinsight/api/src/modules/core/services/analytics/analytics.service.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
AnalyticsService,
77
NON_TRACKING_ANONYMOUS_ID,
88
} from './analytics.service';
9+
import { AppType } from 'src/modules/core/models/server-provider.interface';
910

1011
let mockAnalyticsTrack;
1112
jest.mock(
@@ -59,7 +60,7 @@ describe('AnalyticsService', () => {
5960

6061
describe('initialize', () => {
6162
it('should set anonymousId', () => {
62-
service.initialize({ anonymousId: mockAnonymousId, sessionId });
63+
service.initialize({ anonymousId: mockAnonymousId, sessionId, appType: AppType.Electron });
6364

6465
const anonymousId = service.getAnonymousId();
6566

@@ -70,7 +71,7 @@ describe('AnalyticsService', () => {
7071
describe('sendEvent', () => {
7172
beforeEach(() => {
7273
mockAnalyticsTrack = jest.fn();
73-
service.initialize({ anonymousId: mockAnonymousId, sessionId });
74+
service.initialize({ anonymousId: mockAnonymousId, sessionId, appType: AppType.Electron });
7475
});
7576
it('should send event with anonymousId if permission are granted', async () => {
7677
settingsService.getSettings = jest
@@ -87,7 +88,9 @@ describe('AnalyticsService', () => {
8788
anonymousId: mockAnonymousId,
8889
integrations: { Amplitude: { session_id: sessionId } },
8990
event: TelemetryEvents.ApplicationStarted,
90-
properties: {},
91+
properties: {
92+
buildType: AppType.Electron,
93+
},
9194
});
9295
});
9396
it('should not send event if permission are not granted', async () => {
@@ -118,7 +121,9 @@ describe('AnalyticsService', () => {
118121
anonymousId: mockAnonymousId,
119122
integrations: { Amplitude: { session_id: sessionId } },
120123
event: TelemetryEvents.ApplicationStarted,
121-
properties: {},
124+
properties: {
125+
buildType: AppType.Electron,
126+
},
122127
});
123128
});
124129
});

redisinsight/api/src/modules/core/services/analytics/analytics.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface ITelemetryEvent {
1818
export interface ITelemetryInitEvent {
1919
anonymousId: string;
2020
sessionId: number;
21+
appType: string;
2122
}
2223

2324
@Injectable()
@@ -26,6 +27,8 @@ export class AnalyticsService {
2627

2728
private sessionId: number = -1;
2829

30+
private appType: string = 'unknown';
31+
2932
private analytics;
3033

3134
constructor(
@@ -39,9 +42,10 @@ export class AnalyticsService {
3942

4043
@OnEvent(AppAnalyticsEvents.Initialize)
4144
public initialize(payload: ITelemetryInitEvent) {
42-
const { anonymousId, sessionId } = payload;
45+
const { anonymousId, sessionId, appType } = payload;
4346
this.sessionId = sessionId;
4447
this.anonymousId = anonymousId;
48+
this.appType = appType;
4549
this.analytics = new Analytics(ANALYTICS_CONFIG.writeKey);
4650
}
4751

@@ -68,6 +72,7 @@ export class AnalyticsService {
6872
event,
6973
properties: {
7074
...eventData,
75+
buildType: this.appType,
7176
},
7277
});
7378
}

redisinsight/api/test/api/info/GET-info.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const responseSchema = Joi.object().keys({
1717
appVersion: Joi.string().required(),
1818
osPlatform: Joi.string().required(),
1919
buildType: Joi.string().valid('ELECTRON', 'DOCKER_ON_PREMISE', 'REDIS_STACK').required(),
20+
appType: Joi.string().valid('ELECTRON', 'DOCKER', 'REDIS_STACK_WEB', 'UNKNOWN').required(),
2021
encryptionStrategies: Joi.array().items(Joi.string()),
2122
sessionId: Joi.number().required(),
2223
}).required();

0 commit comments

Comments
 (0)