Skip to content

Commit 52ccfce

Browse files
Merge branch 'main' into feature/RI-6323-wb-big-responses
2 parents 9a22434 + cfc5dea commit 52ccfce

21 files changed

+116
-36
lines changed

redisinsight/api/src/__mocks__/cloud-common.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { HttpStatus } from '@nestjs/common';
2-
import ERROR_MESSAGES from 'src/constants/error-messages';
32
import { CustomErrorCodes } from 'src/constants';
43

54
export const mockCapiUnauthorizedError = {
6-
message: 'Request failed with status code 401',
5+
message: 'Custom unauthorized message',
76
response: {
87
status: 401,
98
},
@@ -12,14 +11,14 @@ export const mockCapiUnauthorizedError = {
1211
export const mockSmApiUnauthorizedError = mockCapiUnauthorizedError;
1312

1413
export const mockSmApiInternalServerError = {
15-
message: 'Something wrong',
14+
message: 'Custom server error message',
1615
response: {
1716
status: 500,
1817
},
1918
};
2019

2120
export const mockSmApiBadRequestError = {
22-
message: 'Bad Request',
21+
message: 'Custom bad request message',
2322
response: {
2423
status: 400,
2524
},
@@ -34,13 +33,13 @@ export const mockUtm = {
3433
export const mockCloudApiUnauthorizedExceptionResponse = {
3534
error: 'CloudApiUnauthorized',
3635
errorCode: CustomErrorCodes.CloudApiUnauthorized,
37-
message: ERROR_MESSAGES.UNAUTHORIZED,
36+
message: mockCapiUnauthorizedError.message,
3837
statusCode: HttpStatus.UNAUTHORIZED,
3938
};
4039

4140
export const mockCloudApiBadRequestExceptionResponse = {
4241
error: 'CloudApiBadRequest',
4342
errorCode: CustomErrorCodes.CloudApiBadRequest,
44-
message: ERROR_MESSAGES.BAD_REQUEST,
43+
message: mockSmApiBadRequestError.message,
4544
statusCode: HttpStatus.BAD_REQUEST,
4645
};

redisinsight/api/src/__mocks__/databases.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ export const mockDatabaseOverviewCurrentKeyspace = DatabaseOverviewKeyspace.Curr
232232
export const mockRedisServerInfoDto = {
233233
redis_version: '7.0.5',
234234
redis_mode: 'standalone',
235+
server_name: 'valkey',
235236
os: 'Linux 4.15.0-1087-gcp x86_64',
236237
arch_bits: '64',
237238
tcp_port: '11113',

redisinsight/api/src/modules/database/database.analytics.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe('DatabaseAnalytics', () => {
5757
timeout: mockDatabaseWithTlsAuth.timeout / 1_000, // milliseconds to seconds
5858
databaseIndex: 0,
5959
useDecompression: mockDatabaseWithTlsAuth.compressor,
60+
serverName: 'valkey',
6061
...DEFAULT_REDIS_MODULES_SUMMARY,
6162
},
6263
);
@@ -88,6 +89,7 @@ describe('DatabaseAnalytics', () => {
8889
timeout: mockDatabaseWithTlsAuth.timeout / 1_000, // milliseconds to seconds
8990
databaseIndex: 0,
9091
useDecompression: mockDatabaseWithTlsAuth.compressor,
92+
serverName: 'valkey',
9193
...DEFAULT_REDIS_MODULES_SUMMARY,
9294
},
9395
);
@@ -127,6 +129,7 @@ describe('DatabaseAnalytics', () => {
127129
version: 20000,
128130
},
129131
customModules: [{ name: 'rediSQL', version: 1 }],
132+
serverName: null,
130133
},
131134
);
132135
});
@@ -166,6 +169,7 @@ describe('DatabaseAnalytics', () => {
166169
version: 20000,
167170
},
168171
customModules: [{ name: 'rediSQL', version: 1 }],
172+
serverName: null,
169173
},
170174
);
171175
});

redisinsight/api/src/modules/database/database.analytics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class DatabaseAnalytics extends TelemetryBaseService {
5151
timeout: instance.timeout / 1_000, // milliseconds to seconds
5252
databaseIndex: instance.db || 0,
5353
useDecompression: instance.compressor || null,
54+
serverName: additionalInfo?.server?.server_name || null,
5455
...modulesSummary,
5556
},
5657
);

redisinsight/api/src/modules/database/database.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export class DatabaseService {
184184
database,
185185
);
186186
const redisInfo = await this.databaseInfoProvider.getRedisGeneralInfo(client);
187+
187188
this.analytics.sendInstanceAddedEvent(database, redisInfo);
188189
await client.disconnect();
189190
} catch (e) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,10 @@ export class DatabaseOverview {
5454
type: Number,
5555
})
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/ai/assistant/DELETE-ai-assistant-chats-id.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ describe('DELETE /ai/assistant/chats/:id', () => {
2626
{
2727
name: 'Should return Unauthorized error',
2828
before: () => {
29-
aiAssistantNock.post('/reset').reply(401, { message: 'Unauthorized' })
29+
aiAssistantNock.post('/reset').replyWithError({ response: { status: 401 }, message: 'Custom unauthorized message' })
3030
},
3131
statusCode: 401,
3232
responseBody: {
3333
statusCode: 401,
3434
error: 'ConvAiUnauthorized',
35-
message: 'Authorization failed',
35+
message: 'Custom unauthorized message',
3636
errorCode: 11301,
3737
},
3838
},

redisinsight/api/test/api/ai/assistant/GET-ai-assistant-chats-id.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ describe('GET /ai/assistant/chats/:id', () => {
4747
{
4848
name: 'Should return Unauthorized error',
4949
before: () => {
50-
aiAssistantNock.get('/history').reply(401, { message: 'Unauthorized' })
50+
aiAssistantNock.get('/history').replyWithError({ response: { status: 401 }, message: 'Custom unauthorized message' })
5151
},
5252
statusCode: 401,
5353
responseBody: {
5454
statusCode: 401,
5555
error: 'ConvAiUnauthorized',
56-
message: 'Authorization failed',
56+
message: 'Custom unauthorized message',
5757
errorCode: 11301,
5858
},
5959
},

0 commit comments

Comments
 (0)