Skip to content

Commit 6d63aa3

Browse files
committed
feat postgres: move schemas to separate files
Tests: протестировано CI commit_hash:1080bd10cbb02dc25c578da7cfb1b39da78e9395
1 parent cba4f06 commit 6d63aa3

File tree

6 files changed

+198
-184
lines changed

6 files changed

+198
-184
lines changed

.mapping.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,6 +3365,7 @@
33653365
"postgresql/src/storages/postgres/cluster.cpp":"taxi/uservices/userver/postgresql/src/storages/postgres/cluster.cpp",
33663366
"postgresql/src/storages/postgres/cluster_types.cpp":"taxi/uservices/userver/postgresql/src/storages/postgres/cluster_types.cpp",
33673367
"postgresql/src/storages/postgres/component.cpp":"taxi/uservices/userver/postgresql/src/storages/postgres/component.cpp",
3368+
"postgresql/src/storages/postgres/component.yaml":"taxi/uservices/userver/postgresql/src/storages/postgres/component.yaml",
33683369
"postgresql/src/storages/postgres/congestion_control/limiter.cpp":"taxi/uservices/userver/postgresql/src/storages/postgres/congestion_control/limiter.cpp",
33693370
"postgresql/src/storages/postgres/congestion_control/limiter.hpp":"taxi/uservices/userver/postgresql/src/storages/postgres/congestion_control/limiter.hpp",
33703371
"postgresql/src/storages/postgres/congestion_control/sensor.cpp":"taxi/uservices/userver/postgresql/src/storages/postgres/congestion_control/sensor.cpp",
@@ -3410,6 +3411,7 @@
34103411
"postgresql/src/storages/postgres/detail/topology/standalone.hpp":"taxi/uservices/userver/postgresql/src/storages/postgres/detail/topology/standalone.hpp",
34113412
"postgresql/src/storages/postgres/detail/tracing_tags.hpp":"taxi/uservices/userver/postgresql/src/storages/postgres/detail/tracing_tags.hpp",
34123413
"postgresql/src/storages/postgres/dist_lock_component_base.cpp":"taxi/uservices/userver/postgresql/src/storages/postgres/dist_lock_component_base.cpp",
3414+
"postgresql/src/storages/postgres/dist_lock_component_base.yaml":"taxi/uservices/userver/postgresql/src/storages/postgres/dist_lock_component_base.yaml",
34133415
"postgresql/src/storages/postgres/dist_lock_strategy.cpp":"taxi/uservices/userver/postgresql/src/storages/postgres/dist_lock_strategy.cpp",
34143416
"postgresql/src/storages/postgres/dsn.cpp":"taxi/uservices/userver/postgresql/src/storages/postgres/dsn.cpp",
34153417
"postgresql/src/storages/postgres/exceptions.cpp":"taxi/uservices/userver/postgresql/src/storages/postgres/exceptions.cpp",

postgresql/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ userver_module(
5050
UBENCH_ENV POSTGRES_DSN_BENCH=postgresql://testsuite@localhost:15433/postgres
5151
DEPENDS core
5252
GENERATE_DYNAMIC_CONFIGS
53+
EMBED_FILES
54+
src/storages/postgres/component.yaml
55+
src/storages/postgres/dist_lock_component_base.yaml
5356
)
5457

5558
target_sources(${PROJECT_NAME} PRIVATE "${LIBPQ_VERSION_DIR}/userver_libpq_version.hpp")

postgresql/src/storages/postgres/component.cpp

Lines changed: 5 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include <dynamic_config/variables/POSTGRES_CONNECTION_PIPELINE_EXPERIMENT.hpp>
3232
#include <dynamic_config/variables/POSTGRES_OMIT_DESCRIBE_IN_EXECUTE.hpp>
3333

34+
#ifndef ARCADIA_ROOT
35+
#include "generated/src/storages/postgres/component.yaml.hpp" // Y_IGNORE
36+
#endif
37+
3438
USERVER_NAMESPACE_BEGIN
3539

3640
namespace components {
@@ -285,150 +289,7 @@ void Postgres::OnSecdistUpdate(const storages::secdist::SecdistConfig& secdist)
285289
}
286290

287291
yaml_config::Schema Postgres::GetStaticConfigSchema() {
288-
return yaml_config::MergeSchemas<ComponentBase>(R"(
289-
type: object
290-
description: PosgreSQL client component
291-
additionalProperties: false
292-
properties:
293-
dbalias:
294-
type: string
295-
description: name of the database in secdist config (if available)
296-
name_alias:
297-
type: string
298-
description: name alias to use in dynamic configs
299-
defaultDescription: name of the component
300-
dbconnection:
301-
type: string
302-
description: connection DSN string (used if no dbalias specified)
303-
blocking_task_processor:
304-
type: string
305-
description: name of task processor for background blocking operations
306-
defaultDescription: engine::current_task::GetBlockingTaskProcessor()
307-
max_replication_lag:
308-
type: string
309-
description: |
310-
replication lag limit for usable replicas. If a replica's lag exceeds this value, it stops receiving
311-
new requests
312-
defaultDescription: 60s
313-
min_pool_size:
314-
type: integer
315-
description: |
316-
number of connections created initially by this component instance to each of the provided PostgreSQL
317-
hosts. Connections are kept even without requests
318-
defaultDescription: 4
319-
max_pool_size:
320-
type: integer
321-
description: |
322-
maximum number of connections that can be created by this component instance to each of the provided
323-
PostgreSQL hosts for "connlimit_mode: manual". Should not be less than `min_pool_size`
324-
defaultDescription: 15
325-
sync-start:
326-
type: boolean
327-
description: perform initial connections synchronously
328-
defaultDescription: false
329-
dns_resolver:
330-
type: string
331-
description: server hostname resolver type (getaddrinfo or async)
332-
defaultDescription: 'async'
333-
enum:
334-
- getaddrinfo
335-
- async
336-
persistent-prepared-statements:
337-
type: boolean
338-
description: cache prepared statements or not
339-
defaultDescription: true
340-
statement-log-mode:
341-
type: string
342-
enum:
343-
- hide
344-
- show
345-
description: whether to log SQL statements in a span tag
346-
defaultDescription: show
347-
user-types-enabled:
348-
type: boolean
349-
description: disabling will disallow use of user-defined types
350-
defaultDescription: true
351-
check-user-types:
352-
type: boolean
353-
description: |
354-
cancel service start if some user types have not been loaded, which
355-
helps to detect missing migrations
356-
defaultDescription: false
357-
ignore_unused_query_params:
358-
type: boolean
359-
description: disable check for not-NULL query params that are not used in query
360-
defaultDescription: false
361-
max-ttl-sec:
362-
type: integer
363-
minimum: 1
364-
description: the maximum lifetime for connections
365-
discard-all-on-connect:
366-
type: boolean
367-
description: execute discard all on new connections
368-
defaultDescription: true
369-
deadline-propagation-enabled:
370-
type: boolean
371-
description: whether statement timeout is affected by deadline propagation
372-
defaultDescription: true
373-
monitoring-dbalias:
374-
type: string
375-
description: name of the database for monitorings
376-
defaultDescription: calculated from dbalias or dbconnection options
377-
max_prepared_cache_size:
378-
type: integer
379-
description: prepared statements cache size limit
380-
defaultDescription: 200
381-
max_statement_metrics:
382-
type: integer
383-
description: limit of exported metrics for named statements
384-
defaultDescription: 0
385-
error-injection:
386-
type: object
387-
description: error-injection options
388-
additionalProperties: false
389-
properties:
390-
enabled:
391-
type: boolean
392-
description: enable error injection
393-
defaultDescription: false
394-
probability:
395-
type: number
396-
description: thrown exception probability
397-
defaultDescription: 0
398-
verdicts:
399-
type: array
400-
description: possible injection verdicts
401-
defaultDescription: empty
402-
items:
403-
type: string
404-
description: what error injection hook may decide to do
405-
enum:
406-
- timeout
407-
- error
408-
- max-delay
409-
- random-delay
410-
max_queue_size:
411-
type: integer
412-
description: |
413-
maximum number of clients waiting for a connection. storages::postgres::PoolError is thrown if a new
414-
request exceeds this limit
415-
defaultDescription: 200
416-
pipeline_enabled:
417-
type: boolean
418-
description: turns on pipeline connection mode
419-
defaultDescription: false
420-
connecting_limit:
421-
type: integer
422-
description: |
423-
limit for concurrent establishing connections number per PostgreSQL host (0 - unlimited)
424-
defaultDescription: 0
425-
connlimit_mode:
426-
type: string
427-
enum:
428-
- auto
429-
- manual
430-
description: how to learn the `max_pool_size`
431-
)");
292+
return yaml_config::MergeSchemasFromResource<ComponentBase>("src/storages/postgres/component.yaml");
432293
}
433294

434295
} // namespace components
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
type: object
2+
description: PosgreSQL client component
3+
additionalProperties: false
4+
properties:
5+
dbalias:
6+
type: string
7+
description: name of the database in secdist config (if available)
8+
name_alias:
9+
type: string
10+
description: name alias to use in dynamic configs
11+
defaultDescription: name of the component
12+
dbconnection:
13+
type: string
14+
description: connection DSN string (used if no dbalias specified)
15+
blocking_task_processor:
16+
type: string
17+
description: name of task processor for background blocking operations
18+
defaultDescription: engine::current_task::GetBlockingTaskProcessor()
19+
max_replication_lag:
20+
type: string
21+
description: |
22+
replication lag limit for usable replicas. If a replica's lag exceeds this value, it stops receiving
23+
new requests
24+
defaultDescription: 60s
25+
min_pool_size:
26+
type: integer
27+
description: |
28+
number of connections created initially by this component instance to each of the provided PostgreSQL
29+
hosts. Connections are kept even without requests
30+
defaultDescription: 4
31+
max_pool_size:
32+
type: integer
33+
description: |
34+
maximum number of connections that can be created by this component instance to each of the provided
35+
PostgreSQL hosts for "connlimit_mode: manual". Should not be less than `min_pool_size`
36+
defaultDescription: 15
37+
sync-start:
38+
type: boolean
39+
description: perform initial connections synchronously
40+
defaultDescription: false
41+
dns_resolver:
42+
type: string
43+
description: server hostname resolver type (getaddrinfo or async)
44+
defaultDescription: 'async'
45+
enum:
46+
- getaddrinfo
47+
- async
48+
persistent-prepared-statements:
49+
type: boolean
50+
description: cache prepared statements or not
51+
defaultDescription: true
52+
statement-log-mode:
53+
type: string
54+
enum:
55+
- hide
56+
- show
57+
description: whether to log SQL statements in a span tag
58+
defaultDescription: show
59+
user-types-enabled:
60+
type: boolean
61+
description: disabling will disallow use of user-defined types
62+
defaultDescription: true
63+
check-user-types:
64+
type: boolean
65+
description: |
66+
cancel service start if some user types have not been loaded, which
67+
helps to detect missing migrations
68+
defaultDescription: false
69+
ignore_unused_query_params:
70+
type: boolean
71+
description: disable check for not-NULL query params that are not used in
72+
query
73+
defaultDescription: false
74+
max-ttl-sec:
75+
type: integer
76+
minimum: 1
77+
description: the maximum lifetime for connections
78+
discard-all-on-connect:
79+
type: boolean
80+
description: execute discard all on new connections
81+
defaultDescription: true
82+
deadline-propagation-enabled:
83+
type: boolean
84+
description: whether statement timeout is affected by deadline propagation
85+
defaultDescription: true
86+
monitoring-dbalias:
87+
type: string
88+
description: name of the database for monitorings
89+
defaultDescription: calculated from dbalias or dbconnection options
90+
max_prepared_cache_size:
91+
type: integer
92+
description: prepared statements cache size limit
93+
defaultDescription: 200
94+
max_statement_metrics:
95+
type: integer
96+
description: limit of exported metrics for named statements
97+
defaultDescription: 0
98+
error-injection:
99+
type: object
100+
description: error-injection options
101+
additionalProperties: false
102+
properties:
103+
enabled:
104+
type: boolean
105+
description: enable error injection
106+
defaultDescription: false
107+
probability:
108+
type: number
109+
description: thrown exception probability
110+
defaultDescription: 0
111+
verdicts:
112+
type: array
113+
description: possible injection verdicts
114+
defaultDescription: empty
115+
items:
116+
type: string
117+
description: what error injection hook may decide to do
118+
enum:
119+
- timeout
120+
- error
121+
- max-delay
122+
- random-delay
123+
max_queue_size:
124+
type: integer
125+
description: |
126+
maximum number of clients waiting for a connection. storages::postgres::PoolError is thrown if a new
127+
request exceeds this limit
128+
defaultDescription: 200
129+
pipeline_enabled:
130+
type: boolean
131+
description: turns on pipeline connection mode
132+
defaultDescription: false
133+
connecting_limit:
134+
type: integer
135+
description: |
136+
limit for concurrent establishing connections number per PostgreSQL host (0 - unlimited)
137+
defaultDescription: 0
138+
connlimit_mode:
139+
type: string
140+
enum:
141+
- auto
142+
- manual
143+
description: how to learn the `max_pool_size`

postgresql/src/storages/postgres/dist_lock_component_base.cpp

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <userver/testsuite/tasks.hpp>
88
#include <userver/yaml_config/merge_schemas.hpp>
99

10+
#ifndef ARCADIA_ROOT
11+
#include "generated/src/storages/postgres/dist_lock_component_base.yaml.hpp" // Y_IGNORE
12+
#endif
13+
1014
USERVER_NAMESPACE_BEGIN
1115

1216
namespace storages::postgres {
@@ -94,46 +98,8 @@ void DistLockComponentBase::AutostartDistLock() {
9498
void DistLockComponentBase::StopDistLock() { worker_->Stop(); }
9599

96100
yaml_config::Schema DistLockComponentBase::GetStaticConfigSchema() {
97-
return yaml_config::MergeSchemas<components::ComponentBase>(R"(
98-
type: object
99-
description: Base class for postgres-based distlock worker components
100-
additionalProperties: false
101-
properties:
102-
cluster:
103-
type: string
104-
description: postgres cluster name
105-
table:
106-
type: string
107-
description: table name to store distlocks
108-
lockname:
109-
type: string
110-
description: name of the lock
111-
lock-ttl:
112-
type: string
113-
description: TTL of the lock; must be at least as long as the duration between subsequent cancellation checks, otherwise brain split is possible
114-
pg-timeout:
115-
type: string
116-
description: timeout, must be less than lock-ttl/2
117-
restart-delay:
118-
type: string
119-
description: how much time to wait after failed task restart
120-
defaultDescription: 100ms
121-
autostart:
122-
type: boolean
123-
description: if true, start automatically after component load
124-
defaultDescription: true
125-
task-processor:
126-
type: string
127-
description: the name of the TaskProcessor for running DoWork
128-
defaultDescription: main-task-processor
129-
testsuite-support:
130-
type: boolean
131-
description: Enable testsuite support
132-
defaultDescription: false
133-
locker-log-level:
134-
type: string
135-
description: Base logging level for locker logs (default is info)
136-
)");
101+
return yaml_config::MergeSchemasFromResource<
102+
components::ComponentBase>("src/storages/postgres/dist_lock_component_base.yaml");
137103
}
138104

139105
} // namespace storages::postgres

0 commit comments

Comments
 (0)