mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:51:57 +00:00
site_alerts: add config warning for critical.externalURL (#5959)
* site_alerts: add runtime validation for critical.externalURL * Apply suggestions from code review Co-Authored-By: Stephen Gutekanst <stephen.gutekanst@gmail.com> * Apply suggestions from code review Co-Authored-By: Stephen Gutekanst <stephen.gutekanst@gmail.com> * Fix e2e test CSS selector * Update e2e waitForSelector
This commit is contained in:
parent
478eca36f1
commit
4eee01e006
@ -8,6 +8,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/globals"
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/jsonc"
|
||||
)
|
||||
|
||||
// Alert implements the GraphQL type Alert.
|
||||
@ -60,6 +61,19 @@ func (r *siteResolver) Alerts(ctx context.Context) ([]*Alert, error) {
|
||||
return alerts, nil
|
||||
}
|
||||
|
||||
// getConfigWarnings identifies problems with the configuration that a site
|
||||
// admin should address, but do not prevent Sourcegraph from running.
|
||||
func getConfigWarnings() (problems conf.Problems, err error) {
|
||||
var c conf.Unified
|
||||
if err := jsonc.Unmarshal(globals.ConfigurationServerFrontendOnly.Raw().Critical, &c.Critical); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c.Critical.ExternalURL == "" {
|
||||
problems = append(problems, conf.NewCriticalProblem("`externalURL` was empty and it is required to be configured for Sourcegraph to work correctly."))
|
||||
}
|
||||
return problems, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Warn about invalid site configuration.
|
||||
AlertFuncs = append(AlertFuncs, func(args AlertFuncArgs) []*Alert {
|
||||
@ -79,6 +93,18 @@ func init() {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
configWarnings, err := getConfigWarnings()
|
||||
if err != nil {
|
||||
return []*Alert{
|
||||
{
|
||||
TypeValue: AlertTypeError,
|
||||
MessageValue: `Update [**critical configuration**](/help/admin/management_console) to resolve problems: ` + err.Error(),
|
||||
},
|
||||
}
|
||||
}
|
||||
problems = append(problems, configWarnings...)
|
||||
|
||||
if len(problems) == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -89,7 +115,7 @@ func init() {
|
||||
if len(criticalProblems) > 0 {
|
||||
alerts = append(alerts, &Alert{
|
||||
TypeValue: AlertTypeWarning,
|
||||
MessageValue: `[**Update critical configuration**](/help/admin/management_console) to resolve problems.` +
|
||||
MessageValue: `[**Update critical configuration**](/help/admin/management_console) to resolve problems:` +
|
||||
"\n* " + strings.Join(criticalProblems.Messages(), "\n* "),
|
||||
})
|
||||
}
|
||||
@ -98,7 +124,7 @@ func init() {
|
||||
if len(siteProblems) > 0 {
|
||||
alerts = append(alerts, &Alert{
|
||||
TypeValue: AlertTypeWarning,
|
||||
MessageValue: `[**Update site configuration**](/site-admin/configuration) to resolve problems.` +
|
||||
MessageValue: `[**Update site configuration**](/site-admin/configuration) to resolve problems:` +
|
||||
"\n* " + strings.Join(siteProblems.Messages(), "\n* "),
|
||||
})
|
||||
}
|
||||
|
||||
@ -121,11 +121,11 @@ describe('e2e test suite', () => {
|
||||
selectMethod: 'keyboard',
|
||||
})
|
||||
await driver.page.click('.e2e-settings-file .e2e-save-toolbar-save')
|
||||
await driver.page.waitForSelector('.e2e-global-alert .global-alerts__alert', { visible: true })
|
||||
await driver.page.waitForSelector('.e2e-global-alert .notices .global-alerts__alert', { visible: true })
|
||||
await driver.page.evaluate(message => {
|
||||
const elem = document.querySelector('.e2e-global-alert .global-alerts__alert')
|
||||
const elem = document.querySelector('.e2e-global-alert .notices .global-alerts__alert')
|
||||
if (!elem) {
|
||||
throw new Error('No .e2e-global-alert .global-alerts__alert element found')
|
||||
throw new Error('No .e2e-global-alert .notices .global-alerts__alert element found')
|
||||
}
|
||||
if (!(elem as HTMLElement).innerText.includes(message)) {
|
||||
throw new Error('Expected "' + message + '" message, but didn\'t find it')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user