Skip to content

Allow configuration of API host#3717

Merged
MDrakos merged 11 commits intomasterfrom
miked/PIF-1050
Aug 28, 2025
Merged

Allow configuration of API host#3717
MDrakos merged 11 commits intomasterfrom
miked/PIF-1050

Conversation

@MDrakos
Copy link
Member

@MDrakos MDrakos commented Aug 26, 2025

@MDrakos
Copy link
Member Author

MDrakos commented Aug 26, 2025

I'm not sure what state the integration tests are in but there are a lot of failures that don't seem related to this changeset at all. If you think I need to investigate any of them let me know.

@MDrakos MDrakos requested a review from Naatan August 26, 2025 17:56
@mitchell-as
Copy link
Collaborator

I can confirm they are all known failures and unrelated to this PR.

Copy link
Contributor

@Naatan Naatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work so far!

}

func getProjectHostFromConfig() string {
cfg, err := config.New()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should route in the config instance from main / prime. Since that controls closing and writing of the config file. I think we'll run into conflicts if we have multiple instances.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this one is a bit awkward. This package is so low-level that passing the config in here will lead to A LOT of cascading changes. Many function signatures will need to be updated to pass a config instance or an interface. I've added a proposal for DB protection in this commit.

We could consider something like above with a lockfile, some sort of global registry of config instances (though this doesn't protect us for inter-process access), bite the bullet and do the updates required to pass the config instance around, or some other solution that I'm not thinking of.

@MDrakos MDrakos requested a review from Naatan August 26, 2025 21:05
if err != nil {
return errs.Wrap(err, "Could not create lock file for %s", i.lockfile)
}
defer pidLock.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would close the lock after the connection has been created, which doesn't solve the potential conflict. In order for the lock to be valid it would have to be closed when the config connection is closed, but if that were the case then your use-case would not work either as it would encounter the lock..

I think this might be a scenario where it makes more sense to break our rule of "no globals" given the application of the package (api) is so global, and not contextual. Perhaps in time we can properly solve this once and for all by threading a context everywhere.

So I'd suggest calling something like api.Init(cfg) from main.go. Just make sure that tests are not using this global, because that would break concurrent tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm misunderstanding how the lockfile library works but I believe it's accessing the lockfile only for database writes and then releasing it. Which should prevent us from running into conflicts between the state tool and the service. I'm realizing now that I'm attempting to solve a problem that already exists so I'll look into the app.Init(cfg) approach.

This will be updated in a separate PR
@Naatan
Copy link
Contributor

Naatan commented Aug 26, 2025

@MDrakos oh also, I don't think this is addressing the following AC:

The state-svc also picks up the new config change

I don't particularly care how, that could be restarting the svc I imagine.

@MDrakos
Copy link
Member Author

MDrakos commented Aug 26, 2025

@MDrakos oh also, I don't think this is addressing the following AC:

The state-svc also picks up the new config change

I don't particularly care how, that could be restarting the svc I imagine.

Yeah, I tried to call this out in one of the integration tests here. The service will pick up the config change after it restarts, or if the config value was set before the service started. The test above my comment specifically sets the config value before the service starts to try to confirm that.

@MDrakos MDrakos requested a review from Naatan August 26, 2025 23:15
@Naatan
Copy link
Contributor

Naatan commented Aug 27, 2025

@MDrakos oh also, I don't think this is addressing the following AC:

The state-svc also picks up the new config change

I don't particularly care how, that could be restarting the svc I imagine.

Yeah, I tried to call this out in one of the integration tests here. The service will pick up the config change after it restarts, or if the config value was set before the service started. The test above my comment specifically sets the config value before the service starts to try to confirm that.

I could have been more explicit in writing that AC, but the intend is that it picks up the change as it's made, without the user manually restarting the state-svc. It should not require the user to manually restart the svc. If this turns out to be too deep a rabbit hole we can probably descope.

Copy link
Contributor

@Naatan Naatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just some churn on the svc restarting stuff -- #3717 (comment)

@MDrakos
Copy link
Member Author

MDrakos commented Aug 27, 2025

Okay with the latest changes the state-svc should pick up when the api host changes. However, because most of our service clients are constructed with a host the state-svc may not change where its requests are going. This would require a larger refactor of a bunch of services to be sure or some sort of restart mechanism when this config value changes.

You have another story for the installers to support config options. If the state tool is installed with the config options set then this will not be an issue. Otherwise it will require a state-svc restart.

@MDrakos MDrakos requested a review from Naatan August 27, 2025 19:54
Copy link
Contributor

@Naatan Naatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, nearly there!

@MDrakos MDrakos requested a review from Naatan August 28, 2025 18:19
Copy link
Contributor

@Naatan Naatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@MDrakos MDrakos merged commit 1a88547 into master Aug 28, 2025
12 of 15 checks passed
@MDrakos MDrakos deleted the miked/PIF-1050 branch August 28, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants