Skip to content

Commit cba4f06

Browse files
committed
feat mongo: move schemas to separate files
Tests: протестировано CI commit_hash:077ca06178693bf06362e18a869a5fb62bb7ae01
1 parent 997a9c4 commit cba4f06

File tree

7 files changed

+132
-116
lines changed

7 files changed

+132
-116
lines changed

.mapping.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,6 +3013,8 @@
30133013
"mongo/src/storages/mongo/collection_mongotest.cpp":"taxi/uservices/userver/mongo/src/storages/mongo/collection_mongotest.cpp",
30143014
"mongo/src/storages/mongo/collection_mongotest.hpp":"taxi/uservices/userver/mongo/src/storages/mongo/collection_mongotest.hpp",
30153015
"mongo/src/storages/mongo/component.cpp":"taxi/uservices/userver/mongo/src/storages/mongo/component.cpp",
3016+
"mongo/src/storages/mongo/component.yaml":"taxi/uservices/userver/mongo/src/storages/mongo/component.yaml",
3017+
"mongo/src/storages/mongo/component_multi.yaml":"taxi/uservices/userver/mongo/src/storages/mongo/component_multi.yaml",
30163018
"mongo/src/storages/mongo/congestion_control/limiter.cpp":"taxi/uservices/userver/mongo/src/storages/mongo/congestion_control/limiter.cpp",
30173019
"mongo/src/storages/mongo/congestion_control/limiter.hpp":"taxi/uservices/userver/mongo/src/storages/mongo/congestion_control/limiter.hpp",
30183020
"mongo/src/storages/mongo/congestion_control/sensor.cpp":"taxi/uservices/userver/mongo/src/storages/mongo/congestion_control/sensor.cpp",
@@ -3023,6 +3025,7 @@
30233025
"mongo/src/storages/mongo/database.hpp":"taxi/uservices/userver/mongo/src/storages/mongo/database.hpp",
30243026
"mongo/src/storages/mongo/deadline_mongotest.cpp":"taxi/uservices/userver/mongo/src/storages/mongo/deadline_mongotest.cpp",
30253027
"mongo/src/storages/mongo/dist_lock_component_base.cpp":"taxi/uservices/userver/mongo/src/storages/mongo/dist_lock_component_base.cpp",
3028+
"mongo/src/storages/mongo/dist_lock_component_base.yaml":"taxi/uservices/userver/mongo/src/storages/mongo/dist_lock_component_base.yaml",
30263029
"mongo/src/storages/mongo/dist_lock_strategy.cpp":"taxi/uservices/userver/mongo/src/storages/mongo/dist_lock_strategy.cpp",
30273030
"mongo/src/storages/mongo/dist_lock_strategy_mongotest.cpp":"taxi/uservices/userver/mongo/src/storages/mongo/dist_lock_strategy_mongotest.cpp",
30283031
"mongo/src/storages/mongo/exception.cpp":"taxi/uservices/userver/mongo/src/storages/mongo/exception.cpp",

mongo/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ userver_module(
1919
UBENCH_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_benchmark.cpp"
2020
DEPENDS core
2121
GENERATE_DYNAMIC_CONFIGS
22+
EMBED_FILES
23+
src/storages/mongo/component.yaml
24+
src/storages/mongo/component_multi.yaml
25+
src/storages/mongo/dist_lock_component_base.yaml
26+
2227
)
2328

2429
_userver_directory_install(

mongo/src/storages/mongo/component.cpp

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
#include <storages/mongo/mongo_secdist.hpp>
1414

15+
#ifndef ARCADIA_ROOT
16+
#include "generated/src/storages/mongo/component.yaml.hpp" // Y_IGNORE
17+
#include "generated/src/storages/mongo/component_multi.yaml.hpp" // Y_IGNORE
18+
#endif
19+
1520
USERVER_NAMESPACE_BEGIN
1621

1722
namespace components {
@@ -85,22 +90,7 @@ void Mongo::OnSecdistUpdate(const storages::secdist::SecdistConfig& config) {
8590
}
8691

8792
yaml_config::Schema Mongo::GetStaticConfigSchema() {
88-
return yaml_config::MergeSchemas<MultiMongo>(R"(
89-
type: object
90-
description: MongoDB client component
91-
additionalProperties: false
92-
properties:
93-
dbalias:
94-
type: string
95-
description: name of the database in secdist config (if available)
96-
dbconnection:
97-
type: string
98-
description: connection string (used if no dbalias specified)
99-
maintenance_period:
100-
type: string
101-
description: pool maintenance period (idle connections pruning etc.)
102-
defaultDescription: 15s
103-
)");
93+
return yaml_config::MergeSchemasFromResource<MultiMongo>("src/storages/mongo/component.yaml");
10494
}
10595

10696
MultiMongo::MultiMongo(const ComponentConfig& config, const ComponentContext& context)
@@ -132,79 +122,7 @@ bool MultiMongo::RemovePool(const std::string& dbalias) { return multi_mongo_.Re
132122
storages::mongo::MultiMongo::PoolSet MultiMongo::NewPoolSet() { return multi_mongo_.NewPoolSet(); }
133123

134124
yaml_config::Schema MultiMongo::GetStaticConfigSchema() {
135-
return yaml_config::MergeSchemas<ComponentBase>(R"(
136-
type: object
137-
description: Dynamically configurable MongoDB client component
138-
additionalProperties: false
139-
properties:
140-
appname:
141-
type: string
142-
description: application name for the DB server
143-
defaultDescription: userver
144-
conn_timeout:
145-
type: string
146-
description: connection timeout
147-
defaultDescription: 2s
148-
so_timeout:
149-
type: string
150-
description: socket timeout
151-
defaultDescription: 10s
152-
queue_timeout:
153-
type: string
154-
description: max connection queue wait time
155-
defaultDescription: 1s
156-
initial_size:
157-
type: string
158-
description: number of connections created initially (per database)
159-
defaultDescription: 16
160-
max_size:
161-
type: integer
162-
description: limit for total connections number (per database)
163-
defaultDescription: 128
164-
idle_limit:
165-
type: integer
166-
description: limit for idle connections number (per database)
167-
defaultDescription: 64
168-
connecting_limit:
169-
type: integer
170-
description: limit for establishing connections number (per database)
171-
defaultDescription: 8
172-
local_threshold:
173-
type: string
174-
description: latency window for instance selection
175-
defaultDescription: mongodb default
176-
max_replication_lag:
177-
type: string
178-
description: replication lag limit for usable secondaries, min. 90s
179-
stats_verbosity:
180-
type: string
181-
description: changes the granularity of reported metrics
182-
defaultDescription: 'terse'
183-
enum:
184-
- terse
185-
- full
186-
- none
187-
dns_resolver:
188-
type: string
189-
description: server hostname resolver type (getaddrinfo or async)
190-
defaultDescription: 'async'
191-
enum:
192-
- getaddrinfo
193-
- async
194-
congestion_control:
195-
description: congestion control settings
196-
type: object
197-
additionalProperties: false
198-
properties:
199-
fake-mode:
200-
type: boolean
201-
description: whether CC limiter is actually working
202-
defaultDescription: false
203-
enabled:
204-
type: boolean
205-
description: whether CC is enabled for the database
206-
defaultDescription: true
207-
)");
125+
return yaml_config::MergeSchemasFromResource<ComponentBase>("src/storages/mongo/component_multi.yaml");
208126
}
209127

210128
} // namespace components
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
type: object
2+
description: MongoDB client component
3+
additionalProperties: false
4+
properties:
5+
dbalias:
6+
type: string
7+
description: name of the database in secdist config (if available)
8+
dbconnection:
9+
type: string
10+
description: connection string (used if no dbalias specified)
11+
maintenance_period:
12+
type: string
13+
description: pool maintenance period (idle connections pruning etc.)
14+
defaultDescription: 15s
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
type: object
2+
description: Dynamically configurable MongoDB client component
3+
additionalProperties: false
4+
properties:
5+
appname:
6+
type: string
7+
description: application name for the DB server
8+
defaultDescription: userver
9+
conn_timeout:
10+
type: string
11+
description: connection timeout
12+
defaultDescription: 2s
13+
so_timeout:
14+
type: string
15+
description: socket timeout
16+
defaultDescription: 10s
17+
queue_timeout:
18+
type: string
19+
description: max connection queue wait time
20+
defaultDescription: 1s
21+
initial_size:
22+
type: string
23+
description: number of connections created initially (per database)
24+
defaultDescription: 16
25+
max_size:
26+
type: integer
27+
description: limit for total connections number (per database)
28+
defaultDescription: 128
29+
idle_limit:
30+
type: integer
31+
description: limit for idle connections number (per database)
32+
defaultDescription: 64
33+
connecting_limit:
34+
type: integer
35+
description: limit for establishing connections number (per database)
36+
defaultDescription: 8
37+
local_threshold:
38+
type: string
39+
description: latency window for instance selection
40+
defaultDescription: mongodb default
41+
max_replication_lag:
42+
type: string
43+
description: replication lag limit for usable secondaries, min. 90s
44+
stats_verbosity:
45+
type: string
46+
description: changes the granularity of reported metrics
47+
defaultDescription: 'terse'
48+
enum:
49+
- terse
50+
- full
51+
- none
52+
dns_resolver:
53+
type: string
54+
description: server hostname resolver type (getaddrinfo or async)
55+
defaultDescription: 'async'
56+
enum:
57+
- getaddrinfo
58+
- async
59+
congestion_control:
60+
description: congestion control settings
61+
type: object
62+
additionalProperties: false
63+
properties:
64+
fake-mode:
65+
type: boolean
66+
description: whether CC limiter is actually working
67+
defaultDescription: false
68+
enabled:
69+
type: boolean
70+
description: whether CC is enabled for the database
71+
defaultDescription: true

mongo/src/storages/mongo/dist_lock_component_base.cpp

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include <userver/utils/statistics/writer.hpp>
99
#include <userver/yaml_config/merge_schemas.hpp>
1010

11+
#ifndef ARCADIA_ROOT
12+
#include "generated/src/storages/mongo/dist_lock_component_base.yaml.hpp" // Y_IGNORE
13+
#endif
14+
1115
USERVER_NAMESPACE_BEGIN
1216

1317
namespace storages::mongo {
@@ -86,33 +90,8 @@ void DistLockComponentBase::Start() {
8690
void DistLockComponentBase::Stop() { worker_->Stop(); }
8791

8892
yaml_config::Schema DistLockComponentBase::GetStaticConfigSchema() {
89-
return yaml_config::MergeSchemas<components::ComponentBase>(R"(
90-
type: object
91-
description: Base class for mongo-based distlock worker components
92-
additionalProperties: false
93-
properties:
94-
lockname:
95-
type: string
96-
description: name of the lock
97-
lock-ttl:
98-
type: string
99-
description: TTL of the lock; must be at least as long as the duration between subsequent cancellation checks, otherwise brain split is possible
100-
mongo-timeout:
101-
type: string
102-
description: timeout, must be at least 2*lock-ttl
103-
restart-delay:
104-
type: string
105-
description: how much time to wait after failed task restart
106-
defaultDescription: 100ms
107-
task-processor:
108-
type: string
109-
description: the name of the TaskProcessor for running DoWork
110-
defaultDescription: main-task-processor
111-
testsuite-support:
112-
type: boolean
113-
description: Enable testsuite support
114-
defaultDescription: false
115-
)");
93+
return yaml_config::MergeSchemasFromResource<
94+
components::ComponentBase>("src/storages/mongo/dist_lock_component_base.yaml");
11695
}
11796

11897
} // namespace storages::mongo
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
type: object
2+
description: Base class for mongo-based distlock worker components
3+
additionalProperties: false
4+
properties:
5+
lockname:
6+
type: string
7+
description: name of the lock
8+
lock-ttl:
9+
type: string
10+
description: TTL of the lock; must be at least as long as the duration between
11+
subsequent cancellation checks, otherwise brain split is possible
12+
mongo-timeout:
13+
type: string
14+
description: timeout, must be at least 2*lock-ttl
15+
restart-delay:
16+
type: string
17+
description: how much time to wait after failed task restart
18+
defaultDescription: 100ms
19+
task-processor:
20+
type: string
21+
description: the name of the TaskProcessor for running DoWork
22+
defaultDescription: main-task-processor
23+
testsuite-support:
24+
type: boolean
25+
description: Enable testsuite support
26+
defaultDescription: false

0 commit comments

Comments
 (0)