22#include "util/Assert.hpp"
23#include "util/config/ConfigDefinition.hpp"
24#include "util/config/Error.hpp"
26#include <fmt/format.h>
38namespace util::config {
50 std::string_view value;
66 [[nodiscard]]
static constexpr std::string_view
67 get(std::string_view key)
69 auto const itr = std::ranges::find_if(kCONFIG_DESCRIPTION, [&](
auto const& v) {
return v.key == key; });
70 ASSERT(itr != kCONFIG_DESCRIPTION.end(),
"Key {} doesn't exist in config", key);
80 [[nodiscard]]
static std::expected<void, Error>
83 namespace fs = std::filesystem;
86 auto const dir = path.parent_path();
87 if (!dir.empty() && !fs::exists(dir)) {
88 return std::unexpected<Error>{
89 fmt::format(
"Error: Directory '{}' does not exist or provided path is invalid", dir.string())
93 std::ofstream file(path.string());
94 if (!file.is_open()) {
95 return std::unexpected{fmt::format(
"Failed to create file '{}': {}", path.string(), std::strerror(errno))};
101 std::cout <<
"Markdown file generated successfully: " << path <<
"\n";
113 file << kCONFIG_DESCRIPTION_HEADER;
115 for (
auto const& [key, val] : kCONFIG_DESCRIPTION) {
116 file <<
"\n### " << key <<
"\n\n";
120 if (key.contains(
"[]")) {
121 file << getClioConfig().asArray(key);
123 file << getClioConfig().getValueView(key);
125 file <<
"- **Description**: " << val <<
"\n";
130 static constexpr auto kCONFIG_DESCRIPTION_HEADER =
131 R
"(# Clio Config Description
133This document provides a list of all available Clio configuration properties in detail.
136> Dot notation in configuration key names represents nested fields.
137> For example, **database.scylladb** refers to the _scylladb_ field inside the _database_ object.
138> If a key name includes "[]", it indicates that the nested field is an array (e.g., etl_sources.[]).
140## Configuration Details
143 static constexpr auto kCONFIG_DESCRIPTION = std::array{
145 .key =
"database.type",
147 "Specifies the type of database used for storing and retrieving data required by the Clio server. Both "
148 "ScyllaDB and Cassandra can serve as backends for Clio; however, this value must be set to `cassandra`."
150 KV{.key =
"database.cassandra.contact_points",
151 .value =
"A list of IP addresses or hostnames for the initial cluster nodes (Cassandra or ScyllaDB) that "
152 "the client connects to when establishing a database connection. If you're running Clio locally, "
153 "set this value to `localhost` or `127.0.0.1`."},
154 KV{.key =
"database.cassandra.secure_connect_bundle",
155 .value =
"The configuration file that contains the necessary credentials and connection details for "
156 "securely connecting to a Cassandra database cluster."},
157 KV{.key =
"database.cassandra.port", .value =
"The port number used to connect to the Cassandra database."},
158 KV{.key =
"database.cassandra.keyspace",
159 .value =
"The Cassandra keyspace to use for the database. If you don't provide a value, this is set to "
160 "`clio` by default."},
161 KV{.key =
"database.cassandra.replication_factor",
162 .value =
"Represents the number of replicated nodes for ScyllaDB. For more details see [Fault Tolerance "
164 "Factor](https://university.scylladb.com/courses/scylla-essentials-overview/lessons/"
165 "high-availability/topic/fault-tolerance-replication-factor/)."},
166 KV{.key =
"database.cassandra.table_prefix",
167 .value =
"An optional field to specify a prefix for the Cassandra database table names."},
168 KV{.key =
"database.cassandra.max_write_requests_outstanding",
169 .value =
"Represents the maximum number of outstanding write requests. Write requests are API calls that "
170 "write to the database."},
171 KV{.key =
"database.cassandra.max_read_requests_outstanding",
173 "Maximum number of outstanding read requests. Read requests are API calls that read from the database."},
174 KV{.key =
"database.cassandra.threads",
175 .value =
"Represents the number of threads that will be used for database operations."},
176 KV{.key =
"database.cassandra.provider", .value =
"The specific database backend provider we are using."},
177 KV{.key =
"database.cassandra.core_connections_per_host",
178 .value =
"The number of core connections per host for the Cassandra database."},
179 KV{.key =
"database.cassandra.queue_size_io",
180 .value =
"Defines the queue size of the input/output (I/O) operations in Cassandra."},
181 KV{.key =
"database.cassandra.write_batch_size",
182 .value =
"Represents the batch size for write operations in Cassandra."},
183 KV{.key =
"database.cassandra.connect_timeout",
184 .value =
"The maximum amount of time in seconds that the system waits for a database connection to be "
186 KV{.key =
"database.cassandra.request_timeout",
187 .value =
"The maximum amount of time in seconds that the system waits for a request to be fetched from the "
189 KV{.key =
"database.cassandra.username", .value =
"The username used for authenticating with the database."},
190 KV{.key =
"database.cassandra.password", .value =
"The password used for authenticating with the database."},
191 KV{.key =
"database.cassandra.certfile",
192 .value =
"The path to the SSL/TLS certificate file used to establish a secure connection between the client "
193 "and the Cassandra database."},
194 KV{.key =
"allow_no_etl", .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 `rippled` "
200 "communication. A value of `0` means disabling this feature."},
201 KV{.key =
"forwarding.request_timeout",
202 .value =
"Specifies the timeout duration (in seconds) for the forwarding request used in `rippled` "
204 KV{.key =
"rpc.cache_timeout",
205 .value =
"Specifies the timeout duration (in seconds) for RPC cache response to timeout. A value of `0` "
206 "means disabling this feature."},
207 KV{.key =
"num_markers", .value =
"Specifies the number of coroutines used to download the initial ledger."},
208 KV{.key =
"dos_guard.whitelist.[]", .value =
"The list of IP addresses to whitelist for DOS protection."},
209 KV{.key =
"dos_guard.max_fetches", .value =
"The maximum number of fetch operations allowed by DOS guard."},
210 KV{.key =
"dos_guard.max_connections",
211 .value =
"The maximum number of concurrent connections for a specific IP address."},
212 KV{.key =
"dos_guard.max_requests",
213 .value =
"The maximum number of requests allowed for a specific IP address."},
214 KV{.key =
"dos_guard.sweep_interval", .value =
"Interval in seconds for DOS guard to sweep(clear) its state."},
215 KV{.key =
"workers", .value =
"The number of threads used to process RPC requests."},
216 KV{.key =
"server.ip", .value =
"The IP address of the Clio HTTP server."},
217 KV{.key =
"server.port", .value =
"The port number of the Clio HTTP server."},
218 KV{.key =
"server.max_queue_size",
219 .value =
"The maximum size of the server's request queue. If set to `0`, this means there is no queue size "
221 KV{.key =
"server.local_admin",
222 .value =
"Indicates if requests from `localhost` are allowed to call Clio admin-only APIs. Note that this "
223 "setting cannot be enabled "
224 "together with [server.admin_password](#serveradmin_password)."},
225 KV{.key =
"server.admin_password",
226 .value =
"The password for Clio admin-only APIs. Note that this setting cannot be enabled together with "
227 "[server.local_admin](#serveradmin_password)."},
228 KV{.key =
"server.processing_policy",
229 .value =
"For the `sequent` policy, requests from a single client connection are processed one by one, with "
230 "the next request read only after the previous one is processed. For the `parallel` policy, Clio "
231 "will accept all requests and process them in parallel, sending a reply for each request as soon "
233 KV{.key =
"server.parallel_requests_limit",
234 .value =
"This is an optional parameter, used only if the `processing_strategy` is `parallel`. It limits "
235 "the number of requests processed in parallel for a single client connection. If not specified, no "
236 "limit is enforced."},
237 KV{.key =
"server.ws_max_sending_queue_size",
238 .value =
"Maximum queue size for sending subscription data to clients. This queue buffers data when a "
239 "client is slow to receive it, ensuring delivery once the client is ready."},
240 KV{.key =
"server.proxy.ips.[]",
241 .value =
"List of proxy ip addresses. When Clio receives a request from proxy it will use "
242 "`Forwarded` value (if any) as client ip. When this option is used together with "
243 "`server.proxy.tokens` Clio will identify proxy by ip or by token."},
244 KV{.key =
"server.proxy.tokens.[]",
245 .value =
"List of tokens in identifying request as a request from proxy. Token should be provided in "
246 "`X-Proxy-Token` header, e.g. "
247 "`X-Proxy-Token: <very_secret_token>'. When Clio receives a request from proxy "
248 "it will use 'Forwarded` value (if any) to get client ip. When this option is used together with "
249 "'server.proxy.ips' Clio will identify proxy by ip or by token."},
250 KV{.key =
"prometheus.enabled", .value =
"Enables or disables Prometheus metrics."},
251 KV{.key =
"prometheus.compress_reply", .value =
"Enables or disables compression of Prometheus responses."},
252 KV{.key =
"io_threads",
253 .value =
"The number of input/output (I/O) threads. The value cannot be less than `1`."},
254 KV{.key =
"subscription_workers",
255 .value =
"The number of worker threads or processes that are responsible for managing and processing "
256 "subscription-based tasks from `rippled`."},
257 KV{.key =
"graceful_period",
258 .value =
"The number of milliseconds the server waits to shutdown gracefully. If Clio does not shutdown "
259 "gracefully after the specified value, it will be killed instead."},
260 KV{.key =
"cache.num_diffs",
261 .value =
"The number of cursors generated is the number of changed (without counting deleted) objects in "
262 "the latest `cache.num_diffs` number of ledgers. Cursors are workers that load the ledger cache "
263 "from the position of markers concurrently. For more information, please read "
264 "[README.md](../src/etl/README.md)."},
265 KV{.key =
"cache.num_markers",
266 .value =
"Specifies how many markers are placed randomly within the cache. These markers define the "
267 "positions on the ledger that will be loaded concurrently by the workers. The higher the number, "
268 "the more places within the cache we potentially cover."},
269 KV{.key =
"cache.num_cursors_from_diff",
270 .value =
"`cache.num_cursors_from_diff` number of cursors are generated by looking at the number of changed "
271 "objects in the most recent ledger. If number of changed objects in current ledger is not enough, "
272 "it will keep reading previous ledgers until it hit `cache.num_cursors_from_diff`. If set to `0`, "
273 "the system defaults to generating cursors based on `cache.num_diffs`."},
274 KV{.key =
"cache.num_cursors_from_account",
275 .value =
"`cache.num_cursors_from_diff` of cursors are generated by reading accounts in `account_tx` table. "
276 "If set to `0`, the system defaults to generating cursors based on `cache.num_diffs`."},
277 KV{.key =
"cache.page_fetch_size", .value =
"The number of ledger objects to fetch concurrently per marker."},
278 KV{.key =
"cache.load", .value =
"The strategy used for Cache loading."},
279 KV{.key =
"log.channels.[].channel", .value =
"The name of the log channel."},
280 KV{.key =
"log.channels.[].level", .value =
"The log level for the specific log channel."},
281 KV{.key =
"log.level",
282 .value =
"The general logging level of Clio. This level is applied to all log channels that do not have an "
283 "explicitly defined logging level."},
284 KV{.key =
"log.format", .value = R
"(The format string for log messages using spdlog format patterns.
286Each of the variables expands like so:
288- `%Y-%m-%d %H:%M:%S.%f`: The full date and time of the log entry with microsecond precision
289- `%^`: Start color range
290- `%3!l`: The severity (aka log level) the entry was sent at stripped to 3 characters
291- `%n`: The logger name (channel) that this log entry was sent to
292- `%$`: End color range
293- `%v`: The actual log message
295Some additional variables that might be useful:
297- `%@`: A partial path to the C++ file and the line number in the said file (`src/file/path:linenumber`)
298- `%t`: The ID of the thread the log entry is written from
300Documentation can be found at: <https://github.com/gabime/spdlog/wiki/Custom-formatting>.)"},
301 KV{.key = "log.is_async", .value =
"Whether spdlog is asynchronous or not."},
302 KV{.key =
"log.enable_console", .value =
"Enables or disables logging to the console."},
303 KV{.key =
"log.directory", .value =
"The directory path for the log files."},
304 KV{.key =
"log.rotation_size",
305 .value =
"The log rotation size in megabytes. When the log file reaches this particular size, a new log "
307 KV{.key =
"log.directory_max_files", .value =
"The maximum number of log files in the directory."},
308 KV{.key =
"log.tag_style",
310 "Log tags are unique identifiers for log messages. `uint`/`int` starts logging from 0 and increments, "
311 "making it faster. In contrast, `uuid` generates a random unique identifier, which adds overhead."},
312 KV{.key =
"extractor_threads", .value =
"Number of threads used to extract data from ETL source."},
313 KV{.key =
"read_only", .value =
"Indicates if the server is allowed to write data to the database."},
314 KV{.key =
"start_sequence",
315 .value =
"If specified, the ledger index Clio will start writing to the database from."},
316 KV{.key =
"finish_sequence", .value =
"If specified, the final ledger that Clio will write to the database."},
317 KV{.key =
"ssl_cert_file", .value =
"The path to the SSL certificate file."},
318 KV{.key =
"ssl_key_file", .value =
"The path to the SSL key file."},
319 KV{.key =
"api_version.default", .value =
"The default API version that the Clio server will run on."},
320 KV{.key =
"api_version.min", .value =
"The minimum API version allowed to use."},
321 KV{.key =
"api_version.max", .value =
"The maximum API version allowed to use."},
322 KV{.key =
"migration.full_scan_threads", .value =
"The number of threads used to scan the table."},
323 KV{.key =
"migration.full_scan_jobs", .value =
"The number of coroutines used to scan the table."},
324 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:48
static std::expected< void, Error > generateConfigDescriptionToFile(std::filesystem::path path)
Generate markdown file of all the clio config descriptions.
Definition ConfigDescription.hpp:81
static constexpr std::string_view get(std::string_view key)
Retrieves the description for a given key.
Definition ConfigDescription.hpp:67
static void writeConfigDescriptionToFile(std::ostream &file)
Writes to Config description to file.
Definition ConfigDescription.hpp:111
constexpr ClioConfigDescription()=default
Constructs a new Clio Config Description based on pre-existing descriptions.