Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[reconfigurator] clickhouse-admin endpoints to generate ClickHouse co…
…nfig files (#6476) ## Overview This commit introduces two new endpoints to the `clickhouse-admin` API. One to generate a ClickHouse server XML configuration file and the other to generate a ClickHouse keeper XML configuration file. ## Purpose "Reconfigurator" will need to call these endpoints to generate the necessary files when bringing up new `clickhouse_server` and `clickhouse_keeper` zones. They will also be necessary to update existing zones with the keeper and server information from new zones. ## API structure Moving forward the API endpoints will follow the following structure: - `/keeper/` : For endpoints that will perform actions on keeper nodes solely. - `/server/` : For endpoints that will perform actions on server nodes solely. ## Usage To generate a server XML config file: ```console $ curl -X put http://example/server/config \ -H "Content-Type: application/json" \ -d '{"generation": {GENERATION_NUM}, settings: {"id": {ID}, "keepers": [{"ipv6|ipv4|domain": "{ADDRESS}"}], "remote_servers": [{"ipv6|ipv4|domain": "{ADDRESS}"}], "config_dir": "{CONFIG_PATH}", "datastore_path": "{DATA_PATH}", "listen_addr": "{LISTEN_ADDRESS}" }}' ``` To generate a keeper XML config file: ```console $ curl -X put http://example/keeper/config \ -H "Content-Type: application/json" \ -d '{"generation": {GENERATION_NUM}, settings: {"node_id": {ID}, "raft_servers": [{"id": {NODE_ID}, "host": {"ipv6|ipv4|domain": "{ADDRESS}"}}], "config_dir": "{CONFIG_PATH}", "datastore_path": "{DATA_PATH}", "listen_addr": "{LISTEN_ADDRESS}"}}' ``` ## Caveats For the time being the generation number isn't used for anything. In a follow up PR we will use it to keep track of the configuration version to make sure we're not generating an incorrect XML configuration file. ## Testing Dropshot server: ```console $ cargo run --bin=clickhouse-admin -- run -c ./smf/clickhouse-admin/config.toml -a [::1]:8888 Compiling omicron-clickhouse-admin v0.1.0 (/Users/karcar/src/omicron/clickhouse-admin) Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.52s Running `target/debug/clickhouse-admin run -c ./smf/clickhouse-admin/config.toml -a '[::1]:8888'` note: configured to log to "/dev/stdout" {"msg":"listening","v":0,"name":"clickhouse-admin","level":30,"time":"2024-09-02T07:32:00.106783Z","hostname":"ixchel","pid":11318,"local_addr":"[::1]:8888","component":"dropshot","file":"/Users/karcar/.cargo/git/checkouts/dropshot-a4a923d29dccc492/06c8dab/dropshot/src/server.rs:205"} {"msg":"accepted connection","v":0,"name":"clickhouse-admin","level":30,"time":"2024-09-02T07:32:17.626437Z","hostname":"ixchel","pid":11318,"local_addr":"[::1]:8888","component":"dropshot","file":"/Users/karcar/.cargo/git/checkouts/dropshot-a4a923d29dccc492/06c8dab/dropshot/src/server.rs:775","remote_addr":"[::1]:51896"} Path { inner: GenerationNum { generation: Generation(123) } } {"msg":"request completed","v":0,"name":"clickhouse-admin","level":30,"time":"2024-09-02T07:32:17.628323Z","hostname":"ixchel","pid":11318,"uri":"/node/server/generate-config/123","method":"post","req_id":"0b623f6b-441c-4418-9189-99504fbea5bf","remote_addr":"[::1]:51896","local_addr":"[::1]:8888","component":"dropshot","file":"/Users/karcar/.cargo/git/checkouts/dropshot-a4a923d29dccc492/06c8dab/dropshot/src/server.rs:914","latency_us":1044,"response_code":"201"} {"msg":"accepted connection","v":0,"name":"clickhouse-admin","level":30,"time":"2024-09-02T07:34:07.829199Z","hostname":"ixchel","pid":11318,"local_addr":"[::1]:8888","component":"dropshot","file":"/Users/karcar/.cargo/git/checkouts/dropshot-a4a923d29dccc492/06c8dab/dropshot/src/server.rs:775","remote_addr":"[::1]:52117"} Path { inner: GenerationNum { generation: Generation(123) } } {"msg":"request completed","v":0,"name":"clickhouse-admin","level":30,"time":"2024-09-02T07:34:07.830355Z","hostname":"ixchel","pid":11318,"uri":"/node/keeper/generate-config/123","method":"post","req_id":"1c729e0c-04bf-4e75-af0a-b23eef40f20f","remote_addr":"[::1]:52117","local_addr":"[::1]:8888","component":"dropshot","file":"/Users/karcar/.cargo/git/checkouts/dropshot-a4a923d29dccc492/06c8dab/dropshot/src/server.rs:914","latency_us":985,"response_code":"201"} ``` Generate server XML file: ```console $ curl -X put http://[::1]:8888/server/config -H "Content-Type: application/json" -d '{"generation": 3, "settings": {"id": 45, "keepers": [{"ipv6": "ff::01"}, {"ipv4": "127.0.0.1"}, {"domain_name": "hi.there"}], "remote_servers": [{"ipv6": "ff::08"}, {"ipv4": "127.0.0.2"}], "config_dir": "./", "datastore_path": "./", "listen_addr": "::1" }}' | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 858 100 602 100 256 210k 91789 --:--:-- --:--:-- --:--:-- 418k { "logger": { "level": "trace", "log": "./log/clickhouse.log", "errorlog": "./log/clickhouse.err.log", "size": 100, "count": 1 }, "macros": { "shard": 1, "replica": 45, "cluster": "oximeter_cluster" }, "listen_host": "::1", "http_port": 8123, "tcp_port": 9000, "interserver_http_port": 9009, "remote_servers": { "cluster": "oximeter_cluster", "secret": "some-unique-value", "replicas": [ { "host": { "ipv6": "ff::8" }, "port": 9000 }, { "host": { "ipv4": "127.0.0.2" }, "port": 9000 } ] }, "keepers": { "nodes": [ { "host": { "ipv6": "ff::1" }, "port": 9181 }, { "host": { "ipv4": "127.0.0.1" }, "port": 9181 }, { "host": { "domain_name": "hi.there" }, "port": 9181 } ] }, "data_path": "./data" } ``` Generate keeper XML file: ```console $ curl -X put http://[::1]:8888/keeper/config -H "Content-Type: application/json" -d '{"generation": 3, "settings": {"id": 1, "raft_servers": [{"id": 1, "host": {"ipv6": "ff::01"}}, {"id": 2, "host":{"ipv4": "127.0.0.1"}}, {"id": 3, "host":{"domain_name": "hi.there"}}], "config_dir": "./", "datastore_path": "./", "listen_addr": "::1" }}' | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 820 100 568 100 252 301k 133k --:--:-- --:--:-- --:--:-- 800k { "logger": { "level": "trace", "log": "./log/clickhouse-keeper.log", "errorlog": "./log/clickhouse-keeper.err.log", "size": 100, "count": 1 }, "listen_host": "::1", "tcp_port": 9181, "server_id": 1, "log_storage_path": "./coordination/log", "snapshot_storage_path": "./coordination/snapshots", "coordination_settings": { "operation_timeout_ms": 10000, "session_timeout_ms": 30000, "raft_logs_level": "trace" }, "raft_config": { "servers": [ { "id": 1, "hostname": { "ipv6": "ff::1" }, "port": 9234 }, { "id": 2, "hostname": { "ipv4": "127.0.0.1" }, "port": 9234 }, { "id": 3, "hostname": { "domain_name": "hi.there" }, "port": 9234 } ] } } ``` Related: #5999 , #3824
- Loading branch information