Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#RI-3935 - Rework the connection timeouts #1693

Merged
merged 22 commits into from Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
57d9cce
#RI-3935 - Rework connections timeouts
zalenskiSofteq Feb 2, 2023
c735e5c
#RI-3935 - Rework connections timeouts
zalenskiSofteq Feb 3, 2023
b69af4e
#RI-3935 - Rework connections timeouts
zalenskiSofteq Feb 3, 2023
efed14b
#RI-3935 - fix pr comment
zalenskiSofteq Feb 3, 2023
9f753e4
#RI-4134 Endpoint to test connection before action
Feb 3, 2023
89af7e8
Merge pull request #1681 from RedisInsight/be/feature/RI-3935_Rework_…
zalenskiSofteq Feb 3, 2023
a38c81e
#RI-3935 - Rework the connection timeouts
zalenskiSofteq Feb 6, 2023
3d8afdf
Merge pull request #1692 from RedisInsight/fe/feature/RI-3935_Rework_…
zalenskiSofteq Feb 6, 2023
ff2a474
Merge pull request #1682 from RedisInsight/be/feature/RI-4134-Test_th…
AmirAllayarovSofteq Feb 6, 2023
ec0ea06
added tests for connection timeout input
vlad-dargel Feb 7, 2023
0b35c67
#RI-3934 - add test connection button (#1696)
AmirAllayarovSofteq Feb 7, 2023
1122973
Merge pull request #1703 from RedisInsight/feature/RI-3934-Test_the_d…
zalenskiSofteq Feb 8, 2023
f802d81
* #RI-4155 - Timeout is displayed in milliseconds in telemetry
zalenskiSofteq Feb 8, 2023
96d25e4
* #RI-4151 - [FE] 'NaN' timeout by default when adding database
zalenskiSofteq Feb 8, 2023
70363f4
Merge pull request #1706 from RedisInsight/feature/bugfix
zalenskiSofteq Feb 8, 2023
d0881aa
Merge branch 'main' into feature/RI-3935_Rework_the_connection_timeouts
zalenskiSofteq Feb 8, 2023
6ab0f67
Merge pull request #1705 from RedisInsight/be/bugfix/RI-4155_Timeout_…
zalenskiSofteq Feb 8, 2023
f3ad1f4
Merge pull request #1699 from RedisInsight/e2e/feature/RI-3935_Rework…
vlad-dargel Feb 8, 2023
42ba1a2
#RI-3935 - revert SEGMENT_WRITE_KEY
zalenskiSofteq Feb 8, 2023
4a1121a
Merge remote-tracking branch 'origin/feature/RI-3935_Rework_the_conne…
zalenskiSofteq Feb 8, 2023
c30d46b
#RI-3935 - revert SEGMENT_WRITE_KEY
zalenskiSofteq Feb 8, 2023
233f015
Merge branch 'main' into feature/RI-3935_Rework_the_connection_timeouts
zalenskiSofteq Feb 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions configs/webpack.config.main.prod.babel.js
@@ -1,6 +1,7 @@
import path from 'path';
import webpack from 'webpack';
import { merge } from 'webpack-merge';
import { toString } from 'lodash'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import baseConfig from './webpack.config.base';
import DeleteSourceMaps from '../scripts/DeleteSourceMaps';
Expand Down Expand Up @@ -69,6 +70,9 @@ export default merge(baseConfig, {
APP_VERSION: version,
AWS_BUCKET_NAME: 'AWS_BUCKET_NAME' in process.env ? process.env.AWS_BUCKET_NAME : '',
SEGMENT_WRITE_KEY: 'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
: toString(30 * 1000), // 30 sec
}),
],

Expand Down
4 changes: 4 additions & 0 deletions configs/webpack.config.main.stage.babel.js
@@ -1,6 +1,7 @@
import webpack from 'webpack';
import { merge } from 'webpack-merge';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import { toString } from 'lodash'
import mainProdConfig from './webpack.config.main.prod.babel';
import DeleteSourceMaps from '../scripts/DeleteSourceMaps';
import { version } from '../redisinsight/package.json';
Expand Down Expand Up @@ -29,6 +30,9 @@ export default merge(mainProdConfig, {
APP_VERSION: version,
AWS_BUCKET_NAME: 'AWS_BUCKET_NAME' in process.env ? process.env.AWS_BUCKET_NAME : '',
SEGMENT_WRITE_KEY: 'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
: toString(30 * 1000), // 30 sec
}),
],
});
4 changes: 4 additions & 0 deletions configs/webpack.config.renderer.dev.babel.js
Expand Up @@ -2,6 +2,7 @@ import path from 'path';
import webpack from 'webpack';
import { merge } from 'webpack-merge';
import { spawn } from 'child_process';
import { toString } from 'lodash'
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
import baseConfig from './webpack.config.base';
Expand Down Expand Up @@ -215,6 +216,9 @@ export default merge(baseConfig, {
APP_VERSION: version,
SEGMENT_WRITE_KEY:
'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
: toString(30 * 1000), // 30 sec
}),

new webpack.LoaderOptionsPlugin({
Expand Down
6 changes: 5 additions & 1 deletion configs/webpack.config.renderer.dev.dll.babel.js
@@ -1,6 +1,7 @@
import webpack from 'webpack';
import path from 'path';
import { merge } from 'webpack-merge';
import { toString } from 'lodash'
import baseConfig from './webpack.config.base';
import { dependencies } from '../package.json';
import { dependencies as dependenciesApi } from '../redisinsight/package.json';
Expand Down Expand Up @@ -54,7 +55,10 @@ export default merge(baseConfig, {
SCAN_TREE_COUNT_DEFAULT: '10000',
PIPELINE_COUNT_DEFAULT: '5',
SEGMENT_WRITE_KEY:
'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
: toString(30 * 1000), // 30 sec
}),

new webpack.LoaderOptionsPlugin({
Expand Down
6 changes: 5 additions & 1 deletion configs/webpack.config.renderer.prod.babel.js
@@ -1,5 +1,6 @@
import path from 'path';
import webpack from 'webpack';
import { toString } from 'lodash'
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
Expand Down Expand Up @@ -200,7 +201,10 @@ export default merge(baseConfig, {
SCAN_TREE_COUNT_DEFAULT: '10000',
PIPELINE_COUNT_DEFAULT: '5',
SEGMENT_WRITE_KEY:
'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
: toString(30 * 1000), // 30 sec
}),

new MiniCssExtractPlugin({
Expand Down
4 changes: 4 additions & 0 deletions configs/webpack.config.renderer.stage.babel.js
@@ -1,5 +1,6 @@
import webpack from 'webpack';
import { merge } from 'webpack-merge';
import { toString } from 'lodash'
import baseConfig from './webpack.config.base';
import rendererProdConfig from './webpack.config.renderer.prod.babel';
import DeleteSourceMaps from '../scripts/DeleteSourceMaps';
Expand All @@ -23,6 +24,9 @@ export default merge(baseConfig, {
SCAN_COUNT_MEMORY_ANALYSES: '10000',
SEGMENT_WRITE_KEY:
'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
: toString(30 * 1000), // 30 sec
}),
],
});
4 changes: 4 additions & 0 deletions configs/webpack.config.web.dev.babel.js
Expand Up @@ -9,6 +9,7 @@ import path from 'path';
import webpack from 'webpack';
import { merge } from 'webpack-merge';
import ip from 'ip';
import { toString } from 'lodash'
import commonConfig from './webpack.config.web.common.babel';

function employCache(loaders) {
Expand Down Expand Up @@ -209,6 +210,9 @@ export default merge(commonConfig, {
SCAN_TREE_COUNT_DEFAULT: '10000',
SEGMENT_WRITE_KEY:
'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
: toString(30 * 1000),
}),

new webpack.LoaderOptionsPlugin({
Expand Down
4 changes: 4 additions & 0 deletions configs/webpack.config.web.prod.babel.js
@@ -1,6 +1,7 @@
import { merge } from 'webpack-merge';
import { resolve } from 'path';
import webpack from 'webpack';
import { toString } from 'lodash'
import TerserPlugin from 'terser-webpack-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
Expand Down Expand Up @@ -56,6 +57,9 @@ export default merge(commonConfig, {
PIPELINE_COUNT_DEFAULT: '5',
SEGMENT_WRITE_KEY:
'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
: toString(30 * 1000), // 30 sec
}),

new BundleAnalyzerPlugin({
Expand Down
3 changes: 3 additions & 0 deletions redisinsight/api/config/default.ts
Expand Up @@ -189,6 +189,9 @@ export default {
|| 'https://raw.githubusercontent.com/RedisBloom/RedisBloom/master/commands.json',
},
],
connections: {
timeout: parseInt(process.env.CONNECTIONS_TIMEOUT_DEFAULT, 10) || 30 * 1_000 // 30 sec
},
redisStack: {
id: process.env.BUILD_TYPE === 'REDIS_STACK' ? process.env.REDIS_STACK_DATABASE_ID || 'redis-stack' : undefined,
name: process.env.REDIS_STACK_DATABASE_NAME,
Expand Down
20 changes: 20 additions & 0 deletions redisinsight/api/migration/1675398140189-database-timeout.ts
@@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class databaseTimeout1675398140189 implements MigrationInterface {
name = 'databaseTimeout1675398140189'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "temporary_database_instance" ("id" varchar PRIMARY KEY NOT NULL, "host" varchar NOT NULL, "port" integer NOT NULL, "name" varchar NOT NULL, "username" varchar, "password" varchar, "tls" boolean, "verifyServerCert" boolean, "lastConnection" datetime, "caCertId" varchar, "clientCertId" varchar, "connectionType" varchar NOT NULL DEFAULT ('STANDALONE'), "nodes" varchar DEFAULT ('[]'), "nameFromProvider" varchar, "sentinelMasterName" varchar, "sentinelMasterUsername" varchar, "sentinelMasterPassword" varchar, "provider" varchar DEFAULT ('UNKNOWN'), "modules" varchar NOT NULL DEFAULT ('[]'), "db" integer, "encryption" varchar, "tlsServername" varchar, "new" boolean, "ssh" boolean, "timeout" integer, CONSTRAINT "FK_3b9b625266c00feb2d66a9f36e4" FOREIGN KEY ("clientCertId") REFERENCES "client_certificate" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_d1bc747b5938e22b4b708d8e9a5" FOREIGN KEY ("caCertId") REFERENCES "ca_certificate" ("id") ON DELETE SET NULL ON UPDATE NO ACTION)`);
await queryRunner.query(`INSERT INTO "temporary_database_instance"("id", "host", "port", "name", "username", "password", "tls", "verifyServerCert", "lastConnection", "caCertId", "clientCertId", "connectionType", "nodes", "nameFromProvider", "sentinelMasterName", "sentinelMasterUsername", "sentinelMasterPassword", "provider", "modules", "db", "encryption", "tlsServername", "new", "ssh") SELECT "id", "host", "port", "name", "username", "password", "tls", "verifyServerCert", "lastConnection", "caCertId", "clientCertId", "connectionType", "nodes", "nameFromProvider", "sentinelMasterName", "sentinelMasterUsername", "sentinelMasterPassword", "provider", "modules", "db", "encryption", "tlsServername", "new", "ssh" FROM "database_instance"`);
await queryRunner.query(`DROP TABLE "database_instance"`);
await queryRunner.query(`ALTER TABLE "temporary_database_instance" RENAME TO "database_instance"`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "database_instance" RENAME TO "temporary_database_instance"`);
await queryRunner.query(`CREATE TABLE "database_instance" ("id" varchar PRIMARY KEY NOT NULL, "host" varchar NOT NULL, "port" integer NOT NULL, "name" varchar NOT NULL, "username" varchar, "password" varchar, "tls" boolean, "verifyServerCert" boolean, "lastConnection" datetime, "caCertId" varchar, "clientCertId" varchar, "connectionType" varchar NOT NULL DEFAULT ('STANDALONE'), "nodes" varchar DEFAULT ('[]'), "nameFromProvider" varchar, "sentinelMasterName" varchar, "sentinelMasterUsername" varchar, "sentinelMasterPassword" varchar, "provider" varchar DEFAULT ('UNKNOWN'), "modules" varchar NOT NULL DEFAULT ('[]'), "db" integer, "encryption" varchar, "tlsServername" varchar, "new" boolean, "ssh" boolean, CONSTRAINT "FK_3b9b625266c00feb2d66a9f36e4" FOREIGN KEY ("clientCertId") REFERENCES "client_certificate" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_d1bc747b5938e22b4b708d8e9a5" FOREIGN KEY ("caCertId") REFERENCES "ca_certificate" ("id") ON DELETE SET NULL ON UPDATE NO ACTION)`);
await queryRunner.query(`INSERT INTO "database_instance"("id", "host", "port", "name", "username", "password", "tls", "verifyServerCert", "lastConnection", "caCertId", "clientCertId", "connectionType", "nodes", "nameFromProvider", "sentinelMasterName", "sentinelMasterUsername", "sentinelMasterPassword", "provider", "modules", "db", "encryption", "tlsServername", "new", "ssh") SELECT "id", "host", "port", "name", "username", "password", "tls", "verifyServerCert", "lastConnection", "caCertId", "clientCertId", "connectionType", "nodes", "nameFromProvider", "sentinelMasterName", "sentinelMasterUsername", "sentinelMasterPassword", "provider", "modules", "db", "encryption", "tlsServername", "new", "ssh" FROM "temporary_database_instance"`);
await queryRunner.query(`DROP TABLE "temporary_database_instance"`);
}

}
2 changes: 2 additions & 0 deletions redisinsight/api/migration/index.ts
Expand Up @@ -26,6 +26,7 @@ import { sshOptions1673035852335 } from './1673035852335-ssh-options';
import { workbenchAndAnalysisDbIndex1673934231410 } from './1673934231410-workbench-and-analysis-db';
import { browserHistory1674539211397 } from './1674539211397-browser-history';
import { databaseAnalysisRecommendations1674660306971 } from './1674660306971-database-analysis-recommendations';
import { databaseTimeout1675398140189 } from './1675398140189-database-timeout';

export default [
initialMigration1614164490968,
Expand Down Expand Up @@ -56,4 +57,5 @@ export default [
workbenchAndAnalysisDbIndex1673934231410,
databaseAnalysisRecommendations1674660306971,
browserHistory1674539211397,
databaseTimeout1675398140189,
];
1 change: 1 addition & 0 deletions redisinsight/api/package.json
Expand Up @@ -53,6 +53,7 @@
"body-parser": "^1.19.0",
"class-transformer": "^0.2.3",
"class-validator": "^0.12.2",
"connect-timeout": "^1.9.0",
"date-fns": "^2.29.3",
"detect-port": "^1.5.1",
"dotenv": "^16.0.0",
Expand Down
1 change: 1 addition & 0 deletions redisinsight/api/src/__mocks__/databases.ts
Expand Up @@ -32,6 +32,7 @@ export const mockDatabase = Object.assign(new Database(), {
host: '127.0.100.1',
port: 6379,
connectionType: ConnectionType.STANDALONE,
timeout: 30_000,
new: false,
});

Expand Down
Expand Up @@ -164,7 +164,7 @@ describe('DatabaseImportService', () => {
}, 0);

expect(databaseRepository.create).toHaveBeenCalledWith({
...pick(mockDatabase, ['host', 'port', 'name', 'connectionType']),
...pick(mockDatabase, ['host', 'port', 'name', 'connectionType', 'timeout']),
new: true,
});
});
Expand All @@ -175,7 +175,7 @@ describe('DatabaseImportService', () => {
}, 0);

expect(databaseRepository.create).toHaveBeenCalledWith({
...pick(mockDatabase, ['host', 'port', 'name', 'connectionType']),
...pick(mockDatabase, ['host', 'port', 'name', 'connectionType', 'timeout']),
name: `${mockDatabase.host}:${mockDatabase.port}`,
new: true,
});
Expand All @@ -188,7 +188,7 @@ describe('DatabaseImportService', () => {
}, 0);

expect(databaseRepository.create).toHaveBeenCalledWith({
...pick(mockDatabase, ['host', 'port', 'name']),
...pick(mockDatabase, ['host', 'port', 'name', 'timeout']),
connectionType: ConnectionType.CLUSTER,
new: true,
});
Expand Down
Expand Up @@ -38,6 +38,7 @@ export class DatabaseConnectionService {
const toUpdate: Partial<Database> = {
new: false,
lastConnection: new Date(),
timeout: client.options.connectTimeout,
modules: await this.databaseInfoProvider.determineDatabaseModules(client),
};

Expand Down
Expand Up @@ -102,6 +102,7 @@ describe('DatabaseAnalytics', () => {
totalMemory: mockRedisGeneralInfo.usedMemory,
numberedDatabases: mockRedisGeneralInfo.databases,
numberOfModules: 0,
timeout: mockDatabaseWithTlsAuth.timeout / 1_000, // milliseconds to seconds
...DEFAULT_REDIS_MODULES_SUMMARY,
},
);
Expand Down Expand Up @@ -130,6 +131,7 @@ describe('DatabaseAnalytics', () => {
totalMemory: mockRedisGeneralInfo.usedMemory,
numberedDatabases: mockRedisGeneralInfo.databases,
numberOfModules: 0,
timeout: mockDatabaseWithTlsAuth.timeout / 1_000, // milliseconds to seconds
...DEFAULT_REDIS_MODULES_SUMMARY,
},
);
Expand Down Expand Up @@ -160,6 +162,7 @@ describe('DatabaseAnalytics', () => {
totalMemory: undefined,
numberedDatabases: undefined,
numberOfModules: 2,
timeout: mockDatabaseWithTlsAuth.timeout / 1_000, // milliseconds to seconds
...DEFAULT_REDIS_MODULES_SUMMARY,
RediSearch: {
loaded: true,
Expand Down Expand Up @@ -195,6 +198,7 @@ describe('DatabaseAnalytics', () => {
useTLSAuthClients: 'disabled',
useSNI: 'enabled',
useSSH: 'disabled',
timeout: mockDatabaseWithTlsAuth.timeout / 1_000, // milliseconds to seconds
previousValues: {
connectionType: prev.connectionType,
provider: prev.provider,
Expand Down Expand Up @@ -229,6 +233,7 @@ describe('DatabaseAnalytics', () => {
useTLSAuthClients: 'enabled',
useSNI: 'enabled',
useSSH: 'disabled',
timeout: mockDatabaseWithTlsAuth.timeout / 1_000, // milliseconds to seconds
previousValues: {
connectionType: prev.connectionType,
provider: prev.provider,
Expand Down
2 changes: 2 additions & 0 deletions redisinsight/api/src/modules/database/database.analytics.ts
Expand Up @@ -65,6 +65,7 @@ export class DatabaseAnalytics extends TelemetryBaseService {
totalMemory: additionalInfo.usedMemory,
numberedDatabases: additionalInfo.databases,
numberOfModules: instance.modules?.length || 0,
timeout: instance.timeout / 1_000, // milliseconds to seconds
...modulesSummary,
},
);
Expand Down Expand Up @@ -97,6 +98,7 @@ export class DatabaseAnalytics extends TelemetryBaseService {
useTLSAuthClients: cur?.clientCert ? 'enabled' : 'disabled',
useSNI: cur?.tlsServername ? 'enabled' : 'disabled',
useSSH: cur?.ssh ? 'enabled' : 'disabled',
timeout: cur?.timeout / 1_000, // milliseconds to seconds
previousValues: {
connectionType: prev.connectionType,
provider: prev.provider,
Expand Down
25 changes: 23 additions & 2 deletions redisinsight/api/src/modules/database/database.controller.ts
Expand Up @@ -75,7 +75,6 @@ export class DatabaseController {
}

@UseInterceptors(ClassSerializerInterceptor)
@UseInterceptors(new TimeoutInterceptor(ERROR_MESSAGES.CONNECTION_TIMEOUT))
@Post('')
@ApiEndpoint({
description: 'Add database instance',
Expand Down Expand Up @@ -158,6 +157,29 @@ export class DatabaseController {
return await this.service.update(id, database, true);
}

@UseInterceptors(ClassSerializerInterceptor)
@Post('/test')
@ApiEndpoint({
description: 'Test connection',
statusCode: 200,
responses: [
{
status: 200,
},
],
})
@UsePipes(
new ValidationPipe({
transform: true,
whitelist: true,
}),
)
async testConnection(
@Body() database: CreateDatabaseDto,
): Promise<void> {
return await this.service.testConnection(database);
}

@Delete('/:id')
@ApiEndpoint({
statusCode: 200,
Expand Down Expand Up @@ -189,7 +211,6 @@ export class DatabaseController {
}

@Get(':id/connect')
@UseInterceptors(new TimeoutInterceptor(ERROR_MESSAGES.CONNECTION_TIMEOUT))
@ApiEndpoint({
description: 'Connect to database instance by id',
statusCode: 200,
Expand Down
12 changes: 11 additions & 1 deletion redisinsight/api/src/modules/database/database.module.ts
@@ -1,5 +1,5 @@
import config from 'src/utils/config';
import { Module, Type } from '@nestjs/common';
import { MiddlewareConsumer, Module, RequestMethod, Type } from '@nestjs/common';
import { DatabaseService } from 'src/modules/database/database.service';
import { DatabaseController } from 'src/modules/database/database.controller';
import { DatabaseRepository } from 'src/modules/database/repositories/database.repository';
Expand All @@ -12,6 +12,7 @@ import { DatabaseInfoController } from 'src/modules/database/database-info.contr
import { DatabaseInfoService } from 'src/modules/database/database-info.service';
import { DatabaseOverviewProvider } from 'src/modules/database/providers/database-overview.provider';
import { StackDatabasesRepository } from 'src/modules/database/repositories/stack.databases.repository';
import { ConnectionMiddleware } from './middleware/connection.middleware';

const SERVER_CONFIG = config.get('server');

Expand Down Expand Up @@ -51,6 +52,15 @@ export class DatabaseModule {
],
};
}
configure(consumer: MiddlewareConsumer): any {
consumer
.apply(ConnectionMiddleware)
.forRoutes(
{ path: 'databases', method: RequestMethod.POST },
{ path: 'databases/test', method: RequestMethod.POST },
{ path: 'databases/:id/connect', method: RequestMethod.GET },
);
}
// todo: check if still needed
// configure(consumer: MiddlewareConsumer): any {
// consumer
Expand Down