3#include "util/Assert.hpp"
4#include "util/config/ConfigDefinition.hpp"
5#include "util/config/Error.hpp"
19namespace util::config {
31 std::string_view value;
48 [[nodiscard]]
static constexpr std::string_view
49 get(std::string_view key)
52 std::ranges::find_if(kConfigDescription, [&](
auto const& v) {
return v.key == key; });
53 ASSERT(itr != kConfigDescription.end(),
"Key {} doesn't exist in config", key);
63 [[nodiscard]]
static std::expected<void, Error>
66 namespace fs = std::filesystem;
69 auto const dir = path.parent_path();
70 if (!dir.empty() && !fs::exists(dir)) {
71 return std::unexpected<Error>{fmt::format(
72 "Error: Directory '{}' does not exist or provided path is invalid", dir.string()
76 std::ofstream file(path.string());
77 if (!file.is_open()) {
78 return std::unexpected{
79 fmt::format(
"Failed to create file '{}': {}", path.string(), std::strerror(errno))
86 std::cout <<
"Markdown file generated successfully: " << path <<
"\n";
98 file << kConfigDescriptionHeader;
100 for (
auto const& [key, val] : kConfigDescription) {
101 file <<
"\n### " << key <<
"\n\n";
105 if (key.contains(
"[]")) {
106 file << getClioConfig().asArray(key);
108 file << getClioConfig().getValueView(key);
110 file <<
"- **Description**: " << val <<
"\n";
115 static constexpr auto kConfigDescriptionHeader =
116 R
"(# Clio Config Description
118This document provides a list of all available Clio configuration properties in detail.
121> Dot notation in configuration key names represents nested fields.
122> For example, **database.scylladb** refers to the _scylladb_ field inside the _database_ object.
123> If a key name includes "[]", it indicates that the nested field is an array (e.g., etl_sources.[]).
125## Configuration Details
128 static constexpr auto kConfigDescription = std::array{
129 KV{.key =
"database.type",
130 .value =
"Specifies the type of database used for storing and retrieving data required "
131 "by the Clio server. Both "
132 "ScyllaDB and Cassandra can serve as backends for Clio; however, this value "
133 "must be set to `cassandra`."},
134 KV{.key =
"database.cassandra.contact_points",
135 .value =
"A list of IP addresses or hostnames for the initial cluster nodes (Cassandra "
137 "the client connects to when establishing a database connection. If you're "
138 "running Clio locally, "
139 "set this value to `localhost` or `127.0.0.1`."},
140 KV{.key =
"database.cassandra.secure_connect_bundle",
141 .value =
"The configuration file that contains the necessary credentials and connection "
143 "securely connecting to a Cassandra database cluster."},
144 KV{.key =
"database.cassandra.port",
145 .value =
"The port number used to connect to the Cassandra database."},
146 KV{.key =
"database.cassandra.keyspace",
147 .value =
"The Cassandra keyspace to use for the database. If you don't provide a value, "
149 "`clio` by default."},
150 KV{.key =
"database.cassandra.replication_factor",
152 "Represents the number of replicated nodes for ScyllaDB. For more details see "
155 "Factor](https://university.scylladb.com/courses/scylla-essentials-overview/lessons/"
156 "high-availability/topic/fault-tolerance-replication-factor/)."},
157 KV{.key =
"database.cassandra.table_prefix",
159 "An optional field to specify a prefix for the Cassandra database table names."},
160 KV{.key =
"database.cassandra.max_write_requests_outstanding",
161 .value =
"Represents the maximum number of outstanding write requests. Write requests "
162 "are API calls that "
163 "write to the database."},
164 KV{.key =
"database.cassandra.max_read_requests_outstanding",
165 .value =
"Maximum number of outstanding read requests. Read requests are API calls that "
166 "read from the database."},
167 KV{.key =
"database.cassandra.threads",
168 .value =
"Represents the number of threads that will be used for database operations."},
169 KV{.key =
"database.cassandra.provider",
170 .value =
"The specific database backend provider we are using."},
171 KV{.key =
"database.cassandra.core_connections_per_host",
172 .value =
"The number of core connections per host for the Cassandra database."},
173 KV{.key =
"database.cassandra.queue_size_io",
174 .value =
"Defines the queue size of the input/output (I/O) operations in Cassandra."},
175 KV{.key =
"database.cassandra.write_batch_size",
176 .value =
"Represents the batch size for write operations in Cassandra."},
177 KV{.key =
"database.cassandra.connect_timeout",
178 .value =
"The maximum amount of time in seconds that the system waits for a database "
181 KV{.key =
"database.cassandra.request_timeout",
182 .value =
"The maximum amount of time in seconds that the system waits for a request to "
183 "be fetched from the "
185 KV{.key =
"database.cassandra.username",
186 .value =
"The username used for authenticating with the database."},
187 KV{.key =
"database.cassandra.password",
188 .value =
"The password used for authenticating with the database."},
189 KV{.key =
"database.cassandra.certfile",
190 .value =
"The path to the SSL/TLS certificate file used to establish a secure "
191 "connection between the client "
192 "and the Cassandra database."},
193 KV{.key =
"allow_no_etl",
194 .value =
"If set to `True`, allows Clio to start without any ETL source."},
195 KV{.key =
"etl_sources.[].ip", .value =
"The IP address of the ETL source."},
196 KV{.key =
"etl_sources.[].ws_port", .value =
"The WebSocket port of the ETL source."},
197 KV{.key =
"etl_sources.[].grpc_port", .value =
"The gRPC port of the ETL source."},
198 KV{.key =
"forwarding.cache_timeout",
199 .value =
"Specifies the timeout duration (in seconds) for the forwarding cache used in "
201 "communication. A value of `0` means disabling this feature."},
202 KV{.key =
"forwarding.request_timeout",
203 .value =
"Specifies the timeout duration (in seconds) for the forwarding request used "
206 KV{.key =
"rpc.cache_timeout",
207 .value =
"Specifies the timeout duration (in seconds) for RPC cache response to "
208 "timeout. A value of `0` "
209 "means disabling this feature."},
210 KV{.key =
"num_markers",
211 .value =
"Specifies the number of coroutines used to download the initial ledger."},
212 KV{.key =
"dos_guard.whitelist.[]",
213 .value =
"The list of IP addresses to whitelist for DOS protection."},
214 KV{.key =
"dos_guard.max_fetches",
215 .value =
"The maximum number of fetch operations allowed by DOS guard."},
216 KV{.key =
"dos_guard.max_connections",
217 .value =
"The maximum number of concurrent connections for a specific IP address."},
218 KV{.key =
"dos_guard.max_requests",
219 .value =
"The maximum number of requests allowed for a specific IP address."},
220 KV{.key =
"dos_guard.sweep_interval",
221 .value =
"Interval in seconds for DOS guard to sweep(clear) its state."},
222 KV{.key =
"workers", .value =
"The number of threads used to process RPC requests."},
223 KV{.key =
"server.ip", .value =
"The IP address of the Clio HTTP server."},
224 KV{.key =
"server.port", .value =
"The port number of the Clio HTTP server."},
225 KV{.key =
"server.max_queue_size",
226 .value =
"The maximum size of the server's request queue. If set to `0`, this means "
227 "there is no queue size "
229 KV{.key =
"server.local_admin",
230 .value =
"Indicates if requests from `localhost` are allowed to call Clio admin-only "
231 "APIs. Note that this "
232 "setting cannot be enabled "
233 "together with [server.admin_password](#serveradmin_password)."},
234 KV{.key =
"server.admin_password",
235 .value =
"The password for Clio admin-only APIs. Note that this setting cannot be "
236 "enabled together with "
237 "[server.local_admin](#serveradmin_password)."},
238 KV{.key =
"server.processing_policy",
239 .value =
"For the `sequent` policy, requests from a single client connection are "
240 "processed one by one, with "
241 "the next request read only after the previous one is processed. For the "
242 "`parallel` policy, Clio "
243 "will accept all requests and process them in parallel, sending a reply for "
244 "each request as soon "
246 KV{.key =
"server.parallel_requests_limit",
247 .value =
"This is an optional parameter, used only if the `processing_strategy` is "
248 "`parallel`. It limits "
249 "the number of requests processed in parallel for a single client connection. "
250 "If not specified, no "
251 "limit is enforced."},
252 KV{.key =
"server.ws_max_sending_queue_size",
253 .value =
"Maximum queue size for sending subscription data to clients. This queue "
254 "buffers data when a "
255 "client is slow to receive it, ensuring delivery once the client is ready."},
256 KV{.key =
"server.proxy.ips.[]",
258 "List of proxy ip addresses. When Clio receives a request from proxy it will use "
259 "`Forwarded` value (if any) as client ip. When this option is used together with "
260 "`server.proxy.tokens` Clio will identify proxy by ip or by token."},
261 KV{.key =
"server.proxy.tokens.[]",
262 .value =
"List of tokens in identifying request as a request from proxy. Token should "
264 "`X-Proxy-Token` header, e.g. "
265 "`X-Proxy-Token: <very_secret_token>'. When Clio receives a request from proxy "
266 "it will use 'Forwarded` value (if any) to get client ip. When this option is "
267 "used together with "
268 "'server.proxy.ips' Clio will identify proxy by ip or by token."},
269 KV{.key =
"prometheus.enabled", .value =
"Enables or disables Prometheus metrics."},
270 KV{.key =
"prometheus.compress_reply",
271 .value =
"Enables or disables compression of Prometheus responses."},
272 KV{.key =
"io_threads",
273 .value =
"The number of input/output (I/O) threads. The value cannot be less than `1`."},
274 KV{.key =
"subscription_workers",
275 .value =
"The number of worker threads or processes that are responsible for managing "
277 "subscription-based tasks from `rippled`."},
278 KV{.key =
"graceful_period",
279 .value =
"The number of seconds the server waits to shutdown gracefully. If Clio does "
281 "gracefully after the specified value, it will be killed instead."},
282 KV{.key =
"cache.num_diffs",
283 .value =
"The number of cursors generated is the number of changed (without counting "
284 "deleted) objects in "
285 "the latest `cache.num_diffs` number of ledgers. Cursors are workers that load "
287 "from the position of markers concurrently. For more information, please read "
288 "[README.md](../src/etl/README.md)."},
289 KV{.key =
"cache.num_markers",
290 .value =
"Specifies how many markers are placed randomly within the cache. These "
291 "markers define the "
292 "positions on the ledger that will be loaded concurrently by the workers. The "
293 "higher the number, "
294 "the more places within the cache we potentially cover."},
295 KV{.key =
"cache.num_cursors_from_diff",
296 .value =
"`cache.num_cursors_from_diff` number of cursors are generated by looking at "
297 "the number of changed "
298 "objects in the most recent ledger. If number of changed objects in current "
299 "ledger is not enough, "
300 "it will keep reading previous ledgers until it hit "
301 "`cache.num_cursors_from_diff`. If set to `0`, "
302 "the system defaults to generating cursors based on `cache.num_diffs`."},
303 KV{.key =
"cache.num_cursors_from_account",
304 .value =
"`cache.num_cursors_from_diff` of cursors are generated by reading accounts in "
305 "`account_tx` table. "
306 "If set to `0`, the system defaults to generating cursors based on "
307 "`cache.num_diffs`."},
308 KV{.key =
"cache.page_fetch_size",
309 .value =
"The number of ledger objects to fetch concurrently per marker."},
310 KV{.key =
"cache.limit_load_in_cluster",
311 .value =
"If enabled only one clio node in a cluster (sharing the same database) will "
312 "load cache at a time"},
313 KV{.key =
"cache.load", .value =
"The strategy used for Cache loading."},
314 KV{.key =
"cache.file.path",
315 .value =
"The path to a file where cache will be saved to on shutdown and loaded from "
317 "If the file couldn't be read Clio will load cache as usual (from DB or from "
319 KV{.key =
"cache.file.max_sequence_age",
320 .value =
"Max allowed difference between the latest sequence in DB and in cache file. "
321 "If the cache file is "
322 "too old (contains too low latest sequence) Clio will reject using it."},
323 KV{.key =
"cache.file.async_save",
325 "When false, Clio waits for cache saving to finish before shutting down. When true, "
326 "cache saving runs in parallel with other shutdown operations."},
327 KV{.key =
"log.channels.[].channel", .value =
"The name of the log channel."},
328 KV{.key =
"log.channels.[].level", .value =
"The log level for the specific log channel."},
329 KV{.key =
"log.level",
330 .value =
"The general logging level of Clio. This level is applied to all log channels "
331 "that do not have an "
332 "explicitly defined logging level."},
333 KV{.key =
"log.format",
334 .value = R
"(The format string for log messages using spdlog format patterns.
336Each of the variables expands like so:
338- `%Y-%m-%d %H:%M:%S.%f`: The full date and time of the log entry with microsecond precision
339- `%^`: Start color range
340- `%3!l`: The severity (aka log level) the entry was sent at stripped to 3 characters
341- `%n`: The logger name (channel) that this log entry was sent to
342- `%$`: End color range
343- `%v`: The actual log message
345Some additional variables that might be useful:
347- `%@`: A partial path to the C++ file and the line number in the said file (`src/file/path:linenumber`)
348- `%t`: The ID of the thread the log entry is written from
350Documentation can be found at: <https://github.com/gabime/spdlog/wiki/Custom-formatting>.)"},
351 KV{.key = "log.is_async", .value =
"Whether spdlog is asynchronous or not."},
352 KV{.key =
"log.enable_console", .value =
"Enables or disables logging to the console."},
353 KV{.key =
"log.directory", .value =
"The directory path for the log files."},
354 KV{.key =
"log.rotation_size",
355 .value =
"The log rotation size in megabytes. When the log file reaches this particular "
358 KV{.key =
"log.directory_max_files",
359 .value =
"The maximum number of log files in the directory."},
360 KV{.key =
"log.rotate",
361 .value =
"Enables or disables log file rotation. When disabled, a single log file is "
362 "used without size-based rotation. Useful when rotation is managed externally "
363 "(e.g., via logrotate)."},
364 KV{.key =
"log.tag_style",
365 .value =
"Log tags are unique identifiers for log messages. `uint`/`int` starts logging "
366 "from 0 and increments, "
367 "making it faster. In contrast, `uuid` generates a random unique identifier, "
368 "which adds overhead."},
369 KV{.key =
"extractor_threads",
370 .value =
"Number of threads used to extract data from ETL source."},
371 KV{.key =
"read_only",
372 .value =
"Indicates if the server is allowed to write data to the database."},
373 KV{.key =
"start_sequence",
374 .value =
"If specified, the ledger index Clio will start writing to the database from."},
375 KV{.key =
"finish_sequence",
376 .value =
"If specified, the final ledger that Clio will write to the database."},
377 KV{.key =
"ssl_cert_file", .value =
"The path to the SSL certificate file."},
378 KV{.key =
"ssl_key_file", .value =
"The path to the SSL key file."},
379 KV{.key =
"api_version.default",
380 .value =
"The default API version that the Clio server will run on."},
381 KV{.key =
"api_version.min", .value =
"The minimum API version allowed to use."},
382 KV{.key =
"api_version.max", .value =
"The maximum API version allowed to use."},
383 KV{.key =
"migration.full_scan_threads",
384 .value =
"The number of threads used to scan the table."},
385 KV{.key =
"migration.full_scan_jobs",
386 .value =
"The number of coroutines used to scan the table."},
387 KV{.key =
"migration.cursors_per_job", .value =
"The number of cursors each job will scan."}
Struct to represent a key-value pair.
Definition ConfigDescription.hpp:29
static std::expected< void, Error > generateConfigDescriptionToFile(std::filesystem::path path)
Generate markdown file of all the clio config descriptions.
Definition ConfigDescription.hpp:64
static constexpr std::string_view get(std::string_view key)
Retrieves the description for a given key.
Definition ConfigDescription.hpp:49
static void writeConfigDescriptionToFile(std::ostream &file)
Writes to Config description to file.
Definition ConfigDescription.hpp:96
constexpr ClioConfigDescription()=default
Constructs a new Clio Config Description based on pre-existing descriptions.