Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use one Oximeter client per admin server #7171

Merged
merged 2 commits into from
Nov 27, 2024
Merged

Conversation

plotnick
Copy link
Contributor

Keeps the admin server's connections to ClickHouse from growing without bound.

Also: don't automatically initialize an already-initialized ClickHouse database. This prevents data loss when upgrading. Schema updates for populated databases must be performed manually, as they have been in the past.

Keeps the admin server's connections to ClickHouse from growing without
bound.

Also: don't automatically initialize an already-initialized ClickHouse
database. This prevents data loss when upgrading. Schema updates for
populated databases must be performed manually, as they have been in
the past.
let log = clickhouse_cli
.log
.as_ref()
.expect("should have configured logging via CLI or config");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fishy to me; can we make clickhouse_cli.log not optional so we don't need this unwrap? Or alternatively, could we accept a Logger that we pass through to the client instead of relying on getting it from clickhouse_cli?

Copy link
Contributor Author

@plotnick plotnick Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed fishy because it was; thanks. 922157b makes ClickhouseCli.log non-optional.

"can't read ClickHouse version: {e}",
))
})?;
if version == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With apologies for this question possibly being more relevant to #6903 - how does this interact with Oximeter doing almost exactly (or maybe exactly exactly) this same check-if-0-and-initialize on startup, given the notes about initialization not being concurrency-safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll take this as a follow-up: #7173.

Copy link
Contributor

@karencfv karencfv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently came across documentation for ClickHouse's "startup scripts" https://clickhouse.com/docs/en/operations/startup-scripts. Essentially, this would mean we can define the schema directly on the XML configuration files.

<clickhouse>
    <startup_scripts>
        <scripts>
            <query>CREATE DATABASE IF NOT EXISTS oximeter;</query>
        </scripts>
        <!-- More queries -->
    </startup_scripts>
</clickhouse>

Might be worth it to investigate if this works for us? If it does, we wouldn't have to initialize all the tables via the oximeter client.

@plotnick plotnick force-pushed the fix-clickhouse-admin-single branch from 1c282f9 to 922157b Compare November 26, 2024 22:47
@plotnick
Copy link
Contributor Author

plotnick commented Nov 26, 2024

Some positive results on a4x2:

root@oxz_clickhouse_db131ccf:~# tail $(svcs -L clickhouse-admin-single) | looker
23:40:54.276Z INFO clickhouse-admin-single (dropshot): request completed
    file = /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dropshot-0.13.0/src/server.rs:863
    latency_us = 2160
    local_addr = [fd00:1122:3344:103::5]:8888
    method = PUT
    remote_addr = [fd00:1122:3344:103::4]:64402
    req_id = 3a2d5ed6-606c-4e9e-b4a8-09b8c9d234cd
    response_code = 204
    uri = /init
23:41:09.954Z INFO clickhouse-admin-single (dropshot): accepted connection
    file = /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dropshot-0.13.0/src/server.rs:1023
    local_addr = [fd00:1122:3344:103::5]:8888
    remote_addr = [fd00:1122:3344:104::5]:57938
23:41:09.963Z INFO clickhouse-admin-single (dropshot): skipping initialization of single-node ClickHouse at version 13
    file = clickhouse-admin/src/http_entrypoints.rs:176
    local_addr = [fd00:1122:3344:103::5]:8888
    method = PUT
    remote_addr = [fd00:1122:3344:104::5]:57938
    req_id = 7a2e4dc9-cb63-4dba-a5cd-d66161ac3f1c
    uri = /init
23:41:09.963Z INFO clickhouse-admin-single (dropshot): request completed
    file = /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dropshot-0.13.0/src/server.rs:863
    latency_us = 8580
    local_addr = [fd00:1122:3344:103::5]:8888
    method = PUT
    remote_addr = [fd00:1122:3344:104::5]:57938
    req_id = 7a2e4dc9-cb63-4dba-a5cd-d66161ac3f1c
    response_code = 204
    uri = /init
23:41:11.665Z INFO clickhouse-admin-single (dropshot): accepted connection
    file = /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dropshot-0.13.0/src/server.rs:1023
    local_addr = [fd00:1122:3344:103::5]:8888
    remote_addr = [fd00:1122:3344:101::5]:50726
23:41:11.668Z INFO clickhouse-admin-single (dropshot): skipping initialization of single-node ClickHouse at version 13
    file = clickhouse-admin/src/http_entrypoints.rs:176
    local_addr = [fd00:1122:3344:103::5]:8888
    method = PUT
    remote_addr = [fd00:1122:3344:101::5]:50726
    req_id = d92ced7f-055b-49dc-b491-81ef0f8124db
    uri = /init
23:41:11.668Z INFO clickhouse-admin-single (dropshot): request completed
    file = /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dropshot-0.13.0/src/server.rs:863
    latency_us = 2652
    local_addr = [fd00:1122:3344:103::5]:8888
    method = PUT
    remote_addr = [fd00:1122:3344:101::5]:50726
    req_id = d92ced7f-055b-49dc-b491-81ef0f8124db
    response_code = 204
    uri = /init
23:41:54.559Z INFO clickhouse-admin-single (dropshot): accepted connection
    file = /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dropshot-0.13.0/src/server.rs:1023
    local_addr = [fd00:1122:3344:103::5]:8888
    remote_addr = [fd00:1122:3344:103::4]:52444
23:41:54.562Z INFO clickhouse-admin-single (dropshot): skipping initialization of single-node ClickHouse at version 13
    file = clickhouse-admin/src/http_entrypoints.rs:176
    local_addr = [fd00:1122:3344:103::5]:8888
    method = PUT
    remote_addr = [fd00:1122:3344:103::4]:52444
    req_id = a67ad687-1238-4bbf-bd94-ecf00bb683c2
    uri = /init
23:41:54.562Z INFO clickhouse-admin-single (dropshot): request completed
    file = /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dropshot-0.13.0/src/server.rs:863
    latency_us = 2620
    local_addr = [fd00:1122:3344:103::5]:8888
    method = PUT
    remote_addr = [fd00:1122:3344:103::4]:52444
    req_id = a67ad687-1238-4bbf-bd94-ecf00bb683c2
    response_code = 204
    uri = /init
root@oxz_clickhouse_db131ccf:~# netstat -u | grep clickhouse-adm | grep -c ESTABLISHED
8

Copy link
Contributor

@jgallagher jgallagher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested across an upgrade on london, and all looked great! 👍

@plotnick plotnick merged commit 6a773fb into main Nov 27, 2024
16 checks passed
@plotnick plotnick deleted the fix-clickhouse-admin-single branch November 27, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants