Skip to content

Commit e7c7a42

Browse files
committed
feat docs: use schemas for documentation in more cases
Tests: протестировано в CI, проверено локально что все поля отображаются и форматируются приятно для глаза (или хотя бы как было раньше) commit_hash:3e27bfb18588c398d9ec65eccdcf515415fdee09
1 parent 0078639 commit e7c7a42

File tree

6 files changed

+64
-114
lines changed

6 files changed

+64
-114
lines changed

postgresql/include/userver/storages/postgres/component.hpp

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ USERVER_NAMESPACE_BEGIN
1818

1919
namespace components {
2020

21-
// clang-format off
22-
2321
/// @ingroup userver_components
2422
///
2523
/// @brief PosgreSQL client component
@@ -117,33 +115,11 @@ namespace components {
117115
/// Please see [PostgreSQL documentation](https://www.postgresql.org/docs/12/libpq-connect.html#LIBPQ-CONNSTRING)
118116
/// on connection strings.
119117
///
120-
/// ## Static options:
121-
/// Name | Description | Default value
122-
/// ----------------------- | ----------------------------------------------------------------------------- | -------------
123-
/// dbalias | name of the database in secdist config (if available) | --
124-
/// name_alias | name alias to use in dynamic configs | name of the component
125-
/// dbconnection | connection DSN string (used if no dbalias specified) | --
126-
/// blocking_task_processor | name of task processor for background blocking operations | engine::current_task::GetBlockingTaskProcessor()
127-
/// max_replication_lag | replication lag limit for usable replicas. If a replica's lag exceeds this value, it stops receiving new requests | 60s
128-
/// sync-start | perform initial connections synchronously | true
129-
/// dns_resolver | server hostname resolver type (getaddrinfo or async) | 'async'
130-
/// persistent-prepared-statements | cache prepared statements or not | true
131-
/// user-types-enabled | allow use of user-defined types | true
132-
/// check-user-types | cancel service start if some user types have not been loaded, which helps to detect missing migrations | false
133-
/// ignore_unused_query_params| disable check for not-NULL query params that are not used in query | false
134-
/// monitoring-dbalias | name of the database for monitorings | calculated from dbalias or dbconnection options
135-
/// max_prepared_cache_size | prepared statements cache size limit | 200
136-
/// max_statement_metrics | limit of exported metrics for named statements | 0
137-
/// min_pool_size | number of connections created initially by this component instance to each of the provided PostgreSQL hosts. Connections are kept even without requests | 4
138-
/// max_pool_size | maximum number of connections that can be created by this component instance to each of the provided hosts for "connlimit_mode: manual". Should not be less than `min_pool_size` | 15
139-
/// max_queue_size | maximum number of clients waiting for a connection. storages::postgres::PoolError is thrown if a new request exceeds this limit. | 200
140-
/// connecting_limit | limit for concurrent establishing connections number per PostgreSQL host (0 - unlimited) | 0
141-
/// connlimit_mode | max_connections setup mode (manual or auto), also see @ref scripts/docs/en/userver/pg_connlimit_mode_auto.md | auto
142-
/// error-injection | artificial error injection settings, error_injection::Settings | --
143-
/// deadline-propagation-enabled | whether deadline propagation sets statement timeout | true
144-
145-
// clang-format on
146-
118+
/// ## Static options of @ref components::Postgres :
119+
/// @include{doc} scripts/docs/en/components_schema/postgresql/src/storages/postgres/component.md
120+
///
121+
/// Options inherited from @ref components::ComponentBase :
122+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
147123
class Postgres : public ComponentBase {
148124
public:
149125
/// Default shard number

postgresql/include/userver/storages/postgres/dist_lock_component_base.hpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ USERVER_NAMESPACE_BEGIN
1414

1515
namespace storages::postgres {
1616

17-
// clang-format off
18-
1917
/// @ingroup userver_components userver_base_classes
2018
///
2119
/// @brief Base class for postgres-based distlock worker components
@@ -43,18 +41,11 @@ namespace storages::postgres {
4341
/// ```
4442
/// See config `POSTGRES_DISTLOCK_SETTINGS`, some of parameters can be dynamically overridden.
4543
///
46-
/// ## Static options:
47-
/// name | Description | Default value
48-
/// -------------- | ------------ | -------------
49-
/// cluster | postgres cluster name | --
50-
/// table | table name to store distlocks | --
51-
/// lockname | name of the lock | --
52-
/// lock-ttl | TTL of the lock; must be at least as long as the duration between subsequent cancellation checks, otherwise brain split is possible | --
53-
/// pg-timeout | timeout, must be less than lock-ttl/2 | --
54-
/// restart-delay | how much time to wait after failed task restart | 100ms
55-
/// autostart | if true, start automatically after component load | false
56-
/// task-processor | the name of the TaskProcessor for running DoWork | main-task-processor
57-
/// testsuite-support | Enable testsuite support | false
44+
/// ## Static options of @ref storages::postgres::DistLockComponentBase :
45+
/// @include{doc} scripts/docs/en/components_schema/postgresql/src/storages/postgres/dist_lock_component_base.md
46+
///
47+
/// Options inherited from @ref components::ComponentBase :
48+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
5849
///
5950
/// ## Migration example
6051
///
@@ -71,9 +62,6 @@ namespace storages::postgres {
7162
/// ```
7263
///
7364
/// @see @ref scripts/docs/en/userver/periodics.md
74-
75-
// clang-format on
76-
7765
class DistLockComponentBase : public components::ComponentBase {
7866
public:
7967
DistLockComponentBase(const components::ComponentConfig&, const components::ComponentContext&);

redis/include/userver/storages/redis/component.hpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class ThreadPools;
3636

3737
namespace components {
3838

39-
// clang-format off
40-
4139
/// @ingroup userver_components
4240
///
4341
/// @brief Valkey and Redis client component
@@ -55,20 +53,11 @@ namespace components {
5553
/// * @ref REDIS_SUBSCRIPTIONS_REBALANCE_MIN_INTERVAL_SECONDS
5654
/// * @ref REDIS_WAIT_CONNECTED
5755
///
58-
/// ## Static options:
59-
/// Name | Description | Default value
60-
/// ---- | ----------- | -------------
61-
/// thread_pools.redis_thread_pool_size | thread count to serve Redis requests | -
62-
/// thread_pools.sentinel_thread_pool_size | thread count to serve sentinel requests. | -
63-
/// groups | array of redis clusters to work with excluding subscribers | -
64-
/// groups.[].config_name | key name in secdist with options for this cluster | -
65-
/// groups.[].db | name to refer to the cluster in components::Redis::GetClient() | -
66-
/// groups.[].sharding_strategy | one of RedisCluster, RedisStandalone, KeyShardCrc32, KeyShardTaximeterCrc32 or KeyShardGpsStorageDriver | "KeyShardTaximeterCrc32"
67-
/// groups.[].allow_reads_from_master | allows read requests from master instance | false
68-
/// subscribe_groups | array of redis clusters to work with in subscribe mode | -
69-
/// subscribe_groups.[].config_name | key name in secdist with options for this cluster | -
70-
/// subscribe_groups.[].db | name to refer to the cluster in components::Redis::GetSubscribeClient() | -
71-
/// subscribe_groups.[].sharding_strategy | either RedisCluster or KeyShardTaximeterCrc32 | "KeyShardTaximeterCrc32"
56+
/// ## Static options of @ref components::Redis :
57+
/// @include{doc} scripts/docs/en/components_schema/redis/src/storages/redis/component.md
58+
///
59+
/// Options inherited from @ref components::ComponentBase :
60+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
7261
///
7362
/// ## Static configuration example:
7463
///
@@ -131,8 +120,6 @@ namespace components {
131120
/// 1. `"shards"` field is ignored, you can specify an empty array there;
132121
/// 2. `"sentinels"` field should contain some of the cluster nodes. They are
133122
/// only used for topology discovery; it is not necessary to list all nodes.
134-
135-
// clang-format on
136123
class Redis : public ComponentBase {
137124
public:
138125
Redis(const ComponentConfig& config, const ComponentContext& component_context);

scripts/docs/components_schema_to_table.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,52 @@ def normalize_default_value(data) -> str:
1818
return data
1919

2020

21+
def visit_object(yaml, prefix: str = ''):
22+
properties = yaml.get('properties', {})
23+
24+
for key, value in properties.items():
25+
if value.get('type') == 'array':
26+
if value['items'].get('type') == 'object':
27+
yield from visit_object(value['items'], prefix + key + '.[].')
28+
elif value.get('description') and value['items'].get('description'):
29+
description = value['description'].strip()
30+
if not description.endswith('.'):
31+
description += '.'
32+
description += ' Each of the array elements: ' + value['items']['description']
33+
34+
value_cloned = value.copy()
35+
value_cloned['description'] = description
36+
yield (prefix + key + '.[]', value_cloned)
37+
elif value.get('description'):
38+
yield (prefix + key + '.[]', value)
39+
else:
40+
yield (prefix + key + '.[]', value['items'])
41+
elif value.get('type') == 'object':
42+
yield from visit_object(value, prefix + key + '.')
43+
else:
44+
yield (prefix + key, value)
45+
46+
additionals = yaml.get('additionalProperties')
47+
if additionals is True:
48+
yield (prefix + '*', yaml)
49+
elif additionals:
50+
yield from visit_object(yaml['additionalProperties'], prefix + '*.')
51+
52+
2153
def format_schema(yaml) -> str:
2254
result = ''
23-
properties = yaml.get('properties', {})
24-
if not properties:
55+
key_values = list(visit_object(yaml))
56+
if not key_values:
2557
result += 'No options'
2658
return result
2759

28-
max_key_size = max(len(key) for key in properties.keys())
29-
max_value_size = max(len(value['description']) for value in properties.values())
60+
max_key_size = max(len(key) for key, _ in key_values)
61+
max_value_size = max(len(value['description']) for _, value in key_values)
3062

3163
result += f'{"Name":{max_key_size}} | {"Description":{max_value_size}} | Default value\n'
3264
result += f'{"":-<{max_key_size}} | {"":-<{max_value_size}} | {"":-<16}\n'
3365

34-
for key, value in properties.items():
66+
for key, value in key_values:
3567
key = key.replace('\n', ' ')
3668
description = value['description'].replace('\n', ' ')
3769
default = normalize_default_value(value.get('defaultDescription', '--'))

ydb/include/userver/ydb/component.hpp

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,18 @@ namespace impl {
2525
class Driver;
2626
} // namespace impl
2727

28-
// clang-format off
29-
3028
/// @ingroup userver_components
3129
///
3230
/// @brief YDB client component
3331
///
34-
/// Provides access to ydb::TableClient, ydb::TopicClient, ydb::FederatedTopicClient, ydb::CoordinationClient.
32+
/// Provides access to @ref ydb::TableClient, @ref ydb::TopicClient, @ref ydb::FederatedTopicClient,
33+
/// @ref ydb::CoordinationClient.
3534
///
36-
/// ## Static options:
37-
/// Name | Description | Default value
38-
/// ---- | ----------- | -------------
39-
/// `credentials-provider` | name of credentials provider component | -
40-
/// `operation-settings.retries` | default retries count for an operation | 3
41-
/// `operation-settings.operation-timeout` | default operation timeout in utils::StringToDuration() format | 1s
42-
/// `operation-settings.cancel-after` | cancel operation after specified string in utils::StringToDuration() format | 1s
43-
/// `operation-settings.client-timeout` | default client timeout in utils::StringToDuration() format | 1s
44-
/// `operation-settings.get-session-timeout` | default session timeout in milliseconds | 5s
45-
/// `databases.<dbname>.endpoint` | gRPC endpoint URL, e.g. grpc://localhost:1234 | -
46-
/// `databases.<dbname>.database` | full database path, e.g. /ru/service/production/database | -
47-
/// `databases.<dbname>.credentials` | credentials config passed to credentials provider component | -
48-
/// `databases.<dbname>.min_pool_size` | minimum pool size for database with name `<dbname>` | 10
49-
/// `databases.<dbname>.max_pool_size` | maximum pool size for database with name `<dbname>` | 50
50-
/// `databases.<dbname>.get_session_retry_limit` | retries count to get session, every attempt with a get-session-timeout | 5
51-
/// `databases.<dbname>.keep-in-query-cache` | whether to use query cache | true
52-
/// `databases.<dbname>.prefer_local_dc` | prefer making requests to local DataCenter | false
53-
/// `databases.<dbname>.aliases` | list of alias names for this database | []
54-
/// `databases.<dbname>.sync_start` | fail on boot time if YDB is not accessible | true
55-
/// `databases.<dbname>.by-database-timings-buckets-ms` | histogram bounds for by-database timing metrics | 40 buckets with +20% increment per step
56-
/// `databases.<dbname>.by-query-timings-buckets-ms` | histogram bounds for by-query timing metrics | 15 buckets with +100% increment per step
57-
58-
// clang-format on
59-
35+
/// ## Static options of @ref ydb::YdbComponent :
36+
/// @include{doc} scripts/docs/en/components_schema/ydb/src/ydb/component.md
37+
///
38+
/// Options inherited from @ref components::ComponentBase :
39+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
6040
class YdbComponent final : public components::ComponentBase {
6141
public:
6242
/// @ingroup userver_component_names

ydb/include/userver/ydb/dist_lock/component_base.hpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class TestsuiteTasks;
1818

1919
namespace ydb {
2020

21-
// clang-format off
22-
2321
/// @ingroup userver_components userver_base_classes
2422
///
2523
/// @brief Base class for YDB-based distlock worker components
@@ -34,24 +32,13 @@ namespace ydb {
3432
///
3533
/// @snippet ydb/functional_tests/basic/static_config.yaml sample-dist-lock
3634
///
37-
/// ## Static options:
38-
/// name | Description | Default value
39-
/// -------------- | ------------ | -------------
40-
/// semaphore-name | name of the semaphore within the coordination node | --
41-
/// database-settings.dbname | the key of the database within ydb component (NOT the actual database path) | --
42-
/// database-settings.coordination-node | name of the coordination node within the database | --
43-
/// initial-setup | if true, then create the coordination node and the semaphore unless they already exist | true
44-
/// task-processor | the name of the TaskProcessor for running DoWork | main-task-processor
45-
/// node-settings.session-grace-period | the time after which the lock will be given to another host after a network failure | 10s
46-
/// session-timeout | for how long we will try to restore session after a network failure before dropping it | 5s
47-
/// restart-session-delay | backoff before attempting to reconnect session after it returns "permanent failure" | 1s
48-
/// acquire-interval | backoff before repeating a failed Acquire call | 100ms
49-
/// restart-delay | backoff before calling DoWork again after it returns or throws | 100ms
50-
/// cancel-task-time-limit | time, within which a cancelled DoWork is expected to finish | 5s
35+
/// ## Static options of @ref ydb::DistLockComponentBase :
36+
/// @include{doc} scripts/docs/en/components_schema/ydb/src/ydb/dist_lock/component_base.md
37+
///
38+
/// Options inherited from @ref components::ComponentBase :
39+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
5140
///
5241
/// @see @ref scripts/docs/en/userver/periodics.md
53-
54-
// clang-format on
5542
class DistLockComponentBase : public components::ComponentBase {
5643
public:
5744
DistLockComponentBase(const components::ComponentConfig&, const components::ComponentContext&);

0 commit comments

Comments
 (0)