sozu-proxy / sozu

Sōzu HTTP reverse proxy, configurable at runtime, fast and safe, built in Rust. It is awesome!
https://www.sozu.io/
GNU Affero General Public License v3.0
2.92k stars 188 forks source link

sort cluster information alphabetically when displaying #1092

Closed Keksoj closed 3 months ago

Keksoj commented 3 months ago

Using BTreeMaps instead of HashMaps suffices to sort items alphabetically. For instance, this list of backends in a config.toml for a given cluster:

backends = [
    { address = "127.0.0.1:1051", backend_id = "a_backend_1" },
    { address = "127.0.0.1:1052", backend_id = "c_backend_2" },
    { address = "127.0.0.1:1053", backend_id = "b_backend_3" },
    { address = "127.0.0.1:1054", backend_id = "aa_backend_4" },
]

will be displayed like this:

backends configuration:

┌──────────────┬────────────────┬────────┬───┬───┬──────┐
│ backend id   │ IP address     │ Backup │ 0 │ 1 │ main │
├──────────────┼────────────────┼────────┼───┼───┼──────┤
│ a_backend_1  │ 127.0.0.1:1051 │        │ X │ X │ X    │
├──────────────┼────────────────┼────────┼───┼───┼──────┤
│ aa_backend_4 │ 127.0.0.1:1054 │        │ X │ X │ X    │
├──────────────┼────────────────┼────────┼───┼───┼──────┤
│ b_backend_3  │ 127.0.0.1:1053 │        │ X │ X │ X    │
├──────────────┼────────────────┼────────┼───┼───┼──────┤
│ c_backend_2  │ 127.0.0.1:1052 │        │ X │ X │ X    │
└──────────────┴────────────────┴────────┴───┴───┴──────┘

In the same way, the frontends of a cluster will be sorted by hostname:

┌───────────┬─────────────────┬───────────────┬───┬───┬──────┐
│ id        │ hostname        │ path          │ 0 │ 1 │ main │
├───────────┼─────────────────┼───────────────┼───┼───┼──────┤
│ MyCluster │ abracadabra.com │ prefix '/api' │ X │ X │ X    │
├───────────┼─────────────────┼───────────────┼───┼───┼──────┤
│ MyCluster │ blabla.com      │ prefix '/api' │ X │ X │ X    │
├───────────┼─────────────────┼───────────────┼───┼───┼──────┤
│ MyCluster │ localhost       │ prefix '/api' │ X │ X │ X    │
└───────────┴─────────────────┴───────────────┴───┴───┴──────┘