Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d7313e1

Browse files
AdrinlolNikolayS
authored andcommitted
feat(ui): add DLE config presets (#515)
1 parent 167979f commit d7313e1

File tree

32 files changed

+1125
-355
lines changed

32 files changed

+1125
-355
lines changed

‎engine/api/swagger-spec/dblab_server_swagger.yaml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,10 @@ paths:
720720
responses:
721721
200:
722722
description: "Successful operation"
723+
content:
724+
application/json:
725+
schema:
726+
$ref: "#/components/schemas/TestConnectionResponse"
723727
400:
724728
description: Bad request
725729
content:
@@ -1230,6 +1234,23 @@ components:
12301234
items:
12311235
type: "string"
12321236

1237+
TestConnectionResponse:
1238+
type: "object"
1239+
properties:
1240+
status:
1241+
type: "string"
1242+
result:
1243+
type: "string"
1244+
message:
1245+
type: "string"
1246+
dbVersion:
1247+
type: "integer"
1248+
required: false
1249+
tuningParams:
1250+
type: "object"
1251+
additionalProperties:
1252+
type: "string"
1253+
12331254
WSToken:
12341255
type: "object"
12351256
properties:

‎engine/internal/retrieval/engine/postgres/tools/db/pg.go‎

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ const (
2727
availableDBsTemplate = `select datname from pg_catalog.pg_database
2828
where not datistemplate and has_database_privilege('%s', datname, 'CONNECT')`
2929

30+
dbVersionQuery = `select setting::integer/10000 from pg_settings where name = 'server_version_num'`
31+
32+
tuningParamsQuery = `select
33+
name, setting
34+
from
35+
pg_settings
36+
where
37+
source <> 'default'
38+
and (
39+
name ~ '(work_mem$|^enable_|_cost$|scan_size$|effective_cache_size|^jit)'
40+
or name ~ '(^geqo|default_statistics_target|constraint_exclusion|cursor_tuple_fraction)'
41+
or name ~ '(collapse_limit$|parallel|plan_cache_mode)'
42+
)`
43+
3044
// maxNumberVerifiedDBs defines the maximum number of databases to verify availability as a database source.
3145
// The DB source instance can contain a large number of databases, so the verification will take a long time.
3246
// Therefore, we introduced a limit on the maximum number of databases to check for suitability as a source.
@@ -50,6 +64,11 @@ type locale struct {
5064
ctype string
5165
}
5266

67+
type tuningParam struct {
68+
name string
69+
setting string
70+
}
71+
5372
// ConnectionString builds PostgreSQL connection string.
5473
func ConnectionString(host, port, username, dbname, password string) string {
5574
return fmt.Sprintf("host=%s port=%s user='%s' database='%s' password='%s'", host, port, username, dbname, password)
@@ -114,10 +133,22 @@ func CheckSource(ctx context.Context, conf *models.ConnectionTest, imageContent
114133
return tcResponse, nil
115134
}
116135

136+
dbVersion, err := getMajorVersion(ctx, conn)
137+
if err != nil {
138+
return nil, err
139+
}
140+
141+
tuningParameters, err := getTuningParameters(ctx, conn)
142+
if err != nil {
143+
return nil, err
144+
}
145+
117146
return &models.TestConnection{
118-
Status: models.TCStatusOK,
119-
Result: models.TCResultOK,
120-
Message: models.TCMessageOK,
147+
Status: models.TCStatusOK,
148+
Result: models.TCResultOK,
149+
Message: models.TCMessageOK,
150+
DBVersion: dbVersion,
151+
TuningParams: tuningParameters,
121152
}, nil
122153
}
123154

@@ -352,3 +383,36 @@ func buildLocalesWarningMessage(dbName string, missingLocales []locale) string {
352383

353384
return sb.String()
354385
}
386+
387+
func getMajorVersion(ctx context.Context, conn *pgx.Conn) (int, error) {
388+
var majorVersion int
389+
390+
row := conn.QueryRow(ctx, dbVersionQuery)
391+
392+
if err := row.Scan(&majorVersion); err != nil {
393+
return 0, fmt.Errorf("failed to perform query detecting major version: %w", err)
394+
}
395+
396+
return majorVersion, nil
397+
}
398+
399+
func getTuningParameters(ctx context.Context, conn *pgx.Conn) (map[string]string, error) {
400+
rows, err := conn.Query(ctx, tuningParamsQuery)
401+
if err != nil {
402+
return nil, fmt.Errorf("failed to perform query detecting query tuning params: %w", err)
403+
}
404+
405+
var tuningParams = make(map[string]string)
406+
407+
for rows.Next() {
408+
var param tuningParam
409+
410+
if err := rows.Scan(&param.name, &param.setting); err != nil {
411+
return nil, fmt.Errorf("failed to scan query tuning params: %w", err)
412+
}
413+
414+
tuningParams[param.name] = param.setting
415+
}
416+
417+
return tuningParams, nil
418+
}

‎engine/pkg/models/admin.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ const (
3737

3838
// TestConnection represents the response of the test connection request.
3939
type TestConnection struct {
40-
Status string `json:"status"`
41-
Result string `json:"result"`
42-
Message string `json:"message"`
40+
Status string `json:"status"`
41+
Result string `json:"result"`
42+
Message string `json:"message"`
43+
DBVersion int `json:"dbVersion,omitempty"`
44+
TuningParams map[string]string `json:"tuningParams"`
4345
}

‎engine/pkg/models/configuration.go‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@ type ConnectionTest struct {
1212

1313
// ConfigProjection is a projection of the configuration.
1414
type ConfigProjection struct {
15-
Debug *bool `proj:"global.debug"`
16-
SharedBuffers *string `proj:"databaseConfigs.configs.shared_buffers"`
17-
SharedPreloadLibraries *string `proj:"databaseConfigs.configs.shared_preload_libraries"`
18-
DockerImage *string `proj:"databaseContainer.dockerImage"`
19-
Timetable *string `proj:"retrieval.refresh.timetable"`
20-
DBName *string `proj:"retrieval.spec.logicalDump.options.source.connection.dbname"`
21-
Host *string `proj:"retrieval.spec.logicalDump.options.source.connection.host"`
22-
Password *string `proj:"retrieval.spec.logicalDump.options.source.connection.password" groups:"sensitive"`
23-
Port *int64 `proj:"retrieval.spec.logicalDump.options.source.connection.port"`
24-
Username *string `proj:"retrieval.spec.logicalDump.options.source.connection.username"`
25-
DBList map[string]interface{} `proj:"retrieval.spec.logicalDump.options.databases,createKey"`
26-
DumpParallelJobs *int64 `proj:"retrieval.spec.logicalDump.options.parallelJobs"`
27-
RestoreParallelJobs *int64 `proj:"retrieval.spec.logicalRestore.options.parallelJobs"`
28-
DumpCustomOptions []interface{} `proj:"retrieval.spec.logicalDump.options.customOptions"`
29-
RestoreCustomOptions []interface{} `proj:"retrieval.spec.logicalRestore.options.customOptions"`
30-
IgnoreDumpErrors *bool `proj:"retrieval.spec.logicalDump.options.ignoreErrors"`
31-
IgnoreRestoreErrors *bool `proj:"retrieval.spec.logicalRestore.options.ignoreErrors"`
15+
Debug *bool `proj:"global.debug"`
16+
DatabaseConfigs map[string]interface{} `proj:"databaseConfigs.configs"`
17+
DockerImage *string `proj:"databaseContainer.dockerImage"`
18+
Timetable *string `proj:"retrieval.refresh.timetable"`
19+
DBName *string `proj:"retrieval.spec.logicalDump.options.source.connection.dbname"`
20+
Host *string `proj:"retrieval.spec.logicalDump.options.source.connection.host"`
21+
Password *string `proj:"retrieval.spec.logicalDump.options.source.connection.password" groups:"sensitive"`
22+
Port *int64 `proj:"retrieval.spec.logicalDump.options.source.connection.port"`
23+
Username *string `proj:"retrieval.spec.logicalDump.options.source.connection.username"`
24+
DBList map[string]interface{} `proj:"retrieval.spec.logicalDump.options.databases,createKey"`
25+
DumpParallelJobs *int64 `proj:"retrieval.spec.logicalDump.options.parallelJobs"`
26+
RestoreParallelJobs *int64 `proj:"retrieval.spec.logicalRestore.options.parallelJobs"`
27+
DumpCustomOptions []interface{} `proj:"retrieval.spec.logicalDump.options.customOptions"`
28+
RestoreCustomOptions []interface{} `proj:"retrieval.spec.logicalRestore.options.customOptions"`
29+
IgnoreDumpErrors *bool `proj:"retrieval.spec.logicalDump.options.ignoreErrors"`
30+
IgnoreRestoreErrors *bool `proj:"retrieval.spec.logicalRestore.options.ignoreErrors"`
3231
}

‎engine/test/2.logical_generic.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ PATCH_CONFIG_DATA=$(jq -n -c \
183183
"databaseConfigs": {
184184
"configs": {
185185
"shared_buffers": "256MB",
186-
"shared_preload_libraries": $spl
186+
"shared_preload_libraries": $spl,
187+
"log_directory": "log"
187188
}
188189
},
189190
"databaseContainer": {

‎ui/packages/ce/src/App/Instance/Page/index.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { getWSToken } from 'api/engine/getWSToken'
1212
import { initWS } from 'api/engine/initWS'
1313
import { getConfig } from 'api/configs/getConfig'
1414
import { getFullConfig } from 'api/configs/getFullConfig'
15+
import { getSeImages } from 'api/configs/getSeImages'
1516
import { updateConfig } from 'api/configs/updateConfig'
1617
import { testDbSource } from 'api/configs/testDbSource'
1718
import { getEngine } from 'api/engine/getEngine'
@@ -32,6 +33,7 @@ export const Page = () => {
3233
getWSToken,
3334
getConfig,
3435
getFullConfig,
36+
getSeImages,
3537
updateConfig,
3638
testDbSource,
3739
initWS,

‎ui/packages/ce/src/App/Menu/StickyTopBar/styles.module.scss‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
padding: 4px;
1313
font-size: 12px;
1414
z-index: 1000;
15+
flex-wrap: wrap;
1516
}
1617

1718
.activateBtn {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { request } from 'helpers/request'
2+
3+
export const getSeImages = async ({
4+
packageGroup,
5+
platformUrl,
6+
}: {
7+
packageGroup: string
8+
platformUrl?: string
9+
}) => {
10+
const response = await request(
11+
`/dblab_se_images?package_group=eq.${packageGroup}
12+
`,
13+
{},
14+
platformUrl,
15+
)
16+
17+
return {
18+
response: response.ok ? await response.json() : null,
19+
error: response.ok ? null : response,
20+
}
21+
}

‎ui/packages/ce/src/api/configs/testDbSource.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ export const testDbSource = async (req: dbSource) => {
1616

1717
return {
1818
response: response.ok ? await response.json(): null,
19-
error: response.ok ? null : response,
19+
error: response.ok ? null : awaitresponse.json()
2020
}
2121
}

‎ui/packages/ce/src/api/configs/updateConfig.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ export const updateConfig = async (req: Config) => {
1313
debug: req.debug,
1414
},
1515
databaseContainer: {
16-
dockerImage: req.dockerImage,
16+
dockerImage: req.dockerPath,
1717
},
1818
databaseConfigs: {
1919
configs: {
2020
shared_buffers: req.sharedBuffers,
2121
shared_preload_libraries: req.sharedPreloadLibraries,
22+
...(req.tuningParams as unknown as { [key: string]: string }),
2223
},
2324
},
2425
retrieval: {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /