Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ConfigDescription.hpp
1#pragma once
2
3#include "util/Assert.hpp"
4#include "util/config/ConfigDefinition.hpp"
5#include "util/config/Error.hpp"
6
7#include <fmt/format.h>
8
9#include <algorithm>
10#include <array>
11#include <cerrno>
12#include <cstring>
13#include <expected>
14#include <filesystem>
15#include <fstream>
16#include <iostream>
17#include <string_view>
18
19namespace util::config {
20
27public:
31 struct KV {
32 std::string_view key;
33 std::string_view value;
34 };
35
42 constexpr ClioConfigDescription() = default;
43
50 [[nodiscard]] static constexpr std::string_view
51 get(std::string_view key)
52 {
53 auto const itr =
54 std::ranges::find_if(kConfigDescription, [&](auto const& v) { return v.key == key; });
55 ASSERT(itr != kConfigDescription.end(), "Key {} doesn't exist in config", key);
56 return itr->value;
57 }
58
65 [[nodiscard]] static std::expected<void, Error>
66 generateConfigDescriptionToFile(std::filesystem::path path)
67 {
68 namespace fs = std::filesystem;
69
70 // Validate the directory exists
71 auto const dir = path.parent_path();
72 if (!dir.empty() && !fs::exists(dir)) {
73 return std::unexpected<Error>{fmt::format(
74 "Error: Directory '{}' does not exist or provided path is invalid", dir.string()
75 )};
76 }
77
78 std::ofstream file(path.string());
79 if (!file.is_open()) {
80 return std::unexpected{
81 fmt::format("Failed to create file '{}': {}", path.string(), std::strerror(errno))
82 };
83 }
84
86 file.close();
87
88 std::cout << "Markdown file generated successfully: " << path << "\n";
89 return {};
90 }
91
97 static void
98 writeConfigDescriptionToFile(std::ostream& file)
99 {
100 file << kConfigDescriptionHeader;
101
102 for (auto const& [key, val] : kConfigDescription) {
103 file << "\n### " << key << "\n\n";
104
105 // Every type of value is directed to operator<< in ConfigValue.hpp
106 // as ConfigValue is the one that holds all the info regarding the config values
107 if (key.contains("[]")) {
108 file << getClioConfig().asArray(key);
109 } else {
110 file << getClioConfig().getValueView(key);
111 }
112 file << "- **Description**: " << val << "\n";
113 }
114 }
115
116private:
117 static constexpr auto kConfigDescriptionHeader =
118 R"(# Clio Config Description
119
120This document provides a list of all available Clio configuration properties in detail.
121
122> [!NOTE]
123> Dot notation in configuration key names represents nested fields.
124> For example, **database.scylladb** refers to the _scylladb_ field inside the _database_ object.
125> If a key name includes "[]", it indicates that the nested field is an array (e.g., etl_sources.[]).
126
127## Configuration Details
128)";
129
130 static constexpr auto kConfigDescription = std::array{
131 KV{
132 .key = "database.type",
133 .value = "Specifies the type of database used for storing and retrieving data "
134 "required by the Clio server. Both ScyllaDB and Cassandra can serve as "
135 "backends for Clio; however, this value must be set to `cassandra`.",
136 },
137 KV{
138 .key = "database.cassandra.contact_points",
139 .value =
140 "A list of IP addresses or hostnames for the initial cluster nodes (Cassandra or "
141 "ScyllaDB) that the client connects to when establishing a database connection. "
142 "If you're running Clio locally, set this value to `localhost` or `127.0.0.1`.",
143 },
144 KV{
145 .key = "database.cassandra.secure_connect_bundle",
146 .value = "The configuration file that contains the necessary credentials and "
147 "connection details for securely connecting to a Cassandra database cluster.",
148 },
149 KV{
150 .key = "database.cassandra.port",
151 .value = "The port number used to connect to the Cassandra database.",
152 },
153 KV{
154 .key = "database.cassandra.keyspace",
155 .value = "The Cassandra keyspace to use for the database. If you don't provide a "
156 "value, this is set to `clio` by default.",
157 },
158 KV{
159 .key = "database.cassandra.replication_factor",
160 .value = "Represents the number of replicated nodes for ScyllaDB. For more details "
161 "see [Fault Tolerance Replication Factor](https://university.scylladb.com/"
162 "courses/scylla-essentials-overview/lessons/high-availability/topic/"
163 "fault-tolerance-replication-factor/).",
164 },
165 KV{
166 .key = "database.cassandra.table_prefix",
167 .value =
168 "An optional field to specify a prefix for the Cassandra database table names.",
169 },
170 KV{
171 .key = "database.cassandra.max_write_requests_outstanding",
172 .value = "Represents the maximum number of outstanding write requests. Write requests "
173 "are API calls that write to the database.",
174 },
175 KV{
176 .key = "database.cassandra.max_read_requests_outstanding",
177 .value = "Maximum number of outstanding read requests. Read requests are API calls "
178 "that read from the database.",
179 },
180 KV{
181 .key = "database.cassandra.threads",
182 .value = "Represents the number of threads that will be used for database operations.",
183 },
184 KV{
185 .key = "database.cassandra.provider",
186 .value = "The specific database backend provider we are using.",
187 },
188 KV{
189 .key = "database.cassandra.core_connections_per_host",
190 .value = "The number of core connections per host for the Cassandra database.",
191 },
192 KV{
193 .key = "database.cassandra.queue_size_io",
194 .value = "Defines the queue size of the input/output (I/O) operations in Cassandra.",
195 },
196 KV{
197 .key = "database.cassandra.write_batch_size",
198 .value = "Represents the batch size for write operations in Cassandra.",
199 },
200 KV{
201 .key = "database.cassandra.connect_timeout",
202 .value = "The maximum amount of time in seconds that the system waits for a database "
203 "connection to be established.",
204 },
205 KV{
206 .key = "database.cassandra.request_timeout",
207 .value = "The maximum amount of time in seconds that the system waits for a request "
208 "to be fetched from the database. Should be set higher than the server side "
209 "read timeout. If omitted, no request timeout is applied.",
210 },
211 KV{
212 .key = "database.cassandra.initial_request_retry_delay",
213 .value = "How long in seconds to wait before the first retry of a database request "
214 "that failed with a transient error.",
215 },
216 KV{
217 .key = "database.cassandra.max_request_retry_delay",
218 .value = "Upper bound in seconds for the exponential backoff between retries of a "
219 "database request.",
220 },
221 KV{
222 .key = "database.cassandra.username",
223 .value = "The username used for authenticating with the database.",
224 },
225 KV{
226 .key = "database.cassandra.password",
227 .value = "The password used for authenticating with the database.",
228 },
229 KV{
230 .key = "database.cassandra.certfile",
231 .value = "The path to the SSL/TLS certificate file used to establish a secure "
232 "connection between the client and the Cassandra database.",
233 },
234 KV{
235 .key = "allow_no_etl",
236 .value = "If set to `True`, allows Clio to start without any ETL source.",
237 },
238 KV{.key = "etl_sources.[].ip", .value = "The IP address of the ETL source."},
239 KV{.key = "etl_sources.[].ws_port", .value = "The WebSocket port of the ETL source."},
240 KV{.key = "etl_sources.[].grpc_port", .value = "The gRPC port of the ETL source."},
241 KV{
242 .key = "forwarding.cache_timeout",
243 .value = "Specifies the timeout duration (in seconds) for the forwarding cache used "
244 "in `rippled` communication. A value of `0` means disabling this feature.",
245 },
246 KV{
247 .key = "forwarding.request_timeout",
248 .value = "Specifies the timeout duration (in seconds) for the forwarding request used "
249 "in `rippled` communication.",
250 },
251 KV{
252 .key = "rpc.cache_timeout",
253 .value = "Specifies the timeout duration (in seconds) for RPC cache response to "
254 "timeout. A value of `0` means disabling this feature.",
255 },
256 KV{
257 .key = "num_markers",
258 .value = "Specifies the number of coroutines used to download the initial ledger.",
259 },
260 KV{
261 .key = "dos_guard.whitelist.[]",
262 .value = "The list of IP addresses to whitelist for DOS protection.",
263 },
264 KV{
265 .key = "dos_guard.max_fetches",
266 .value = "The maximum number of fetch operations allowed by DOS guard.",
267 },
268 KV{
269 .key = "dos_guard.max_connections",
270 .value = "The maximum number of concurrent connections for a specific IP address.",
271 },
272 KV{
273 .key = "dos_guard.max_requests",
274 .value = "The maximum number of requests allowed for a specific IP address.",
275 },
276 KV{
277 .key = "dos_guard.sweep_interval",
278 .value = "Interval in seconds for DOS guard to sweep(clear) its state.",
279 },
280 KV{.key = "workers", .value = "The number of threads used to process RPC requests."},
281 KV{.key = "server.ip", .value = "The IP address of the Clio HTTP server."},
282 KV{.key = "server.port", .value = "The port number of the Clio HTTP server."},
283 KV{
284 .key = "server.max_queue_size",
285 .value = "The maximum size of the server's request queue. If set to `0`, this means "
286 "there is no queue size limit.",
287 },
288 KV{
289 .key = "server.local_admin",
290 .value = "Indicates if requests from `localhost` are allowed to call Clio admin-only "
291 "APIs. Note that this setting cannot be enabled together with "
292 "[server.admin_password](#serveradmin_password).",
293 },
294 KV{
295 .key = "server.admin_password",
296 .value = "The password for Clio admin-only APIs. Note that this setting cannot be "
297 "enabled together with [server.local_admin](#serveradmin_password).",
298 },
299 KV{
300 .key = "server.processing_policy",
301 .value =
302 "For the `sequent` policy, requests from a single client connection are processed "
303 "one by one, with the next request read only after the previous one is processed. "
304 "For the `parallel` policy, Clio will accept all requests and process them in "
305 "parallel, sending a reply for each request as soon as it is ready.",
306 },
307 KV{
308 .key = "server.parallel_requests_limit",
309 .value = "This is an optional parameter, used only if the `processing_strategy` is "
310 "`parallel`. It limits the number of requests processed in parallel for a "
311 "single client connection. If not specified, no limit is enforced.",
312 },
313 KV{
314 .key = "server.ws_max_sending_queue_size",
315 .value = "Maximum queue size for sending subscription data to clients. This queue "
316 "buffers data when a client is slow to receive it, ensuring delivery once "
317 "the client is ready.",
318 },
319 KV{
320 .key = "server.proxy.ips.[]",
321 .value =
322 "List of proxy ip addresses. When Clio receives a request from proxy it will use "
323 "`Forwarded` value (if any) as client ip. When this option is used together with "
324 "`server.proxy.tokens` Clio will identify proxy by ip or by token.",
325 },
326 KV{
327 .key = "server.proxy.tokens.[]",
328 .value = "List of tokens in identifying request as a request from proxy. Token should "
329 "be provided in `X-Proxy-Token` header, e.g. `X-Proxy-Token: "
330 "<very_secret_token>'. When Clio receives a request from proxy it will use "
331 "'Forwarded` value (if any) to get client ip. When this option is used "
332 "together with 'server.proxy.ips' Clio will identify proxy by ip or by token.",
333 },
334 KV{.key = "prometheus.enabled", .value = "Enables or disables Prometheus metrics."},
335 KV{
336 .key = "prometheus.compress_reply",
337 .value = "Enables or disables compression of Prometheus responses.",
338 },
339 KV{
340 .key = "io_threads",
341 .value = "The number of input/output (I/O) threads. The value cannot be less than `1`.",
342 },
343 KV{
344 .key = "subscription_workers",
345 .value = "The number of worker threads or processes that are responsible for managing "
346 "and processing subscription-based tasks from `rippled`.",
347 },
348 KV{
349 .key = "graceful_period",
350 .value =
351 "The number of seconds the server waits to shutdown gracefully. If Clio does not "
352 "shutdown gracefully after the specified value, it will be killed instead.",
353 },
354 KV{
355 .key = "cache.num_diffs",
356 .value =
357 "The number of cursors generated is the number of changed (without counting "
358 "deleted) objects in the latest `cache.num_diffs` number of ledgers. Cursors are "
359 "workers that load the ledger cache from the position of markers concurrently. "
360 "For more information, please read [README.md](../src/etl/README.md).",
361 },
362 KV{
363 .key = "cache.num_markers",
364 .value = "Specifies how many markers are placed randomly within the cache. These "
365 "markers define the positions on the ledger that will be loaded concurrently "
366 "by the workers. The higher the number, the more places within the cache we "
367 "potentially cover.",
368 },
369 KV{
370 .key = "cache.num_cursors_from_diff",
371 .value = "`cache.num_cursors_from_diff` number of cursors are generated by looking at "
372 "the number of changed objects in the most recent ledger. If number of "
373 "changed objects in current ledger is not enough, it will keep reading "
374 "previous ledgers until it hit `cache.num_cursors_from_diff`. If set to `0`, "
375 "the system defaults to generating cursors based on `cache.num_diffs`.",
376 },
377 KV{
378 .key = "cache.num_cursors_from_account",
379 .value = "`cache.num_cursors_from_diff` of cursors are generated by reading accounts "
380 "in `account_tx` table. If set to `0`, the system defaults to generating "
381 "cursors based on `cache.num_diffs`.",
382 },
383 KV{
384 .key = "cache.page_fetch_size",
385 .value = "The number of ledger objects to fetch concurrently per marker.",
386 },
387 KV{
388 .key = "cache.limit_load_in_cluster",
389 .value = "If enabled only one clio node in a cluster (sharing the same database) will "
390 "load cache at a time",
391 },
392 KV{.key = "cache.load", .value = "The strategy used for Cache loading."},
393 KV{
394 .key = "cache.file.path",
395 .value = "The path to a file where cache will be saved to on shutdown and loaded from "
396 "on startup. If the file couldn't be read Clio will load cache as usual "
397 "(from DB or from rippled).",
398 },
399 KV{
400 .key = "cache.file.max_sequence_age",
401 .value = "Max allowed difference between the latest sequence in DB and in cache file. "
402 "If the cache file is too old (contains too low latest sequence) Clio will "
403 "reject using it.",
404 },
405 KV{
406 .key = "cache.file.async_save",
407 .value = "When false, Clio waits for cache saving to finish before shutting down. "
408 "When true, cache saving runs in parallel with other shutdown operations.",
409 },
410 KV{.key = "log.channels.[].channel", .value = "The name of the log channel."},
411 KV{.key = "log.channels.[].level", .value = "The log level for the specific log channel."},
412 KV{
413 .key = "log.level",
414 .value = "The general logging level of Clio. This level is applied to all log "
415 "channels that do not have an explicitly defined logging level.",
416 },
417 KV{
418 .key = "log.format",
419 .value = R"(The format string for log messages using spdlog format patterns.
420
421Each of the variables expands like so:
422
423- `%Y-%m-%d %H:%M:%S.%f`: The full date and time of the log entry with microsecond precision
424- `%^`: Start color range
425- `%3!l`: The severity (aka log level) the entry was sent at stripped to 3 characters
426- `%n`: The logger name (channel) that this log entry was sent to
427- `%$`: End color range
428- `%v`: The actual log message
429
430Some additional variables that might be useful:
431
432- `%@`: A partial path to the C++ file and the line number in the said file (`src/file/path:linenumber`)
433- `%t`: The ID of the thread the log entry is written from
434
435Documentation can be found at: <https://github.com/gabime/spdlog/wiki/Custom-formatting>.)",
436 },
437 KV{.key = "log.is_async", .value = "Whether spdlog is asynchronous or not."},
438 KV{.key = "log.enable_console", .value = "Enables or disables logging to the console."},
439 KV{.key = "log.directory", .value = "The directory path for the log files."},
440 KV{
441 .key = "log.rotation_size",
442 .value = "The log rotation size in megabytes. When the log file reaches this "
443 "particular size, a new log file starts.",
444 },
445 KV{
446 .key = "log.directory_max_files",
447 .value = "The maximum number of log files in the directory.",
448 },
449 KV{
450 .key = "log.rotate",
451 .value = "Enables or disables log file rotation. When disabled, a single log file is "
452 "used without size-based rotation. Useful when rotation is managed "
453 "externally (e.g., via logrotate).",
454 },
455 KV{
456 .key = "log.tag_style",
457 .value = "Log tags are unique identifiers for log messages. `uint`/`int` starts "
458 "logging from 0 and increments, making it faster. In contrast, `uuid` "
459 "generates a random unique identifier, which adds overhead.",
460 },
461 KV{
462 .key = "extractor_threads",
463 .value = "Number of threads used to extract data from ETL source.",
464 },
465 KV{
466 .key = "read_only",
467 .value = "Indicates if the server is allowed to write data to the database.",
468 },
469 KV{
470 .key = "start_sequence",
471 .value = "If specified, the ledger index Clio will start writing to the database from.",
472 },
473 KV{
474 .key = "finish_sequence",
475 .value = "If specified, the final ledger that Clio will write to the database.",
476 },
477 KV{.key = "ssl_cert_file", .value = "The path to the SSL certificate file."},
478 KV{.key = "ssl_key_file", .value = "The path to the SSL key file."},
479 KV{
480 .key = "api_version.default",
481 .value = "The default API version that the Clio server will run on.",
482 },
483 KV{.key = "api_version.min", .value = "The minimum API version allowed to use."},
484 KV{.key = "api_version.max", .value = "The maximum API version allowed to use."},
485 KV{
486 .key = "migration.full_scan_threads",
487 .value = "The number of threads used to scan the table.",
488 },
489 KV{
490 .key = "migration.full_scan_jobs",
491 .value = "The number of coroutines used to scan the table.",
492 },
493 KV{
494 .key = "migration.cursors_per_job",
495 .value = "The number of cursors each job will scan.",
496 },
497 };
498};
499
500} // namespace util::config
Array const & asArray(std::string_view key) const
Returns the Array object associated with the specified key.
Definition ConfigDefinition.cpp:125
ValueView getValueView(std::string_view fullKey) const
Returns the specified ValueView object associated with the key.
Definition ConfigDefinition.cpp:98
Clio configuration: definitions of the supported keys, their types, constraints and defaults,...
Definition HandlerRegistry.hpp:24
ClioConfigDefinition & getClioConfig()
Full Clio Configuration definition.
Definition ConfigDefinition.cpp:243
Struct to represent a key-value pair.
Definition ConfigDescription.hpp:31
std::string_view key
The config key.
Definition ConfigDescription.hpp:32
std::string_view value
The description of the config key.
Definition ConfigDescription.hpp:33
static std::expected< void, Error > generateConfigDescriptionToFile(std::filesystem::path path)
Generate markdown file of all the clio config descriptions.
Definition ConfigDescription.hpp:66
static constexpr std::string_view get(std::string_view key)
Retrieves the description for a given key.
Definition ConfigDescription.hpp:51
static void writeConfigDescriptionToFile(std::ostream &file)
Writes to Config description to file.
Definition ConfigDescription.hpp:98
constexpr ClioConfigDescription()=default
Constructs a new Clio Config Description based on pre-existing descriptions.