whilenull / 7777-support

Documentation and support for 7777.
https://port7777.com
54 stars 3 forks source link

Show role when choosing database #54

Open slootjes opened 7 months ago

slootjes commented 7 months ago

When using Port 7777 on an RDS cluster with multiple instances the output looks something like this:

Listing databases.
Which database would you like to connect to?

[1] some-service-databaseinstance1-azznqqajdhkm
[2] some-service-databaseinstance2-cqtwprntcl09

but based on this names I don't know which of the 2 is a reader or a writer. When making changes I obviously need a writer and while just doing some queries I prefer using a reader instance. Currently I always need to login to AWS to see which one I need. It would be very nice to see the role of the instance in this selection, perhaps like this:

Listing databases.
Which database would you like to connect to?

[1] some-service-databaseinstance1-azznoqajd0km (Writer instance)
[2] some-service-databaseinstance2-cqtwprbtdl09 (Reader instance)

While writing this, maybe also add the instance size to it as well:

Listing databases.
Which database would you like to connect to?

[1] some-service-databaseinstance1-azznoqajd0km (Writer instance / Serverless v2 (0.5 - 16 ACUs))
[2] some-service-databaseinstance2-cqtwprbtdl09 (Reader instance / tg4.medium)

What do you think?

mnapoli commented 7 months ago

Sounds like a great improvement idea, thanks for opening this. Naive question: is the reader/writer status exposed via the RDS API?

In any case I'm taking note of the idea (no promise on an implementation date ^^)

slootjes commented 7 months ago

The information is returned in the describe db clusters API endpoint which is already used as far as I know by this app, this is the relevant output for my cluster:

<DBClusterMembers>
    <DBClusterMember>
        <DBInstanceIdentifier>some-service-databaseinstance1-azznoqajd0km</DBInstanceIdentifier>
        <DBClusterParameterGroupStatus>in-sync</DBClusterParameterGroupStatus>
        <PromotionTier>1</PromotionTier>
        <IsClusterWriter>true</IsClusterWriter>
    </DBClusterMember>
    <DBClusterMember>
        <DBInstanceIdentifier>some-service-databaseinstance2-cqtwprbtdl09</DBInstanceIdentifier>
        <DBClusterParameterGroupStatus>in-sync</DBClusterParameterGroupStatus>
        <PromotionTier>1</PromotionTier>
        <IsClusterWriter>false</IsClusterWriter>
    </DBClusterMember>
</DBClusterMembers>

The "IsClusterWriter" returns the relevant information if it's read/write or read only.

The instance type is available in the Describe Db Instances API call:

<DBInstanceClass>db.serverless</DBInstanceClass>

Maybe returning it as a table would be prettier even when adding more information.

slootjes commented 2 months ago

Any update on this by any chance? The same thing applies for Elasticache:

Which Elasticache instance would you like to connect to?

[1] blr12bzer1fbecf1-001
[2] blr12bzer1fbecf1-002
[3] blrhen961d1ou3l-001
[4] blrhen961d1ou3l-002

Here it doesn't even show the name, only the identifier given by AWS. The same information would be useful here, especially the description and role (primary/replica).

slootjes commented 2 weeks ago

Any news on this? Please let me know if there is a way for me to contribute, I don't think this should be difficult.

mnapoli commented 2 weeks ago

@slootjes no update at the moment.

Here is the relevant code if you want to have a go at it: https://gist.github.com/mnapoli/ea2300ed9496784ac91addefa183fd4f

The small challenge is that the prompt's selected result === what is displayed. So if we add more info to each line (e.g. the name, etc.), then when the user selects the line we get the whole string back.

slootjes commented 2 weeks ago

Thanks for this :) The easy way out would be to have something like "{option} - {extra usefull stuff}" and then split/trim on the - and use the first part?

mnapoli commented 2 weeks ago

Oh yeah why not actually! Splitting on some character could work

slootjes commented 2 weeks ago

I do see that the cluster ID being such a random name is because the ID is optional in CloudFormation and I didn't set one, this is not a bug in Port 7777. It would be very nice though to also get the description (which I did fill in) but I understand if this is a problem of my own :) The reader/writer (or primary/replace) would be most useful to know still.