-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Reloading database config with dynamic config #18358
Reloading database config with dynamic config #18358
Conversation
Note: Fails to work correctly as the config provided to Knex is based on a deep copy Signed-off-by: Günther Wieser <guenther.wieser@creative-it.com>
Changed Packages
|
Signed-off-by: Johannes Grumboeck <johannes.grumboeck@redbull.com>
d8b23be
to
4d081ac
Compare
@guentherwieser wrote the following comment with questions to the issue #17466. I think it's better to have implementation discussions here in the PR.
@freben @benjdlambert @Rugvip @jhaals It would be great to get your opinion, if we are on the right track with this proposal, and what are your thoughts in this? |
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution! |
@freben @benjdlambert |
Hey 👋 sorry it's just me this next few weeks and been a bit slammed! Will hopefully get to this over the weekend or monday 🙏 |
Hi @guentherwieser, any chance you can update the title of this PR to something more descriptive? Makes it much easier when looking at all the PRs in a list to tell what this is about. Thanks in advance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we're heading in a good direction - just some smaller things to work out I think. I'm also keeping an eye on #18507 as it looks like there's going to be some overlap here. I want to get some other maintainers feedback on the approaches for both this and the one over in #18507 when they get back from the holidays and work out a path forward here, so going to add the after-vacations
label on this to pick up when they're back in a week or so. Does that sounds OK?
@@ -33,9 +34,17 @@ import { Client } from 'pg'; | |||
export function createPgDatabaseClient( | |||
dbConfig: Config, | |||
overrides?: Knex.Config, | |||
) { | |||
const knexConfig = buildPgDatabaseConfig(dbConfig, overrides); | |||
deps?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need these here right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! 👍
Got an initial high level question on the approach
console.log(`backend: ${JSON.stringify(config.getOptionalConfig('backend'))}`); | ||
} | ||
console.log('Invalidating the database cache...'); | ||
this.databaseCache.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to tell knex that config has changed? Would it be enough to simply read the latest config whenever we want to create a new database connection? Reading config from the ConfigService is very fast, more or less property-access fast. With that I feel we would be able to avoid quite a lot of complicated coupling?
Of course that all hinges on whether knex will detect failed connections and try to re-establish new ones with new config. If it keeps trying to re-use the old config while failing to connect that approach wouldn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add to the above Q, I'm wondering what the behavior would be if we provide an expirationChecker
that always returns true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to tell knex that config has changed? Would it be enough to simply read the latest config whenever we want to create a new database connection? Reading config from the ConfigService is very fast, more or less property-access fast. With that I feel we would be able to avoid quite a lot of complicated coupling?
I don't think you can "just" read the latest config. In token-based access architecture, you will have to make a request to acquire a new token. Together with this token, you will get an expiration timestamp. Simple comparison current timestamp will not take long to mark the connection as expired.
There is a similar issue and PR with more accomplished implementation of the approach proposed here https://github.com/backstage/backstage/pull/18507/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what we're doing now though right? At the moment we are just reacting to changes in config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yeah. Token-based access is out of the scope of this PR. Sorry :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So is it alright to flip around the approach in this PR? So that rather than subscribing and pushing config changes we have the knex client read the latest config every time it needs to create a new connection? We just gotta make sure that the expirationChecker
behaves well with that approach. As in if we use a naive approach were it always returns true
, we'd for example need to make sure that doesn't cause existing connections to be torn down. It could also be that we actually want the expirationChecker
to read config itself, to check if it has changed, if that ends up being the best approach we'd also need to make sure it isn't called too often, i.e. on every statement.
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution! |
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution! |
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution! |
We'll rethink the implementation and open a new PR when ready. |
Note: Fails to work correctly as the config provided to Knex is based on a deep copy
This is to support #17466, yet it is far from being done - it's just to provide example code for better clarification
Hey, I just made a Pull Request!
✔️ Checklist
Signed-off-by
line in the message. (more info)