Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DatabasesProvider } from 'src/modules/shared/services/instances-busines
import { RedisService } from 'src/modules/core/services/redis/redis.service';
import { AppTool } from 'src/models';
import { InstancesBusinessService } from 'src/modules/shared/services/instances-business/instances-business.service';
import { getAvailableEndpoints, getRunningProcesses, getTCP4Endpoints } from 'src/utils/auto-discovery-helper';
import { getAvailableEndpoints, getRunningProcesses, getTCPEndpoints } from 'src/utils/auto-discovery-helper';
import { convertRedisInfoReplyToObject } from 'src/utils';
import { ISettingsProvider } from 'src/modules/core/models/settings-provider.interface';
import config from 'src/utils/config';
Expand Down Expand Up @@ -56,7 +56,7 @@ export class AutoDiscoveryService implements OnModuleInit {
* @private
*/
private async discoverDatabases() {
const endpoints = await getAvailableEndpoints(getTCP4Endpoints(await getRunningProcesses()));
const endpoints = await getAvailableEndpoints(getTCPEndpoints(await getRunningProcesses()));

// Add redis databases or resolve after 1s to not block app startup for a long time
await Promise.race([
Expand Down
21 changes: 17 additions & 4 deletions redisinsight/api/src/utils/auto-discovery-helper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
getTCP4Endpoints,
getTCPEndpoints,
} from 'src/utils/auto-discovery-helper';

const winNetstat = ''
Expand All @@ -12,6 +12,7 @@ const winNetstat = ''
+ 'TCP [::]:445 [::]:0 LISTENING 4\n'
+ 'TCP [::]:808 [::]:0 LISTENING 6084\n'
+ 'TCP [::]:2701 [::]:0 LISTENING 6056\n'
+ 'TCP [::]:5000 [::]:0 LISTENING 6056\n'
+ 'TCP *:* LISTENING 6056';

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

const getTCP4EndpointsTests = [
const getTCPEndpointsTests = [
{
name: 'win output',
input: winNetstat.split('\n'),
output: [
{ host: 'localhost', port: 5000 },
{ host: 'localhost', port: 6379 },
{ host: 'localhost', port: 6380 },
{ host: 'localhost', port: 135 },
{ host: 'localhost', port: 445 },
{ host: 'localhost', port: 808 },
{ host: 'localhost', port: 2701 },
],
},
{
Expand All @@ -56,6 +61,12 @@ const getTCP4EndpointsTests = [
{ host: 'localhost', port: 5000 },
{ host: 'localhost', port: 6379 },
{ host: 'localhost', port: 6380 },
{ host: 'localhost', port: 28100 },
{ host: 'localhost', port: 8100 },
{ host: 'localhost', port: 8101 },
{ host: 'localhost', port: 8102 },
{ host: 'localhost', port: 8103 },
{ host: 'localhost', port: 8200 },
],
},
{
Expand All @@ -65,14 +76,16 @@ const getTCP4EndpointsTests = [
{ host: 'localhost', port: 5000 },
{ host: 'localhost', port: 6379 },
{ host: 'localhost', port: 6380 },
{ host: 'localhost', port: 5002 },
{ host: 'localhost', port: 52167 },
],
},
];

describe('getTCP4Endpoints', () => {
getTCP4EndpointsTests.forEach((test) => {
getTCPEndpointsTests.forEach((test) => {
it(`Should return endpoints to test ${test.name}`, async () => {
const result = getTCP4Endpoints(test.input);
const result = getTCPEndpoints(test.input);

expect(result).toEqual(test.output);
});
Expand Down
8 changes: 4 additions & 4 deletions redisinsight/api/src/utils/auto-discovery-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ export const getRunningProcesses = async (): Promise<string[]> => new Promise((r
* Return list of unique endpoints (host is hardcoded) to test
* @param processes
*/
export const getTCP4Endpoints = (processes: string[]): Endpoint[] => {
const regExp = /(\d+\.\d+\.\d+\.\d+|\*)[:.](\d+)/;
export const getTCPEndpoints = (processes: string[]): Endpoint[] => {
const regExp = /\s((\d+\.\d+\.\d+\.\d+|\*)[:.]|([0-9a-fA-F\][]{0,4}[.:]){1,8})(\d+)\s/;
const endpoints = new Map();

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

if (match) {
endpoints.set(match[2], {
endpoints.set(match[4], {
host: 'localhost',
port: parseInt(match[2], 10),
port: parseInt(match[4], 10),
});
}
});
Expand Down