[config]: Removal of Global externalURL and Updated Config Validation#57064
[config]: Removal of Global externalURL and Updated Config Validation#57064cesrjimenez wants to merge 7 commits intomainfrom
Conversation
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff b150ded...68fd6d7.
|
| func ExternalURL() *url.URL { | ||
| return globals.ExternalURL() | ||
| } |
There was a problem hiding this comment.
lol, not sad to see this go away
| server.ChangesetSyncRegistry = syncRegistry | ||
| } | ||
|
|
||
| go globals.WatchExternalURL() |
camdencheek
left a comment
There was a problem hiding this comment.
LGTM! Since you went through all the usage sites of ExternalURL, do you know if we can safely remove it from the "requires restart" list?
internal/conf/computed.go
Outdated
| var err error | ||
| if _, err = url.Parse(val); err != nil { | ||
| problems = append(problems, NewSiteProblem("Could not parse `externalURL`.")) | ||
| } |
There was a problem hiding this comment.
nit: why the bonus err declaration? And should we include the error message
| var err error | |
| if _, err = url.Parse(val); err != nil { | |
| problems = append(problems, NewSiteProblem("Could not parse `externalURL`.")) | |
| } | |
| if _, err := url.Parse(val); err != nil { | |
| problems = append(problems, NewSiteProblem(fmt.Sprintf("Could not parse `externalURL`: %s", err))) | |
| } |
| log.Fatalf("The 'DEPLOY_TYPE' environment variable is invalid. Expected one of: %q, %q, %q, %q, %q, %q, %q. Got: %q", deploy.Kubernetes, deploy.DockerCompose, deploy.PureDocker, deploy.SingleDocker, deploy.Dev, deploy.Helm, deploy.App, deployType) | ||
| } | ||
|
|
||
| ContributeValidator(validateExternalURLConfig) |
There was a problem hiding this comment.
We should check when this validator actually runs. If we can guarantee that conf.Get() will never see a config that doesn't pass validation, it would be nice to add a little helper to this package that parses the URL and panics on error. We added quite a bit of error handling in this PR for something that shouldn't ever happen.
There was a problem hiding this comment.
When looking into this, I came across these, which can be rolled into the external URL validator.
There was a problem hiding this comment.
Okay, I looked into this, and we do not, in fact, guarantee that the output of conf.Get() passes validation. We guarantee that the input passes validation, but we might add new validators with a release, which is usually the source of the banner message.
Feel free to ignore the first message. It think it's still worth moving those linked lines to the contributed validator though.
There was a problem hiding this comment.
Sounds good, I moved the linked lines to the contributed validator 👍
| // and make the user SCIM-controlled (which is the same as a replace) | ||
| return u.Update(ctx, strconv.Itoa(int(userID)), func(getResource func() scim.Resource) (updated scim.Resource, _ error) { | ||
| var now = time.Now() | ||
| now := time.Now() |
keegancsmith
left a comment
There was a problem hiding this comment.
Have you tested this on a fresh setup with dev config/etc? conf.Get() on a fresh instance I think just returns an empty struct, which means externalURL will be empty. From reading the old behaviour, this is a divergence and I worry this will lead to us bricking sourcegraph on fresh startup or if an admin fat fingers. The old behaviour:
- If there is bad or no config, we return http://example.com
- If in the process life time there was a good value before the bad value, it returns the last good value.
The 2nd point doesn't seem that important, but the first seems like it may be very important.
Either way this is a heroic change. Approving given my concerns may not count for much.
This Pull Request focuses on removing the reliance on global variables and enhancing configuration validation by utilizing the ContributeValidator pattern, leading to a more robust and maintainable system.
Changes:
Removal of Global externalURL References:
externalURL. Now, the system efficiently retrieves the most recentexternalURLusingconf.Get(), ensuring that the most up-to-date and relevant URL is always utilized.Updated Site Config Validation:
ContributeValidatorpattern. This change replaces the prior global watch method, enhancing the reliability and structure of our configuration validation system.Tests Update:
Advantages:
conf.Get()to retrieveexternalURL, the system ensures the use of the most current URL, enhancing accuracy and responsiveness.ContributeValidatorpattern for site config validation optimizes the process, making it more reliable and structured.Test plan