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

Adding subcommand "pgcat config pools list" #548

Open
guedes opened this issue Aug 15, 2023 · 0 comments
Open

Adding subcommand "pgcat config pools list" #548

guedes opened this issue Aug 15, 2023 · 0 comments

Comments

@guedes
Copy link

guedes commented Aug 15, 2023

Is your feature request related to a problem? Please describe.

From the @sebastianwebber's work on adding clap and a --help I saw the opportunity to improve pgcat with some cli commands to eliminate some "toil".

Describe the solution you'd like

I'm working on the PR #547 to add some cli subcommands to pgcat command line, so it can works as a cli. This could open doors to create stable interfaces and automate things like change pgcat configuration.

The current code is a work in progress and implements a config subcommand to pgcat. By now only list pools is implemented, but the goal is to implements all the "CRUD" for configuration, so we can edit config file without open it any editor 😄

The current implementation reads configuration after it is loaded. If you think that this a good idea I'm planning to implement not only the "CRUD" but also refactor the main.rs a bit, to organize the cli code and the server code.

See bellow some pgcat config pools list output of different files:


➤ cargo run -- .circleci/pgcat.toml config pools list
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/pgcat .circleci/pgcat.toml config pools list`
2023-08-15T21:59:54.700588Z  INFO pgcat: Welcome to PgCat! Meow. (Version 1.1.2-dev)    
🌀 Pools list
┌────────────┬─────────────┬─────────┬──────────┬───────────────────────────────────────────┬─────────────────────────────────────────┐
│ name       │ mode        │ lb mode │ def role │ users                                     │ shards                                  │
├────────────┼─────────────┼─────────┼──────────┼───────────────────────────────────────────┼─────────────────────────────────────────┤
│ sharded_db │ transaction │ random  │ any      │ ┌───────────────┬────────┬──────────────┐ │ ┌──────────┬──────────────────────────┐ │
│            │             │         │          │ │ username      │ p size │ stmt timeout │ │ │ database │ servers                  │ │
│            │             │         │          │ ├───────────────┼────────┼──────────────┤ │ ├──────────┼──────────────────────────┤ │
│            │             │         │          │ │ sharding_user │ 9      │ 0            │ │ │ shard0   │ 127.0.0.1:5432 (Primary) │ │
│            │             │         │          │ ├───────────────┼────────┼──────────────┤ │ │          │ localhost:5432 (Replica) │ │
│            │             │         │          │ │ other_user    │ 21     │ 30000        │ │ ├──────────┼──────────────────────────┤ │
│            │             │         │          │ └───────────────┴────────┴──────────────┘ │ │ shard1   │ 127.0.0.1:5432 (Primary) │ │
│            │             │         │          │                                           │ │          │ localhost:5432 (Replica) │ │
│            │             │         │          │                                           │ ├──────────┼──────────────────────────┤ │
│            │             │         │          │                                           │ │ shard2   │ 127.0.0.1:5432 (Primary) │ │
│            │             │         │          │                                           │ │          │ localhost:5432 (Replica) │ │
│            │             │         │          │                                           │ └──────────┴──────────────────────────┘ │
├────────────┼─────────────┼─────────┼──────────┼───────────────────────────────────────────┼─────────────────────────────────────────┤
│ simple_db  │ session     │ random  │ primary  │ ┌─────────────┬────────┬──────────────┐   │ ┌──────────┬──────────────────────────┐ │
│            │             │         │          │ │ username    │ p size │ stmt timeout │   │ │ database │ servers                  │ │
│            │             │         │          │ ├─────────────┼────────┼──────────────┤   │ ├──────────┼──────────────────────────┤ │
│            │             │         │          │ │ simple_user │ 5      │ 30000        │   │ │ some_db  │ 127.0.0.1:5432 (Primary) │ │
│            │             │         │          │ └─────────────┴────────┴──────────────┘   │ │          │ localhost:5432 (Replica) │ │
│            │             │         │          │                                           │ └──────────┴──────────────────────────┘ │
└────────────┴─────────────┴─────────┴──────────┴───────────────────────────────────────────┴─────────────────────────────────────────┘

➤ cargo run -- examples/docker/pgcat.toml config pools list
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/pgcat examples/docker/pgcat.toml config pools list`
2023-08-15T23:39:41.207326Z  INFO pgcat: Welcome to PgCat! Meow. (Version 1.1.2-dev)    
🌀 Pools list
┌──────────┬─────────────┬─────────┬──────────┬──────────────────────────────────────┬────────────────────────────────────────┐
│ name     │ mode        │ lb mode │ def role │ users                                │ shards                                 │
├──────────┼─────────────┼─────────┼──────────┼──────────────────────────────────────┼────────────────────────────────────────┤
│ postgres │ transaction │ random  │ any      │ ┌──────────┬────────┬──────────────┐ │ ┌──────────┬─────────────────────────┐ │
│          │             │         │          │ │ username │ p size │ stmt timeout │ │ │ database │ servers                 │ │
│          │             │         │          │ ├──────────┼────────┼──────────────┤ │ ├──────────┼─────────────────────────┤ │
│          │             │         │          │ │ postgres │ 9      │ 0            │ │ │ postgres │ postgres:5432 (Primary) │ │
│          │             │         │          │ └──────────┴────────┴──────────────┘ │ │          │ postgres:5432 (Replica) │ │
│          │             │         │          │                                      │ ├──────────┼─────────────────────────┤ │
│          │             │         │          │                                      │ │ postgres │ postgres:5432 (Primary) │ │
│          │             │         │          │                                      │ │          │ postgres:5432 (Replica) │ │
│          │             │         │          │                                      │ ├──────────┼─────────────────────────┤ │
│          │             │         │          │                                      │ │ postgres │ postgres:5432 (Primary) │ │
│          │             │         │          │                                      │ │          │ postgres:5432 (Replica) │ │
│          │             │         │          │                                      │ └──────────┴─────────────────────────┘ │
└──────────┴─────────────┴─────────┴──────────┴──────────────────────────────────────┴────────────────────────────────────────┘

I appreciate any suggestions to PR #547.

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

No branches or pull requests

1 participant