Skip to content

Commit 3affc23

Browse files
committed
RI-6363 include server_name to telemetry
1 parent 3533807 commit 3affc23

File tree

6 files changed

+70
-17
lines changed

6 files changed

+70
-17
lines changed

redisinsight/api/src/modules/database/models/database-overview.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,60 @@ export class DatabaseOverview {
44
@ApiProperty({
55
description: 'Redis database version',
66
type: String,
7-
})
7+
})
88
version: string;
99

1010
@ApiPropertyOptional({
1111
description: 'Total number of bytes allocated by Redis primary shards',
1212
type: Number,
13-
})
13+
})
1414
usedMemory?: number;
1515

1616
@ApiPropertyOptional({
1717
description: 'Total number of keys inside Redis primary shards',
1818
type: Number,
19-
})
19+
})
2020
totalKeys?: number;
2121

2222
@ApiPropertyOptional({
2323
description: 'Nested object with total number of keys per logical database',
2424
type: Number,
25-
})
25+
})
2626
totalKeysPerDb?: Record<string, number>;
2727

2828
@ApiPropertyOptional({
2929
description: 'Median for connected clients in the all shards',
3030
type: Number,
31-
})
31+
})
3232
connectedClients?: number;
3333

3434
@ApiPropertyOptional({
3535
description: 'Sum of current commands per second in the all shards',
3636
type: Number,
37-
})
37+
})
3838
opsPerSecond?: number;
3939

4040
@ApiPropertyOptional({
4141
description: 'Sum of current network input in the all shards (kbps)',
4242
type: Number,
43-
})
43+
})
4444
networkInKbps?: number;
4545

4646
@ApiPropertyOptional({
4747
description: 'Sum of current network out in the all shards (kbps)',
4848
type: Number,
49-
})
49+
})
5050
networkOutKbps?: number;
5151

5252
@ApiPropertyOptional({
5353
description: 'Sum of current cpu usage in the all shards (%)',
5454
type: Number,
55-
})
55+
})
5656
cpuUsagePercentage?: number;
57+
58+
@ApiProperty({
59+
description: 'Database server name',
60+
type: String,
61+
})
62+
serverName?: string;
5763
}

redisinsight/api/src/modules/database/providers/database-overview.provider.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const mockGetTotalResponse1 = 1;
5555

5656
export const mockDatabaseOverview: DatabaseOverview = {
5757
version: mockServerInfo.redis_version,
58+
serverName: null,
5859
usedMemory: 1,
5960
totalKeys: 2,
6061
totalKeysPerDb: {
@@ -110,6 +111,28 @@ describe('OverviewService', () => {
110111
networkOutKbps: undefined,
111112
});
112113
});
114+
it('should return overview with serverName if server_name is present in redis info', async () => {
115+
const redisInfoReplyWithServerName = `${mockStandaloneRedisInfoReply.slice(0, 11)}server_name:valkey\r\n${mockStandaloneRedisInfoReply.slice(11)}`;
116+
when(standaloneClient.sendCommand)
117+
.calledWith(['info'], { replyEncoding: 'utf8' })
118+
.mockResolvedValue(redisInfoReplyWithServerName);
119+
120+
const result = await service.getOverview(mockClientMetadata, standaloneClient, mockCurrentKeyspace);
121+
122+
expect(result).toEqual({
123+
...mockDatabaseOverview,
124+
version: '6.0.5',
125+
serverName: 'valkey',
126+
connectedClients: 1,
127+
totalKeys: 1,
128+
totalKeysPerDb: undefined,
129+
usedMemory: 1000000,
130+
cpuUsagePercentage: undefined,
131+
opsPerSecond: undefined,
132+
networkInKbps: undefined,
133+
networkOutKbps: undefined,
134+
});
135+
});
113136
it('should return total 0 and empty total per db object', async () => {
114137
spyGetNodeInfo.mockResolvedValueOnce({
115138
...mockNodeInfo,

redisinsight/api/src/modules/database/providers/database-overview.provider.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class DatabaseOverviewProvider {
5555

5656
return {
5757
version: this.getVersion(nodesInfo),
58+
serverName: this.getServerName(nodesInfo),
5859
totalKeys,
5960
totalKeysPerDb,
6061
usedMemory: this.calculateUsedMemory(nodesInfo),
@@ -126,6 +127,15 @@ export class DatabaseOverviewProvider {
126127
return get(nodes, [0, 'server', 'redis_version'], null);
127128
}
128129

130+
/**
131+
* Get server_name from the first shard in the list
132+
* @param nodes
133+
* @private
134+
*/
135+
private getServerName(nodes = []): string {
136+
return get(nodes, [0, 'server', 'server_name'], null);
137+
}
138+
129139
/**
130140
* Sum of current ops per second (instantaneous_ops_per_sec) for all shards
131141
* @param nodes

redisinsight/api/test/api/database/GET-databases-id-overview.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const endpoint = (id = constants.TEST_INSTANCE_ID) =>
77

88
const responseSchema = Joi.object().keys({
99
version: Joi.string().required(),
10+
serverName: Joi.string().allow(null),
1011
totalKeys: Joi.number().integer().allow(null),
1112
totalKeysPerDb: Joi.object().allow(null),
1213
usedMemory: Joi.number().integer().allow(null),

redisinsight/ui/src/slices/interfaces/instances.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ export interface DatabaseConfigInfo {
307307
networkInKbps?: Nullable<number>
308308
networkOutKbps?: Nullable<number>
309309
cpuUsagePercentage?: Nullable<number>
310+
serverName?: Nullable<string>
310311
}
311312

312313
export interface InitialStateInstances {

redisinsight/ui/src/telemetry/telemetryUtils.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,53 @@ import {
2020
import { TelemetryEvent } from './events'
2121
import { checkIsAnalyticsGranted } from './checkAnalytics'
2222

23-
export const getProvider = (dbId: string): Maybe<string> => {
23+
export const getProviderData = (dbId: string): {
24+
provider: Maybe<string>,
25+
serverName: Maybe<string>
26+
} => {
27+
let provider
28+
let serverName
2429
const instance = get(store.getState(), 'connections.instances.connectedInstance')
25-
return (instance.id === dbId) ? instance.provider : undefined
30+
if (instance.id === dbId) {
31+
provider = instance?.provider
32+
const instanceOverview = get(store.getState(), 'connections.instances.instanceOverview')
33+
serverName = instanceOverview?.serverName || undefined
34+
}
35+
return { provider, serverName }
2636
}
2737

2838
const TELEMETRY_EMPTY_VALUE = 'none'
2939

3040
const sendEventTelemetry = async ({ event, eventData = {}, traits = {} }: ITelemetrySendEvent) => {
41+
let providerData
3142
try {
3243
const isAnalyticsGranted = checkIsAnalyticsGranted()
3344
if (!isAnalyticsGranted) {
3445
return
3546
}
3647

37-
if (!eventData.provider && eventData.databaseId) {
38-
eventData.provider = getProvider(eventData.databaseId)
48+
if (eventData.databaseId) {
49+
providerData = getProviderData(eventData.databaseId)
3950
}
4051
await apiService.post(`${ApiEndpoints.ANALYTICS_SEND_EVENT}`,
41-
{ event, eventData, traits })
52+
{ event, eventData: { ...providerData, ...eventData }, traits })
4253
} catch (e) {
4354
// continue regardless of error
4455
}
4556
}
4657

4758
const sendPageViewTelemetry = async ({ name, eventData = {} }: ITelemetrySendPageView) => {
4859
try {
60+
let providerData
4961
const isAnalyticsGranted = checkIsAnalyticsGranted()
5062
if (!isAnalyticsGranted) {
5163
return
5264
}
53-
if (!eventData.provider && eventData.databaseId) {
54-
eventData.provider = getProvider(eventData.databaseId)
65+
if (eventData.databaseId) {
66+
providerData = getProviderData(eventData.databaseId)
5567
}
5668
await apiService.post(`${ApiEndpoints.ANALYTICS_SEND_PAGE}`,
57-
{ event: name, eventData })
69+
{ event: name, eventData: { ...providerData, ...eventData } })
5870
} catch (e) {
5971
// continue regardless of error
6072
}

0 commit comments

Comments
 (0)