charles-001 / dolphie

Your single pane of glass for real-time analytics into MySQL/MariaDB & ProxySQL
https://pypi.org/project/dolphie/
GNU General Public License v3.0
651 stars 40 forks source link

Link a hostgroup tab id to a specific login/password pair #68

Closed valentintraen closed 1 month ago

valentintraen commented 1 month ago

Hi !

I don't think this is currently possible but I think it could be interesting to be able to indicate a specific login/password pair for each tab of a hostgroup. For example, I would like to create a hostgroup allowing me to connect to all the MySQL servers in the same cluster but also to all the ProxySQLs in the same cluster. And since mySQL and ProxySQL passwords are different in my case, I can't do it (I think?)

For example :

1=server1:3307~[red]MySQL[/red]server1
2=server2:3307~[red]MySQL[/red]server2
3=server3:3307~[red]MySQL[/red]server3
4=server1:6032~[blue]ProxySQL[/blue]server1
5=server2:6032~[blue]ProxySQL[/blue]server2

I would like to be able to configure a login/password pair for 1,2,3 and another login/password pair for 4 and 5.

Maybe :

1=server1:3307~[red]MySQL[/red]server1~/etc/dolphie/login1.cnf
2=server2:3307~[red]MySQL[/red]server2~/etc/dolphie/login1.cnf
3=server3:3307~[red]MySQL[/red]server3~/etc/dolphie/login1.cnf
4=server1:6032~[blue]ProxySQL[/blue]server1~/etc/dolphie/login2.cnf
5=server2:6032~[blue]ProxySQL[/blue]server2~/etc/dolphie/login2.cnf
charles-001 commented 1 month ago

Hi Valentin,

I understand what you're trying to do :) You are correct, Dolphie currently doesn't support specifying login credentials per entry in a hostgroup; all hosts in a hostgroup use the same credentials. I've thought about this before, but never got around to implementing a solution.

The thing here is that Dolphie has many ways to use credentials (command-line, environment variables, dolphie's config, ~/.mylogin.cnf, and ~/.my.cnf). In an ideal world, it would be great to be able to support all of those methods in a clean way for each host in a hostgroup, but I don't think this type of feature is worth that work.

What if I did something like this to change it up to give the keys meaning (can't use ':' in a key, so instead use '|') and let the user specify a new special section for hostgroup credentials:

[my_hostgroup]
server1={"tab_title": "[red]MySQL 1[/red]server1", "hostgroup_credential": "mysql"}
server2={"tab_title": "[red]MySQL 2[/red]server2", "hostgroup_credential": "mysql"}
server3={"tab_title": "[red]MySQL 3[/red]server3", "hostgroup_credential": "mysql"}
server4|6032={"tab_title": "[blue]ProxySQL 1[/blue]server4", "hostgroup_credential": "proxysql"}
server5|6032={"tab_title": "[blue]ProxySQL 2[/blue]server5", "hostgroup_credential": "proxysql"}

[hostgroup_credential_mysql]
file=/etc/dolphie/login1.cnf # (this would work the same way as mycnf_file using [client] section)

[hostgroup_credential_proxysql]
user=dolphie
password=hunter2

I see this as a clean way to provide credentials. I'd only support user/password since I think those are the only ones really needed. Thoughts?

valentintraen commented 1 month ago

That would be perfect! I'll let you implement it in the way that seems most simple and clear to you.

charles-001 commented 1 month ago

I also want to make sure you feel the same way! Is there any other way you think would be better or anything else you need for this while I'll be in this part of the code?

valentintraen commented 1 month ago

I think that's what needs to be done. It meets my needs, it's clean and it's easy to implement and industrialize if I want to generate Dolphie configuration files with Ansible for example. For me it's all good.

If I mix "proxysql" and "mysql" panels in my startup_panels declaration, will that cause no problems? (because of the proxysql panels which will not work for my connections 1,2,3 etc...).

charles-001 commented 1 month ago

Awesome! I'll look to change that here soon. You can mix mysql/proxysql panels via startup_panels without any issues. I don't believe a panel will show if your tab isn't on its connection source.

charles-001 commented 1 month ago

HI @valentintraen - I actually went full blown on this and created a new feature "Credential Profiles" which is a way to universally use saved credentials for hostgroups as well as with individual hosts. The Host Setup modal fully supports this as well.

I've created a new branch called 6.1.0 and pushed my changes. Can you follow these steps and test it out?

  1. git clone the repo
  2. git checkout 6.1.0
  3. poetry install
  4. poetry run dolphie <options>

I've updated the README so please follow that and let me know if anything needs clarification. Look forward to your feedback!

valentintraen commented 1 month ago

Amazing ! I'm going to test in more depth but I did a test on one of my clusters with mysql and proxysql, it works! Perhaps consider indicating in the readme that Credential Profiles must be declared before Hostgroups in the configuration file. I will continue my tests and I tell you if I see something that does not work. In any case, very nice work!

charles-001 commented 1 month ago

Ahh, good catch! I just pushed a change that fixes the credential profiles ordering so it doesn't matter. I now load them first before hostgroups.

valentintraen commented 1 month ago

Hi ! Based on my testing, I believe everything is working as expected! Well done !

charles-001 commented 1 month ago

That's great to hear! I'll get this into a new version here soon. Thanks for the request!

charles-001 commented 1 month ago

This feature is now in 6.1.0