Skip to content

Commit 08d38eb

Browse files
author
arthosofteq
authored
Merge pull request #770 from RedisInsight/feature/RI-3001-autodiscovery_ipv6_support
#RI-3001 add IPv6 support for redis autodiscovery
2 parents 9b67887 + 716a0c2 commit 08d38eb

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DatabasesProvider } from 'src/modules/shared/services/instances-busines
55
import { RedisService } from 'src/modules/core/services/redis/redis.service';
66
import { AppTool } from 'src/models';
77
import { InstancesBusinessService } from 'src/modules/shared/services/instances-business/instances-business.service';
8-
import { getAvailableEndpoints, getRunningProcesses, getTCP4Endpoints } from 'src/utils/auto-discovery-helper';
8+
import { getAvailableEndpoints, getRunningProcesses, getTCPEndpoints } from 'src/utils/auto-discovery-helper';
99
import { convertRedisInfoReplyToObject } from 'src/utils';
1010
import { ISettingsProvider } from 'src/modules/core/models/settings-provider.interface';
1111
import config from 'src/utils/config';
@@ -56,7 +56,7 @@ export class AutoDiscoveryService implements OnModuleInit {
5656
* @private
5757
*/
5858
private async discoverDatabases() {
59-
const endpoints = await getAvailableEndpoints(getTCP4Endpoints(await getRunningProcesses()));
59+
const endpoints = await getAvailableEndpoints(getTCPEndpoints(await getRunningProcesses()));
6060

6161
// Add redis databases or resolve after 1s to not block app startup for a long time
6262
await Promise.race([

redisinsight/api/src/utils/auto-discovery-helper.spec.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
getTCP4Endpoints,
2+
getTCPEndpoints,
33
} from 'src/utils/auto-discovery-helper';
44

55
const winNetstat = ''
@@ -12,6 +12,7 @@ const winNetstat = ''
1212
+ 'TCP [::]:445 [::]:0 LISTENING 4\n'
1313
+ 'TCP [::]:808 [::]:0 LISTENING 6084\n'
1414
+ 'TCP [::]:2701 [::]:0 LISTENING 6056\n'
15+
+ 'TCP [::]:5000 [::]:0 LISTENING 6056\n'
1516
+ 'TCP *:* LISTENING 6056';
1617

1718
const linuxNetstat = ''
@@ -39,14 +40,18 @@ const macNetstat = ''
3940
+ 'tcp6 0 0 ::1.52167 ::1.5002 ESTABLISHED 406172 146808 31200 0 0x0102 0x00000008\n';
4041
/* eslint-enable max-len */
4142

42-
const getTCP4EndpointsTests = [
43+
const getTCPEndpointsTests = [
4344
{
4445
name: 'win output',
4546
input: winNetstat.split('\n'),
4647
output: [
4748
{ host: 'localhost', port: 5000 },
4849
{ host: 'localhost', port: 6379 },
4950
{ host: 'localhost', port: 6380 },
51+
{ host: 'localhost', port: 135 },
52+
{ host: 'localhost', port: 445 },
53+
{ host: 'localhost', port: 808 },
54+
{ host: 'localhost', port: 2701 },
5055
],
5156
},
5257
{
@@ -56,6 +61,12 @@ const getTCP4EndpointsTests = [
5661
{ host: 'localhost', port: 5000 },
5762
{ host: 'localhost', port: 6379 },
5863
{ host: 'localhost', port: 6380 },
64+
{ host: 'localhost', port: 28100 },
65+
{ host: 'localhost', port: 8100 },
66+
{ host: 'localhost', port: 8101 },
67+
{ host: 'localhost', port: 8102 },
68+
{ host: 'localhost', port: 8103 },
69+
{ host: 'localhost', port: 8200 },
5970
],
6071
},
6172
{
@@ -65,14 +76,16 @@ const getTCP4EndpointsTests = [
6576
{ host: 'localhost', port: 5000 },
6677
{ host: 'localhost', port: 6379 },
6778
{ host: 'localhost', port: 6380 },
79+
{ host: 'localhost', port: 5002 },
80+
{ host: 'localhost', port: 52167 },
6881
],
6982
},
7083
];
7184

7285
describe('getTCP4Endpoints', () => {
73-
getTCP4EndpointsTests.forEach((test) => {
86+
getTCPEndpointsTests.forEach((test) => {
7487
it(`Should return endpoints to test ${test.name}`, async () => {
75-
const result = getTCP4Endpoints(test.input);
88+
const result = getTCPEndpoints(test.input);
7689

7790
expect(result).toEqual(test.output);
7891
});

redisinsight/api/src/utils/auto-discovery-helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ export const getRunningProcesses = async (): Promise<string[]> => new Promise((r
5252
* Return list of unique endpoints (host is hardcoded) to test
5353
* @param processes
5454
*/
55-
export const getTCP4Endpoints = (processes: string[]): Endpoint[] => {
56-
const regExp = /(\d+\.\d+\.\d+\.\d+|\*)[:.](\d+)/;
55+
export const getTCPEndpoints = (processes: string[]): Endpoint[] => {
56+
const regExp = /\s((\d+\.\d+\.\d+\.\d+|\*)[:.]|([0-9a-fA-F\][]{0,4}[.:]){1,8})(\d+)\s/;
5757
const endpoints = new Map();
5858

5959
processes.forEach((line) => {
6060
const match = line.match(regExp);
6161

6262
if (match) {
63-
endpoints.set(match[2], {
63+
endpoints.set(match[4], {
6464
host: 'localhost',
65-
port: parseInt(match[2], 10),
65+
port: parseInt(match[4], 10),
6666
});
6767
}
6868
});

0 commit comments

Comments
 (0)