pgcat icon indicating copy to clipboard operation
pgcat copied to clipboard

Adding subcommand "pgcat config pools list"

Open guedes opened this issue 2 years ago • 0 comments

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 :smile:

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.

guedes avatar Aug 15 '23 23:08 guedes